#ifdef HAVE_CURSES #include #endif #ifndef HAVE_CURSES #define wlogprint(...) applog(LOG_WARNING, __VA_ARGS__) #endif continue; } if (gpus[gpu].name) free(gpus[gpu].name); gpus[gpu].name = lpInfo[i].strAdapterName; if (!gpus[gpu].cutofftemp) gpus[gpu].cutofftemp = opt_cutofftemp; gpus[gpu].temp = ret; #ifdef HAVE_CURSES #endif #ifdef HAVE_CURSES #endif #ifdef HAVE_CURSES #endif #ifdef HAVE_CURSES #endif if (temp > cgpu->cutofftemp) { #ifdef HAVE_CURSES wlogprint("Cutoff temperature: %d\n", gpus[gpu].cutofftemp); gpus[gpu].cutofftemp = val; #endif static inline void init_adl(__maybe_unused int nDevs) {} static inline void change_gpusettings(__maybe_unused int gpu) { } static inline void clear_adl(__maybe_unused int nDevs) {} #include "driver-cpu.h" /* for algo_names[], TODO: re-factor dependency */ { SEVERITY_SUCC, MSG_POOLPRIO,PARAM_NONE, "Changed pool priorities" }, { switch (status) { case LIFE_WELL: return ALIVE; case LIFE_SICK: return SICK; case LIFE_DEAD: return DEAD; case LIFE_NOSTART: return NOSTART; case LIFE_INIT: return INIT; default: return UNKNOWN; } } status = (char *)status2str(cgpu->status); status = (char *)status2str(cgpu->status); gpu = thr_info[i].cgpu->device_id; { return; } pools_changed[i] = false; } pools_changed[i] = true; if (current_pool()->prio) switch_pools(NULL); } { "poolpriority", poolpriority, true }, #if JANSSON_MAJOR_VERSION > 2 || (JANSSON_MAJOR_VERSION == 2 && JANSSON_MINOR_VERSION > 0) #elif JANSSON_MAJOR_VERSION > 1 json_config = json_loads(buf, 0, &json_err); #else json_config = json_loads(buf, &json_err); #endif /* * Copyright 2012 Luke Dashjr * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the Free * Software Foundation; either version 3 of the License, or (at your option) * any later version. See COPYING for more details. */ #define _BSD_SOURCE #include #include #include #include #include #define BFL_FILE_MAGIC "BFLDATA" #define BFL_UPLOAD_MAGIC "NGH-STREAM" fprintf(stderr, __VA_ARGS__); \ return n; \ } \ } while(0) #define ERRRESP(buf) buf, (buf[strlen(buf)-1] == '\n' ? "" : "\n") myassert(fgets(buf, sizeof(buf), BFL), n, "Error reading response from " msg "\n"); \ myassert(!strcmp(buf, "OK\n"), n, "Invalid response from " msg ": %s%s", ERRRESP(buf)); \ } while(0) myassert(argc == 3, 1, "Usage: %s \n", argv[0]); setbuf(stdout, NULL); // Check filename char *FWname = basename(strdup(argv[2])); size_t FWnameLen = strlen(FWname); myassert(FWnameLen <= 255, 0x0f, "Firmware filename '%s' is too long\n", FWname); uint8_t n8 = FWnameLen; // Open and check firmware file FILE *FW = fopen(argv[2], "r"); myassert(FW, 0x10, "Failed to open '%s' for reading\n", argv[2]); char buf[0x20]; myassert(1 == fread(buf, 7, 1, FW), 0x10, "Failed to read from '%s'\n", argv[2]); myassert(!memcmp(buf, BFL_FILE_MAGIC, sizeof(BFL_FILE_MAGIC)-1), 0x11, "'%s' doesn't look like a BFL firmware\n", argv[2]); myassert(!fseek(FW, 0, SEEK_END), 0x12, "Failed to find end of '%s'\n", argv[2]); long FWlen = ftell(FW); myassert(FWlen > 0, 0x12, "Couldn't get size of '%s'\n", argv[2]); myassert(!fseek(FW, 7, SEEK_SET), 0x12, "Failed to rewind firmware file after getting size\n"); FWlen -= 7; printf("Firmware file looks OK :)\n"); // Open device FILE *BFL = fopen(argv[1], "r+"); myassert(BFL, 0x20, "Failed to open '%s' for read/write\n", argv[1]); myassert(!setvbuf(BFL, NULL, _IOFBF, 1032), 0x21, "Failed to setup buffer for device"); // ZAX: Start firmware upload printf("Starting firmware upload... "); myassert(1 == fwrite("ZAX", 3, 1, BFL), 0x22, "Failed to issue ZAX command\n"); WAITFOROK(0x22, "ZAX"); // Firmware upload header myassert(1 == fwrite(BFL_UPLOAD_MAGIC, sizeof(BFL_UPLOAD_MAGIC)-1, 1, BFL), 0x23, "Failed to send firmware upload header (magic)\n"); uint32_t n32 = htonl(FWlen - FWlen / 6); myassert(1 == fwrite(&n32, sizeof(n32), 1, BFL), 0x23, "Failed to send firmware upload header (size)\n"); myassert(1 == fwrite("\0\0", 2 , 1, BFL), 0x23, "Failed to send firmware upload header (padding 1)\n"); myassert(1 == fwrite(&n8, sizeof(n8) , 1, BFL), 0x23, "Failed to send firmware upload header (filename length)\n"); myassert(1 == fwrite(FWname, n8 , 1, BFL), 0x23, "Failed to send firmware upload header (filename)\n"); myassert(1 == fwrite("\0>>>>>>>>", 9 , 1, BFL), 0x23, "Failed to send firmware upload header (padding 2)\n"); WAITFOROK(0x23, "firmware upload header"); printf("OK, sending...\n"); // Actual firmware upload myassert(1 == fread(&n8, sizeof(n8), 1, FW), 0x30, "Error reading data from firmware file\n"); if (5 == i % 6) continue; n8 ^= 0x2f; myassert(1 == fwrite(&n8, sizeof(n8), 1, BFL), 0x31, "Error sending data to device\n"); myassert(1 == fwrite(">>>>>>>>", 8, 1, BFL), 0x32, "Error sending block-finish to device\n"); printf("\r%5.2f%% complete", (double)i * 100. / (double)FWlen); WAITFOROK(0x32, "block-finish"); } } printf("\r100%% complete :)\n"); myassert(1 == fwrite(">>>>>>>>", 8, 1, BFL), 0x3f, "Error sending upload-finished to device\n"); // ZBX: Finish programming printf("Waiting for device... "); myassert(1 == fwrite("ZBX", 3, 1, BFL), 0x40, "Failed to issue ZBX command\n"); WAITFOROK(0x40, "ZBX"); } #ifdef HAVE_CURSES #endif #include "driver-cpu.h" #include "driver-opencl.h" #if defined(USE_BITFORCE) || defined(USE_ICARUS) || defined(USE_MODMINER) # define USE_FPGA # define USE_FPGA_SERIAL #elif defined(USE_ZTEX) # define USE_FPGA #endif const int opt_cutofftemp = 95; #endif #ifdef HAVE_CURSES #else #endif #ifdef HAVE_CURSES #endif pthread_mutex_t console_lock; static #ifndef HAVE_CURSES const #endif bool curses_active; static pthread_mutex_t sharelog_lock; if (!sharelog_file) return; // timestamp,disposition,target,pool,dev,thr,sharehash,sharedata rv = snprintf(s, sizeof(s), "%lu,%s,%s,%s,%s%u,%u,%s,%s\n", t, disposition, target, pool->rpc_url, cgpu->api->name, cgpu->device_id, thr_id, hash, data); free(target); free(hash); free(data); s[sizeof(s) - 1] = '\0'; applog(LOG_ERR, "sharelog printf error"); return; } mutex_lock(&sharelog_lock); ret = fwrite(s, rv, 1, sharelog_file); fflush(sharelog_file); mutex_unlock(&sharelog_lock); applog(LOG_ERR, "sharelog fwrite error"); } #ifdef USE_FPGA_SERIAL char *r = ""; long int i = strtol(arg, &r, 10); if ((!*r) && i >= 0 && i <= INT_MAX) { sharelog_file = fdopen((int)i, "a"); if (!sharelog_file) applog(LOG_ERR, "Failed to open fd %u for share log", (unsigned int)i); } else if (!strcmp(arg, "-")) { sharelog_file = stdout; if (!sharelog_file) applog(LOG_ERR, "Standard output missing for share log"); } else { sharelog_file = fopen(arg, "a"); if (!sharelog_file) applog(LOG_ERR, "Failed to open %s for share log", arg); } return NULL; } static char *temp_cutoff_str = NULL; char *set_temp_cutoff(char *arg) { int val; if (!(arg && arg[0])) return "Invalid parameters for set temp cutoff"; val = atoi(arg); if (val < 0 || val > 200) return "Invalid value passed to set temp cutoff"; temp_cutoff_str = arg; return NULL; } static void load_temp_cutoffs() { int i, val = 0, device = 0; char *nextptr; if (temp_cutoff_str) { for (device = 0, nextptr = strtok(temp_cutoff_str, ","); nextptr; ++device, nextptr = strtok(NULL, ",")) { if (device >= total_devices) quit(1, "Too many values passed to set temp cutoff"); val = atoi(nextptr); if (val < 0 || val > 200) quit(1, "Invalid value passed to set temp cutoff"); devices[device]->cutofftemp = val; } if (!devices[i]->cutofftemp) devices[i]->cutofftemp = opt_cutofftemp; return; } if (device <= 1) { for (i = device; i < total_devices; ++i) devices[i]->cutofftemp = val; } } #ifdef HAVE_OPENCL "Disable GPU mining even if suitable devices exist" #else opt_hidden #endif ), #if defined(WANT_CPUMINE) && (defined(HAVE_OPENCL) || defined(USE_FPGA)) #endif #if defined(HAVE_OPENCL) || defined(HAVE_MODMINER) "Specify a path to where bitstream and kernel files are"), #endif #ifdef HAVE_OPENCL #ifdef HAVE_ADL "Disable the ATI display library used for monitoring and setting GPU parameters" #else opt_hidden ), #ifdef HAVE_OPENCL #else opt_hidden ), #ifdef USE_FPGA_SERIAL OPT_WITH_ARG("--sharelog", set_sharelog, NULL, NULL, "Append share log to file"), #if defined(HAVE_ADL) || defined(USE_BITFORCE) || defined(USE_MODMINER) "Temperature where a device will be automatically disabled, one value or comma separated list"), #endif #ifdef HAVE_ADL #ifdef HAVE_CURSES "Disable ncurses formatted screen output" #else opt_hidden #endif ), #if JANSSON_MAJOR_VERSION > 1 #else config = json_load_file(arg, &err); #endif #ifdef USE_MODMINER "modminer " #endif #ifdef HAVE_CURSES #endif #ifdef HAVE_CURSES #endif #ifdef HAVE_CURSES mutex_unlock(&console_lock); mutex_lock(&console_lock); #endif else tailsprintf(buf, " | "); #ifdef HAVE_CURSES else wprintw(statuswin, " | "); #endif #ifdef HAVE_CURSES #endif #ifdef HAVE_CURSES bool log_curses_only(int prio, const char *f, va_list ap) return true; } return false; #endif #ifdef HAVE_CURSES #endif static #ifdef WIN32 const #endif char **initial_args; thr_info[i].work_restart = true; #ifdef HAVE_CURSES #endif #ifdef HAVE_CURSES #endif #ifdef HAVE_CURSES fprintf(fcfg, "%s%d", i > 0 ? "," : "", gpus[i].cutofftemp); #ifdef HAVE_CURSES #endif #ifdef HAVE_CURSES #endif { const bool primary = (!mythr->device_thread) || mythr->primary_thread; mythr->work_restart = false; applog(LOG_ERR, "%s %d failure, disabling!", api->name, cgpu->device_id); cgpu->deven = DEV_DISABLED; #ifdef HAVE_CURSES #endif struct thr_info *thr = cgpu->thr[0]; if (cgpu->status != LIFE_INIT) #ifdef HAVE_CURSES #endif #ifdef HAVE_CURSES #endif #ifdef HAVE_CURSES #endif #ifdef HAVE_CURSES #endif #ifdef USE_MODMINER extern struct device_api modminer_api; #endif struct _cgpu_devid_counter { char name[4]; int lastid; UT_hash_handle hh; }; bool add_cgpu(struct cgpu_info*cgpu) { static struct _cgpu_devid_counter *devids = NULL; struct _cgpu_devid_counter *d; HASH_FIND_STR(devids, cgpu->api->name, d); if (d) cgpu->device_id = ++d->lastid; d = malloc(sizeof(*d)); memcpy(d->name, cgpu->api->name, sizeof(d->name)); cgpu->device_id = d->lastid = 0; HASH_ADD_STR(devids, name, d); } devices[total_devices++] = cgpu; return true; } mutex_init(&console_lock); mutex_init(&sharelog_lock); s = strdup(argv[0]); strcpy(cgminer_path, dirname(s)); free(s); #ifdef HAVE_CURSES if (opt_realquiet || devices_enabled == -1) use_curses = false; #endif #ifdef USE_MODMINER #endif struct cgpu_info *cgpu = devices[i]; if (cgpu->name) applog(LOG_ERR, " %2d. %s %d: %s (driver: %s)", i, cgpu->api->name, cgpu->device_id, cgpu->name, cgpu->api->dname); else applog(LOG_ERR, " %2d. %s %d (driver: %s)", i, cgpu->api->name, cgpu->device_id, cgpu->api->dname); load_temp_cutoffs(); #ifdef HAVE_CURSES #endif #ifdef HAVE_CURSES if (!use_curses || !input_pool(false)) #endif #ifdef HAVE_CURSES #endif cgpu->thr = malloc(sizeof(*cgpu->thr) * (cgpu->threads+1)); cgpu->thr[cgpu->threads] = NULL; cgpu->status = LIFE_INIT; cgpu->thr[j] = thr; #ifdef HAVE_CURSES #endif #include #include #include "miner.h" // for timersub static inline int nanosleep(const struct timespec *req, struct timespec *rem) struct timeval tstart; DWORD msecs; gettimeofday(&tstart, NULL); msecs = (req->tv_sec * 1000) + ((999999 + req->tv_nsec) / 1000000); if (SleepEx(msecs, true) == WAIT_IO_COMPLETION) { if (rem) { struct timeval tdone, tnow, tleft; tdone.tv_sec = tstart.tv_sec + req->tv_sec; tdone.tv_usec = tstart.tv_usec + ((999 + req->tv_nsec) / 1000); if (tdone.tv_usec > 1000000) { tdone.tv_usec -= 1000000; ++tdone.tv_sec; } gettimeofday(&tnow, NULL); if (timercmp(&tnow, &tdone, >)) return 0; timersub(&tdone, &tnow, &tleft); rem->tv_sec = tleft.tv_sec; rem->tv_nsec = tleft.tv_usec * 1000; } errno = EINTR; return -1; } return 0; static inline int sleep(unsigned int secs) struct timespec req, rem; req.tv_sec = secs; req.tv_nsec = 0; if (!nanosleep(&req, &rem)) return 0; return rem.tv_sec + (rem.tv_nsec ? 1 : 0); /* * Copyright 2012 Luke Dashjr * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the Free * any later version. See COPYING for more details. */ #include #include #include #include #include #include #include "config.h" #include "compat.h" #include "miner.h" #define KNAME_WORK "full work" #define KNAME_RANGE "nonce range" struct device_api bitforce_api; { { } } } // We have a real BitForce! bitforce->kname = KNAME_RANGE; bitforce->kname = KNAME_WORK; } { } static void get_bitforce_statline_before(char *buf, struct cgpu_info *bitforce) { float gt = bitforce->temp; if (gt > 0) tailsprintf(buf, "%5.1fC ", gt); else tailsprintf(buf, " ", gt); tailsprintf(buf, " | "); } static bool bitforce_thread_prepare(struct thr_info *thr) { struct cgpu_info *bitforce = thr->cgpu; struct timeval now; gettimeofday(&now, NULL); get_datestamp(bitforce->init, &now); return true; } { bitforce->kname = KNAME_WORK; } memcpy(ob + 8, work->midstate, 32); memcpy(ob + 8 + 32, work->data + 64, 12); if (opt_debug) { } } } if (unlikely(thr->work_restart)) } } while (1) { hex2bin((void*)&nonce, pnoncebuf, 4); #ifndef __BIG_ENDIAN__ nonce = swab32(nonce); #endif bitforce->kname = KNAME_WORK; submit_nonce(thr, work, nonce); break; pnoncebuf += 9; } } struct device_api bitforce_api = { .dname = "bitforce", .api_detect = bitforce_detect, .get_statline_before = get_bitforce_statline_before, .thread_prepare = bitforce_thread_prepare, .scanhash = bitforce_scanhash, }; #include "driver-cpu.h" extern bool ScanHash_4WaySSE2(struct thr_info*, const unsigned char *pmidstate, extern bool ScanHash_altivec_4way(struct thr_info*, const unsigned char *pmidstate, extern bool scanhash_via(struct thr_info*, const unsigned char *pmidstate, extern bool scanhash_c(struct thr_info*, const unsigned char *midstate, unsigned char *data, extern bool scanhash_cryptopp(struct thr_info*, const unsigned char *midstate,unsigned char *data, extern bool scanhash_asm32(struct thr_info*, const unsigned char *midstate,unsigned char *data, extern bool scanhash_sse2_64(struct thr_info*, const unsigned char *pmidstate, unsigned char *pdata, extern bool scanhash_sse4_64(struct thr_info*, const unsigned char *pmidstate, unsigned char *pdata, extern bool scanhash_sse2_32(struct thr_info*, const unsigned char *pmidstate, unsigned char *pdata, struct thr_info dummy = {0}; &dummy, cgpu = &cpus[i]; cgpu->kname = algo_names[opt_algo]; add_cgpu(cgpu); thr, .dname = "cpu", #include "miner.h" #endif // It's 10 per second, thus value = 10/TIME_FACTOR = #define ICARUS_READ_FAULT_DECISECONDS 1 static int icarus_gets(unsigned char *buf, int fd, struct timeval *tv_finish, struct thr_info *thr, int read_count) ret = icarus_gets(nonce_bin, fd, &tv_finish, thr, info->read_count); } .dname = "icarus", /* * Copyright 2012 Luke Dashjr * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the Free * Software Foundation; either version 3 of the License, or (at your option) * any later version. See COPYING for more details. */ #include "config.h" #include #include #include #include "logging.h" #include "miner.h" #define BITSTREAM_FILENAME "fpgaminer_top_fixed7_197MHz.ncd" #define BISTREAM_USER_ID "\2\4$B" struct device_api modminer_api; modminer->name = devname; { } { } { if (p[0] == '=') unsigned long fwusercode = (unsigned long)strtoll(p, &p, 16); len = ((unsigned long)ubuf[0] << 24) | ((unsigned long)ubuf[1] << 16) | (ubuf[2] << 8) | ubuf[3]; buf[1] = fpgaid; buf[2] = (len >> 0) & 0xff; buf[3] = (len >> 8) & 0xff; buf[4] = (len >> 16) & 0xff; buf[5] = (len >> 24) & 0xff; } return true; } { struct cgpu_info *modminer = thr->cgpu; struct modminer_fpga_state *state; state = thr->cgpu_data = calloc(1, sizeof(struct modminer_fpga_state)); return true; } { struct modminer_fpga_state *state = thr->cgpu_data; unsigned char cmd[6], buf[1]; cmd[3] = cmd[4] = cmd[5] = '\0'; } { struct cgpu_info *modminer = thr->cgpu; unsigned char cmd[2], buf[4]; return false; } if (memcmp(buf, BISTREAM_USER_ID, 4)) { if (!modminer_fpga_upload_bitstream(modminer)) return false; thr->primary_thread = true; return true; } { } { char *midstate = state->next_work_cmd + 2; char *taildata = midstate + 32; if (!(memcmp(midstate, work->midstate, 32) || memcmp(taildata, work->data + 64, 12))) return false; memcpy(midstate, work->midstate, 32); memcpy(taildata, work->data + 64, 12); return true; } { struct modminer_fpga_state *state = thr->cgpu_data; gettimeofday(&state->tv_workstart, NULL); state->hashes = 0; { struct modminer_fpga_state *state = thr->cgpu_data; } else { } } } while (1) { if (memcmp(&nonce, "\xff\xff\xff\xff", 4)) { } } if (work_restart(thr)) break; break; } struct timeval tv_workend, elapsed; gettimeofday(&tv_workend, NULL); if (hashes > 0xffffffff) hashes = 0xffffffff; else if (hashes <= state->hashes) hashes = 1; else hashes -= state->hashes; state->hashes += hashes; return hashes; } { struct modminer_fpga_state *state = thr->cgpu_data; bool startwork; startwork = modminer_prepare_next_work(state, work); if (state->work_running) { hashes = modminer_process_results(thr); if (work_restart(thr)) { state->work_running = false; } state->work_running = true; if (startwork) { if (!modminer_start_work(thr)) } // This is intentionally early work->blk.nonce += hashes; return hashes; } { free(thr->cgpu_data); } struct device_api modminer_api = { .dname = "modminer", .api_detect = modminer_detect, .get_statline_before = get_modminer_statline_before, .thread_prepare = modminer_fpga_prepare, .thread_init = modminer_fpga_init, .scanhash = modminer_scanhash, .thread_shutdown = modminer_fpga_shutdown, }; #ifdef HAVE_CURSES #endif #include "driver-opencl.h" #ifdef HAVE_CURSES #endif #endif /* HAVE_OPENCL */ #if defined(HAVE_OPENCL) && defined(HAVE_CURSES) case LIFE_INIT: void *reinit_gpu(__maybe_unused void *userdata) cgpu = &gpus[i]; add_cgpu(cgpu); #ifdef HAVE_CURSES #endif #ifdef HAVE_CURSES char *buf; #endif dev_error(cgpu, REASON_DEV_NOSTART); cgpu->name = strdup(name); if (!cgpu->kname) { switch (clStates[i]->chosen_kernel) { } } return -1; return -1; .dname = "opencl", while (!(overflow || thr->work_restart)) { if (thr->work_restart) { if (thr->work_restart) { /* * Copyright 2012 Luke Dashjr * Copyright 2012 Andrew Smith * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the Free * Software Foundation; either version 3 of the License, or (at your option) * any later version. See COPYING for more details. */ #include "config.h" #include #include #include #ifndef WIN32 #include #include #include #include #include #ifndef O_CLOEXEC #define O_CLOEXEC 0 #endif #else #include #include #endif #ifdef HAVE_LIBUDEV #include #endif #include "elist.h" #include "logging.h" #include "miner.h" #ifdef HAVE_LIBUDEV { struct udev *udev = udev_new(); struct udev_enumerate *enumerate = udev_enumerate_new(udev); struct udev_list_entry *list_entry; char found = 0; udev_enumerate_add_match_subsystem(enumerate, "tty"); udev_enumerate_add_match_property(enumerate, "ID_MODEL", prodname); udev_enumerate_scan_devices(enumerate); udev_list_entry_foreach(list_entry, udev_enumerate_get_list_entry(enumerate)) { struct udev_device *device = udev_device_new_from_syspath( udev_enumerate_get_udev(enumerate), udev_list_entry_get_name(list_entry) ); if (!device) continue; const char *devpath = udev_device_get_devnode(device); if (devpath && detectone(devpath)) ++found; udev_device_unref(device); } udev_enumerate_unref(enumerate); udev_unref(udev); return found; } #else { return 0; } #endif { #ifndef WIN32 DIR *D; struct dirent *de; const char udevdir[] = "/dev/serial/by-id"; char devpath[sizeof(udevdir) + 1 + NAME_MAX]; char *devfile = devpath + sizeof(udevdir); char found = 0; D = opendir(udevdir); if (!D) return 0; memcpy(devpath, udevdir, sizeof(udevdir) - 1); devpath[sizeof(udevdir) - 1] = '/'; while ( (de = readdir(D)) ) { if (!strstr(de->d_name, prodname)) continue; strcpy(devfile, de->d_name); ++found; } closedir(D); return found; #else return 0; #endif } { struct string_elist *iter, *tmp; bool inhibitauto = false; char found = 0; list_for_each_entry_safe(iter, tmp, &scan_devices, list) { forceauto = true; inhibitauto = true; string_elist_del(iter); inhibitauto = true; ++found; } } found += autoscan(); return found; } { #ifdef WIN32 HANDLE hSerial = CreateFile(devpath, GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL); if (unlikely(hSerial == INVALID_HANDLE_VALUE)) { DWORD e = GetLastError(); switch (e) { case ERROR_ACCESS_DENIED: applog(LOG_ERR, "Do not have user privileges required to open %s", devpath); break; case ERROR_SHARING_VIOLATION: applog(LOG_ERR, "%s is already in use by another process", devpath); break; default: break; } return -1; } // thanks to af_newbie for pointers about this COMMCONFIG comCfg = {0}; comCfg.dwSize = sizeof(COMMCONFIG); comCfg.wVersion = 1; comCfg.dcb.DCBlength = sizeof(DCB); comCfg.dcb.BaudRate = baud; comCfg.dcb.fBinary = 1; comCfg.dcb.fDtrControl = DTR_CONTROL_ENABLE; comCfg.dcb.fRtsControl = RTS_CONTROL_ENABLE; comCfg.dcb.ByteSize = 8; SetCommConfig(hSerial, &comCfg, sizeof(comCfg)); COMMTIMEOUTS cto = {ctoms, 0, ctoms, 0, ctoms}; SetCommTimeouts(hSerial, &cto); if (purge) { PurgeComm(hSerial, PURGE_RXABORT); PurgeComm(hSerial, PURGE_TXABORT); PurgeComm(hSerial, PURGE_RXCLEAR); PurgeComm(hSerial, PURGE_TXCLEAR); } return _open_osfhandle((LONG)hSerial, 0); #else int fdDev = open(devpath, O_RDWR | O_CLOEXEC | O_NOCTTY); if (unlikely(fdDev == -1)) { if (errno == EACCES) applog(LOG_ERR, "Do not have user privileges required to open %s", devpath); return -1; } switch (baud) { default: applog(LOG_WARNING, "Unrecognized baud rate: %lu", baud); } if (purge) tcflush(fdDev, TCIOFLUSH); return fdDev; #endif } { ssize_t len, tlen = 0; while (bufsiz) { len = read(fd, buf, eol ? 1 : bufsiz); break; tlen += len; if (eol && *eol == buf[0]) break; buf += len; bufsiz -= len; } return tlen; } { char fullpath[PATH_MAX]; strcpy(fullpath, path); strcat(fullpath, "/"); if (subdir) { strcat(fullpath, subdir); strcat(fullpath, "/"); } strcat(fullpath, filename); return fopen(fullpath, "rb"); } #define _open_bitstream(path, subdir) do { \ f = _open_bitstream(path, subdir, filename); \ if (f) \ return f; \ } while(0) #define _open_bitstream3(path) do { \ _open_bitstream(path, dname); \ _open_bitstream(path, "bitstreams"); \ _open_bitstream(path, NULL); \ } while(0) { FILE *f; _open_bitstream3(opt_kernel_path); _open_bitstream3(cgminer_path); _open_bitstream3("."); return NULL; } /* * Copyright 2012 Luke Dashjr * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the Free * Software Foundation; either version 3 of the License, or (at your option) * any later version. See COPYING for more details. */ #ifndef FPGAUTILS_H #define FPGAUTILS_H #include #include typedef bool(*detectone_func_t)(const char*); #define serial_read(fd, buf, count) \ _serial_read(fd, (char*)(buf), count, NULL) #define serial_read_line(fd, buf, bufsiz, eol) \ #define serial_close(fd) close(fd) #endif fp = open_bitstream("ztex", firmware); fp = open_bitstream("ztex", firmware); char buf[256]; strcpy(buf, ztex->bitFileName); strcat(buf, ".bit"); static void my_log_curses(__maybe_unused int prio, char *f, va_list ap) #ifdef HAVE_CURSES if (use_curses && log_curses_only(prio, f, ap)) ; else #endif { int len = strlen(f); strcpy(f + len - 1, " \n"); mutex_lock(&console_lock); vprintf(f, ap); mutex_unlock(&console_lock); } } static void log_generic(int prio, const char *fmt, va_list ap); void vapplog(int prio, const char *fmt, va_list ap) { if (use_syslog || opt_log_output || prio <= LOG_NOTICE) log_generic(prio, fmt, ap); static void log_generic(int prio, const char *fmt, va_list ap) sprintf(f, " [%d-%02d-%02d %02d:%02d:%02d] %s\n", my_log_curses(prio, f, ap); LIFE_NOSTART, LIFE_INIT, struct thr_info; struct work; struct device_api { // API-global functions void (*api_detect)(); // Device-specific functions // Thread-specific functions }; int cgminer_id; struct device_api *api; int device_id; char *name; char *device_path; FILE *device_file; int threads; struct thr_info **thr; float temp; int cutofftemp; extern bool add_cgpu(struct cgpu_info*); bool primary_thread; void *cgpu_data; bool work_restart; struct string_elist { char *string; bool free_me; struct list_head list; }; static inline void string_elist_add(const char *s, struct list_head *head) { struct string_elist *n; n = calloc(1, sizeof(*n)); n->string = strdup(s); n->free_me = true; list_add_tail(&n->list, head); } static inline void string_elist_del(struct string_elist *item) { if (item->free_me) free(item->string); list_del(&item->list); } typedef bool (*sha256_func)(struct thr_info*, const unsigned char *pmidstate, uint32_t max_nonce, uint32_t *last_nonce, uint32_t nonce); extern pthread_mutex_t console_lock; extern struct list_head scan_devices; extern int total_devices; extern const int opt_cutofftemp; extern void get_datestamp(char *, struct timeval *); extern void tailsprintf(char *f, const char *fmt, ...); extern bool log_curses_only(int prio, const char *f, va_list ap); #include "driver-cpu.h" bool ScanHash_4WaySSE2(struct thr_info*thr, const unsigned char *pmidstate, uint32_t max_nonce, uint32_t *last_nonce, unsigned int *nNonce_p = (unsigned int*)(pdata + 76); pdata += 64; nonce += j; *last_nonce = nonce; *nNonce_p = nonce; return true; if ((nonce >= max_nonce) || thr->work_restart) *last_nonce = nonce; return false; #include "driver-cpu.h" bool ScanHash_altivec_4way(struct thr_info*thr, const unsigned char *pmidstate, uint32_t max_nonce, uint32_t *last_nonce, unsigned int *nNonce_p = (unsigned int*)(pdata + 76); pdata += 64; nonce += j; *last_nonce = nonce; *nNonce_p = nonce; return true; if ((nonce >= max_nonce) || thr->work_restart) *last_nonce = nonce; return false; bool scanhash_cryptopp(struct thr_info*thr, const unsigned char *midstate, uint32_t max_nonce, uint32_t *last_nonce, uint32_t *nonce = (uint32_t *)(data + 76); data += 64; *last_nonce = n; if ((n >= max_nonce) || thr->work_restart) { *last_nonce = n; bool scanhash_asm32(struct thr_info*thr, const unsigned char *midstate, uint32_t max_nonce, uint32_t *last_nonce, uint32_t *nonce = (uint32_t *)(data + 76); data += 64; *last_nonce = n; if ((n >= max_nonce) || thr->work_restart) { *last_nonce = n; bool scanhash_c(struct thr_info*thr, const unsigned char *midstate, unsigned char *data, uint32_t max_nonce, uint32_t *last_nonce, uint32_t *nonce = (uint32_t *)(data + 76); data += 64; *last_nonce = n; if ((n >= max_nonce) || thr->work_restart) { *last_nonce = n; #include "driver-cpu.h" bool scanhash_sse2_64(struct thr_info*thr, const unsigned char *pmidstate, uint32_t max_nonce, uint32_t *last_nonce, uint32_t *nNonce_p = (uint32_t *)(pdata + 76); pdata += 64; nonce += j; *last_nonce = nonce + 1; *nNonce_p = nonce; return true; if (unlikely((nonce >= max_nonce) || thr->work_restart)) *last_nonce = nonce; return false; nonce += 4; #include "driver-cpu.h" bool scanhash_sse2_32(struct thr_info*thr, const unsigned char *pmidstate, uint32_t max_nonce, uint32_t *last_nonce, uint32_t *nNonce_p = (uint32_t *)(pdata + 76); pdata += 64; nonce += j; *last_nonce = nonce; *nNonce_p = nonce; return true; if (unlikely((nonce >= max_nonce) || thr->work_restart)) { *last_nonce = nonce; return false; } #include "driver-cpu.h" bool scanhash_sse4_64(struct thr_info*thr, const unsigned char *pmidstate, uint32_t max_nonce, uint32_t *last_nonce, uint32_t *nNonce_p = (uint32_t *)(pdata + 76); pdata += 64; nonce += j; *last_nonce = nonce; *nNonce_p = nonce; return true; if (unlikely((nonce >= max_nonce) || thr->work_restart)) *last_nonce = nonce; return false; nonce += 4; #include "driver-cpu.h" unsigned char *data_inout, const unsigned char *target, uint32_t max_nonce, uint32_t *last_nonce, *last_nonce = n; if ((n >= max_nonce) || thr->work_restart) { *last_nonce = n; char *reason; if (!strcasecmp("X-Reject-Reason", key)) { hi->reason = val; /* steal memory reference */ val = NULL; } memset(&err, 0, sizeof(err)); headers = curl_slist_append(headers, json_object_set_new(val, "reject-reason", json_string(hi.reason)); ldiv_t d; d = ldiv(msecs, 1000); tleft.tv_sec = d.quot; tleft.tv_nsec = d.rem * 1000000; free(pool->swork.job_id); free(pool->swork.prev_hash); free(pool->swork.coinbase1); free(pool->swork.coinbase2); free(pool->swork.bbversion); free(pool->swork.nbit); free(pool->swork.ntime);