Browse Source

Merge branch 'uniscan2' into bfgminer

Luke Dashjr 12 years ago
parent
commit
8be8d943bb
6 changed files with 63 additions and 7 deletions
  1. 1 1
      driver-hashbuster.c
  2. 1 1
      driver-nanofury.c
  3. 0 1
      fpgautils.h
  4. 32 2
      lowl-hid.c
  5. 2 0
      lowlevel.h
  6. 27 2
      miner.c

+ 1 - 1
driver-hashbuster.c

@@ -184,7 +184,7 @@ bool hashbuster_lowl_probe(const struct lowlevel_device_info * const info)
 	
 	hid_close(h);
 	
-	if (bfg_claim_hid(&hashbuster_drv, true, info->path))
+	if (lowlevel_claim(&hashbuster_drv, true, info))
 		return false;
 	
 	struct cgpu_info *cgpu;

+ 1 - 1
driver-nanofury.c

@@ -210,7 +210,7 @@ bool nanofury_lowl_probe(const struct lowlevel_device_info * const info)
 	nanofury_device_off(mcp);
 	mcp2210_close(mcp);
 	
-	if (bfg_claim_hid(&nanofury_drv, true, info->path))
+	if (lowlevel_claim(&nanofury_drv, true, info))
 		return false;
 	
 	struct cgpu_info *cgpu;

+ 0 - 1
fpgautils.h

@@ -40,7 +40,6 @@ extern char *bfg_make_devid_usb(uint8_t usbbus, uint8_t usbaddr);
 extern struct device_drv *bfg_claim_usb(struct device_drv * const, const bool verbose, const uint8_t usbbus, const uint8_t usbaddr);
 #define bfg_make_devid_libusb(dev)  bfg_make_devid_usb(libusb_get_bus_number(dev), libusb_get_device_address(dev))
 #define bfg_claim_libusb(api, verbose, dev)  bfg_claim_usb(api, verbose, libusb_get_bus_number(dev), libusb_get_device_address(dev))
-#define bfg_claim_hid(api, verbose, path)  bfg_claim_any2(api, (verbose)?"":NULL, "hid", path)
 
 #ifdef HAVE_LIBUSB
 extern void cgpu_copy_libusb_strings(struct cgpu_info *, libusb_device *);

+ 32 - 2
lowl-hid.c

@@ -22,6 +22,7 @@ typedef void *dlh_t;
 typedef HMODULE dlh_t;
 #endif
 
+#include <ctype.h>
 #include <stdbool.h>
 #include <stdint.h>
 #include <stdio.h>
@@ -30,6 +31,7 @@ typedef HMODULE dlh_t;
 #include <hidapi.h>
 #include <utlist.h>
 
+#include "fpgautils.h"
 #include "logging.h"
 #include "lowlevel.h"
 #include "miner.h"
@@ -48,6 +50,8 @@ int HID_API_EXPORT (*dlsym_hid_write)(hid_device *, const unsigned char *, size_
 	}  \
 } while(0)
 
+static bool hidapi_libusb;
+
 static
 bool hidapi_try_lib(const char * const dlname)
 {
@@ -77,6 +81,9 @@ bool hidapi_try_lib(const char * const dlname)
 	LOAD_SYM(hid_read);
 	LOAD_SYM(hid_write);
 	
+	if (strstr(dlname, "libusb"))
+		hidapi_libusb = true;
+	
 	applog(LOG_DEBUG, "%s: Successfully loaded %s", __func__, dlname);
 	
 	return true;
@@ -160,8 +167,31 @@ struct lowlevel_device_info *hid_devinfo_scan()
 	LL_FOREACH(hid_enum, hid_item)
 	{
 		info = malloc(sizeof(struct lowlevel_device_info));
-		char * const devid = malloc(4 + strlen(hid_item->path) + 1);
-		sprintf(devid, "hid:%s", hid_item->path);
+		char *devid;
+		const char * const hidpath = hid_item->path;
+		if (hidapi_libusb
+		  && strlen(hidpath) == 12
+		  && hidpath[0] == '0'
+		  && hidpath[1] == '0'
+		  && isxdigit(hidpath[2])
+		  && isxdigit(hidpath[3])
+		  && hidpath[4] == ':'
+		  && hidpath[5] == '0'
+		  && hidpath[6] == '0'
+		  && isxdigit(hidpath[7])
+		  && isxdigit(hidpath[8])
+		  && hidpath[9] == ':')
+		{
+			unsigned char usbbus, usbaddr;
+			hex2bin(&usbbus , &hidpath[2], 1);
+			hex2bin(&usbaddr, &hidpath[7], 1);
+			devid = bfg_make_devid_usb(usbbus, usbaddr);
+		}
+		else
+		{
+			devid = malloc(4 + strlen(hid_item->path) + 1);
+			sprintf(devid, "hid:%s", hid_item->path);
+		}
 		*info = (struct lowlevel_device_info){
 			.lowl = &lowl_hid,
 			.path = strdup(hid_item->path),

+ 2 - 0
lowlevel.h

@@ -49,6 +49,8 @@ extern int lowlevel_detect_id(lowl_found_devinfo_func_t, void *, const struct lo
 extern void lowlevel_scan_free();
 
 extern struct lowlevel_device_info *lowlevel_ref(const struct lowlevel_device_info *);
+#define lowlevel_claim(drv, verbose, info)  \
+	bfg_claim_any(drv, (verbose) ? ((info)->path ?: "") : NULL, (info)->devid)
 extern void lowlevel_devinfo_semicpy(struct lowlevel_device_info *dst, const struct lowlevel_device_info *src);
 extern void lowlevel_devinfo_free(struct lowlevel_device_info *);
 

+ 27 - 2
miner.c

@@ -496,6 +496,23 @@ static void applog_and_exit(const char *fmt, ...)
 	exit(1);
 }
 
+static
+bool devpaths_match(const char * const ap, const char * const bp)
+{
+	char * const a = devpath_to_devid(ap);
+	if (!a)
+		return false;
+	char * const b = devpath_to_devid(bp);
+	bool rv = false;
+	if (b)
+	{
+		rv = !strcmp(a, b);
+		free(b);
+	}
+	free(a);
+	return rv;
+}
+
 static
 bool cgpu_match(const char * const pattern, const struct cgpu_info * const cgpu)
 {
@@ -540,7 +557,13 @@ bool cgpu_match(const char * const pattern, const struct cgpu_info * const cgpu)
 		if ((!strncmp(devser, ser, serlen)) && devser[serlen] == '\0')
 		{}  // Match
 		else
-			return false;
+		{
+			char devpath2[serlen + 1];
+			memcpy(devpath2, ser, serlen);
+			devpath2[serlen] = '\0';
+			if (!devpaths_match(devpath, ser))
+				return false;
+		}
 	}
 	else
 		n = strtol(p, (void*)&p2, 0);
@@ -10327,7 +10350,7 @@ void _scan_serial(void *p)
 static
 bool _probe_device_match(const struct lowlevel_device_info * const info, const char * const ser)
 {
-	if (!(true
+	if (!(false
 		|| (info->serial && !strcasecmp(ser, info->serial))
 		|| (info->path   && !strcasecmp(ser, info->path  ))
 	))
@@ -10450,6 +10473,8 @@ noauto: ;
 		BFG_FOREACH_DRIVER_BY_PRIORITY(dreg, dreg_tmp)
 		{
 			const struct device_drv * const drv = dreg->drv;
+			if (!drv->lowl_probe)
+				continue;
 			if (drv->lowl_probe(info))
 				return NULL;
 		}