/** * bitfury.c - cgminer worker for bitfury chip/board * * Copyright (c) 2013 bitfury * Copyright (c) 2013 legkodymov * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 as * published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, see http://www.gnu.org/licenses/. **/ #include "miner.h" #include #include #include "libbitfury.h" #include "util.h" #define GOLDEN_BACKLOG 5 struct device_drv bitfury_drv; // Forward declarations static void bitfury_disable(struct thr_info* thr); static bool bitfury_prepare(struct thr_info *thr); static void bitfury_detect(void) { int chip_n; struct cgpu_info *bitfury_info; applog(LOG_INFO, "INFO: bitfury_detect"); chip_n = libbitfury_detectChips(); if (!chip_n) { applog(LOG_WARNING, "No Bitfury chips detected!"); return; } else { applog(LOG_WARNING, "BITFURY: %d chips detected!", chip_n); } bitfury_info = calloc(1, sizeof(struct cgpu_info)); bitfury_info->drv = &bitfury_drv; bitfury_info->threads = 1; bitfury_info->chip_n = chip_n; add_cgpu(bitfury_info); } static uint32_t bitfury_checkNonce(struct work *work, uint32_t nonce) { applog(LOG_INFO, "INFO: bitfury_checkNonce"); } static int64_t bitfury_scanHash(struct thr_info *thr) { static struct bitfury_device devices[100]; int chip_n; int chip; uint64_t hashes = 0; chip_n = thr->cgpu->chip_n; for (chip = 0; chip < chip_n; chip++) { if(!devices[chip].work) { devices[chip].work = get_queued(thr->cgpu); if (devices[chip].work == NULL) { return 0; } work_to_payload(&(devices[chip].payload), devices[chip].work); } } libbitfury_sendHashData(devices, chip_n); for (chip = 0; chip < chip_n; chip++) { if (devices[chip].job_switched) { int i,j; int *res = devices[chip].results; struct work *owork = devices[chip].owork; i = devices[chip].results_n; for (j = i - 1; j >= 0; j--) { if (owork) { submit_nonce(thr, owork, bswap_32(res[j])); } } if (owork) work_completed(thr->cgpu, owork); devices[chip].owork = devices[chip].work; devices[chip].work = NULL; hashes += 0xffffffffull * i; } } return hashes; } static void bitfury_statline_before(char *buf, struct cgpu_info *cgpu) { applog(LOG_INFO, "INFO bitfury_statline_before"); } static bool bitfury_prepare(struct thr_info *thr) { struct timeval now; struct cgpu_info *cgpu = thr->cgpu; cgtime(&now); get_datestamp(cgpu->init, &now); applog(LOG_INFO, "INFO bitfury_prepare"); return true; } static void bitfury_shutdown(struct thr_info *thr) { applog(LOG_INFO, "INFO bitfury_shutdown"); } static void bitfury_disable(struct thr_info *thr) { applog(LOG_INFO, "INFO bitfury_disable"); } struct device_drv bitfury_drv = { .drv_id = DRIVER_BITFURY, .dname = "bitfury", .name = "BITFURY", .drv_detect = bitfury_detect, .get_statline_before = bitfury_statline_before, .thread_prepare = bitfury_prepare, .scanwork = bitfury_scanHash, .thread_shutdown = bitfury_shutdown, .hash_work = hash_queued_work, };