Introducing a new way to review your PRs.

Read the announcement

luke-jr / bfgminer

Modular ASIC/FPGA miner written in C, featuring overclocking, monitoring, fan speed control and remote interface capabilities.

View on GitHub

13 documents · Updated Nov 16, 2026

docs / vendor-asic-drivers

Vendor ASIC Drivers

Overview

This area contains vendor-specific ASIC miner drivers that are neither the generic CPU/GPU/FPGA paths nor the Avalon/Bitmain/USB-stick families. Each file registers a struct device_drv and plugs one hardware protocol into the miner core through deviceapi.h and miner.h callbacks: detection (.drv_detect, .lowl_match, .lowl_probe), thread setup, one of the miner loops (minerloop_queue, minerloop_async, hash_queued_work, minerloop_scanhash, or an Icarus-derived loop), work submission, result polling, stats, and optional TUI/RPC --set-device controls.

The common flow is: detect a physical or proxy device, allocate a cgpu_info with one or more logical processors, initialise per-device/per-chip state in .thread_init or .thread_prepare, convert BFGMiner struct work into the vendor wire format, record enough ID/slot/task state to match returned nonces, and call submit_nonce() plus hashes_done2() when results arrive. Drivers use the core queue APIs (get_work(), get_queued(), flush_queue(), HASH_ADD on queued_work, DL_APPEND lists, and thr->queue_full) rather than owning pool selection themselves.

The owned drivers fall into several protocol families:

  • driver-aan.c and driver-aan.h implement a shared SPI protocol for AAN/A1-like chips. The shared code handles chip reset/BIST, four-slot job IDs, PLL/difficulty controls, register polling, nonce result parsing, and queue fullness across managed processors. driver-jingtian.c is the concrete board driver: it opens Linux spidev, drives chip-select and reset GPIOs, prepends a Jingtian header before every AAN command, reads two extra temperature bytes after AAN registers, and delegates queueing/polling/API status to the shared AAN callbacks.
  • driver-bfsb.c, driver-bfx.c, and driver-metabank.c are Bitfury board wrappers over libbitfury and driver-bitfury.h. They differ mainly in low-level bus selection: BFSB banks the system SPI bus with spi_bfsb_select_bank(), BFX opens an FT232H MPSSE device and exposes it as a spi_port, and Metabank scans 32 I2C-controlled slots via tm_i2c before routing system SPI to the selected slot. All three reuse Bitfury job preparation, polling, nonce processing, enable/disable, and status reporting.
  • driver-cairnsmore.c and driver-zeusminer.c customise the Icarus serial protocol from driver-icarus.h. Cairnsmore detects the Cairnsmore1 VCOM product, sets two-FPGA timing defaults, optionally probes dynamic clock support with special 64-byte commands, and then mutates the inherited icarus_drv. ZeusMiner builds a scrypt-specific golden work probe, derives read timing from the golden nonce, injects the clock/difficulty header in zeusminer_job_prepare(), and also initialises by copying icarus_drv.
  • driver-alchemist.c, driver-drillbit.c, driver-hashfast.c, and driver-rockminer.c are direct serial/VCOM protocols. Alchemist requires custom firmware, scans chips/cores using diagnostic golden work, writes 113-byte job/config frames, and uses minerloop_scanhash. Drillbit exchanges single-letter commands (I, R, C, W, E, T, L) and maps one serial board to many chip processors. HashFast frames messages with an 0xaa header, CRC8, opcodes such as HFOP_USB_INIT, HFOP_HASH, HFOP_NONCE, and HFOP_STATUS, queues one pending work per core, and can change per-chip clocks once cores go idle. Rockminer detects R-BOX/RX-BOX devices with golden work, bisects chip count, then responds to 8-byte nonce/task/request messages while retaining two task slots per chip.
  • driver-cointerra.c and driver-cointerra.h implement Cointerra GoldStrike USB bulk messaging. Messages are 64-byte ZZ frames with offsets defined in the header. Detection opens libusb interface 0, sends reset-init, requests device info, and creates one processor per reported core. Runtime queueing responds to request-work counts, assigns 16-bit work IDs, records work in cgpu->queued_work, parses match/work-done/status/info/debug messages, and exposes detailed telemetry from struct cointerra_info.
  • driver-klondike.c and driver-klondike.h implement a libusb command/reply protocol for Klondike K1/K16/K64. A detached reply thread continuously reads 15-byte KLINE replies into a locked free/used list. Queue fullness actively sends work when device work queues have capacity, keeps old work in queued_work for nonce matching, handles overheat by aborting and disabling devices, and maintains per-device stats/clock/fan/temperature state.
  • driver-knc.c is the original KnC SPI/I2C driver. It detects ASICs through /dev/i2c-2, creates 192 logical cores per chip, opens /dev/spidev1.0, batches submit/flush commands into 4096-byte SPI transactions, matches replies by work ID, and reads temperature/DCDC telemetry from per-die I2C devices. It also disables cores temporarily after repeated hardware errors.
  • driver-kncasic.c is the newer KnC Jupiter/Neptune transport driver. It depends on knc-asic/knc-transport.h and knc-asic/knc-asic.h, creates cgpus per ASIC/die, runs a dedicated SPI transport thread with ring buffers, tracks per-core work slots, decodes reports, and drives a custom hash_driver_work() loop that repeatedly calls .scanwork and flushes on work restarts.
  • driver-titan.c, titan-asic.c, and titan-asic.h implement KnC Titan scrypt ASIC support on top of the same KnC transport primitives. Detection scans ASIC/die combinations, knc_titan_init() configures per-core nonce ranges and Titan setup parameters, queueing holds a shared local work queue, and polling sends urgent or normal work through per-core or FPGA-parallel helpers in titan-asic.c, processes reports, maintains rolling die hash rate, and periodically reconfigures dies that stop returning shares.
  • driver-minion.c is a Linux SPI driver for Minion chips. It probes chip signatures over /dev/spidev0.0, maps each core to a logical processor, programs PLL/core-enable/temperature registers, queues register-format tasks, polls FIFO result records, distributes hash accounting across enabled cores, and reinitialises chips on timeout.
  • driver-minergate.c is a Unix-domain-socket proxy protocol used by external miner controllers. Detection connects to default sockets such as /tmp/connection_pipe and /tmp/connection_pipe_sp30, negotiates packet shape by protocol version, queues work into request packets, reads fixed-size response packets, submits noffset nonces, and optionally reads external temperature stats from /var/run/mg_rate_temp.

Coverage

Coupling

Risks

  • driver-minergate.c currently rejects every explicit protover setting because minergate_init_protover() checks if (i != MPV_SP10 || i != MPV_SP30). If a user needs to override protocol version through --set-device, detection cannot accept it even though the rest of the file supports both SP10 and SP30 packet layouts.
  • driver-titan.c exposes a die set-device command, but die_test_and_add() and die_disable() mark addition/deletion as TODO/not implemented. If callers expect runtime die enable/disable to take effect, they can receive errors or a reconfigure-only path while the actual die set remains unchanged.
  • driver-drillbit.c parses chip IDs from result packets in drillbit_get_work_results() and assigns struct thr_info *thr = proc->thr[0] before checking whether drillbit_find_proc() returned NULL. A malformed or newer firmware result with an out-of-range chip ID can dereference a null processor instead of just counting a hardware error.
  • driver-aan.c implements shared AAN queueing but leaves aan_queue_flush() as TODO; driver-jingtian.c wires this flush callback directly. On restart/stale-work events, the hardware queue may continue returning old job IDs until overwritten, increasing bad-job/hardware-error handling in aan_scanwork().
  • driver-rockminer.c also has an empty rockminer_queue_flush(). Combined with two alternating task slots in struct rockminer_chip_data, stale work relies on timeout/resend logic in rockminer_poll() rather than an explicit hardware flush, so lost task-request packets can cause resends or delayed queue recovery.