Browse Source

Bugfix: Avoid unnecessary rescans due to wrong devtype

Luke Dashjr 11 years ago
parent
commit
76d0cc183b
13 changed files with 55 additions and 15 deletions
  1. 1 0
      driver-bfx.c
  2. 0 2
      driver-drillbit.c
  3. 6 0
      driver-hashbuster.c
  4. 6 0
      driver-hashbusterusb.c
  5. 0 2
      driver-hashfast.c
  6. 1 0
      driver-klondike.c
  7. 1 0
      driver-nanofury.c
  8. 1 0
      driver-x6500.c
  9. 1 0
      driver-ztex.c
  10. 1 0
      lowl-vcom.c
  11. 23 11
      miner.c
  12. 8 0
      miner.h
  13. 6 0
      util.c

+ 1 - 0
driver-bfx.c

@@ -131,6 +131,7 @@ bool bfx_lowl_probe(const struct lowlevel_device_info * const info)
 		if (info->lowl != &lowl_usb)
 			applog(LOG_DEBUG, "%s: Matched \"%s\" serial \"%s\", but lowlevel driver is not ft232r!",
 			       __func__, product, serial);
+		bfg_probe_result_flags = BPR_WRONG_DEVTYPE;
 		return false;
 	}
 	

+ 0 - 2
driver-drillbit.c

@@ -47,8 +47,6 @@ struct drillbit_board {
 static
 bool drillbit_lowl_match(const struct lowlevel_device_info * const info)
 {
-	if (!lowlevel_match_id(info, &lowl_vcom, 0, 0))
-		return false;
 	return (info->manufacturer && strstr(info->manufacturer, "Drillbit"));
 }
 

+ 6 - 0
driver-hashbuster.c

@@ -175,11 +175,17 @@ bool hashbuster_lowl_probe(const struct lowlevel_device_info * const info)
 	uint8_t buf[0x40] = {'\xfe'};
 	
 	if (info->lowl != &lowl_hid)
+	{
+		bfg_probe_result_flags = BPR_WRONG_DEVTYPE;
 		applogr(false, LOG_DEBUG, "%s: Matched \"%s\" serial \"%s\", but lowlevel driver is not hid!",
 		       __func__, product, serial);
+	}
 	
 	if (info->vid != 0xFA04 || info->pid != 0x0011)
+	{
+		bfg_probe_result_flags = BPR_WRONG_DEVTYPE;
 		applogr(false, LOG_DEBUG, "%s: Wrong VID/PID", __func__);
+	}
 	
 	h = hid_open_path(path);
 	if (!h)

+ 6 - 0
driver-hashbusterusb.c

@@ -156,11 +156,17 @@ bool hashbusterusb_lowl_probe(const struct lowlevel_device_info * const info)
 	libusb_device_handle *h;
 	
 	if (info->lowl != &lowl_usb)
+	{
+		bfg_probe_result_flags = BPR_WRONG_DEVTYPE;
 		applogr(false, LOG_DEBUG, "%s: Matched \"%s\" %s, but lowlevel driver is not usb_generic!",
 		       __func__, product, info->devid);
+	}
 	
 	if (info->vid != 0xFA04 || info->pid != 0x000D)
+	{
+		bfg_probe_result_flags = BPR_WRONG_DEVTYPE;
 		applogr(false, LOG_DEBUG, "%s: Wrong VID/PID", __func__);
+	}
 	
 	libusb_device *dev = info->lowl_data;
 	if ( (j = libusb_open(dev, &h)) )

+ 0 - 2
driver-hashfast.c

@@ -203,8 +203,6 @@ ignoresome:
 static
 bool hashfast_lowl_match(const struct lowlevel_device_info * const info)
 {
-	if (!lowlevel_match_id(info, &lowl_vcom, 0, 0))
-		return false;
 	return (info->manufacturer && strstr(info->manufacturer, "HashFast"));
 }
 

+ 1 - 0
driver-klondike.c

@@ -851,6 +851,7 @@ bool klondike_lowl_probe_custom(const struct lowlevel_device_info * const info,
 {
 	if (unlikely(info->lowl != &lowl_usb))
 	{
+		bfg_probe_result_flags = BPR_WRONG_DEVTYPE;
 		applog(LOG_DEBUG, "%s: Matched \"%s\" serial \"%s\", but lowlevel driver is not usb!",
 		       __func__, info->product, info->serial);
 		goto err;

+ 1 - 0
driver-nanofury.c

@@ -245,6 +245,7 @@ bool nanofury_lowl_probe(const struct lowlevel_device_info * const info)
 	
 	if (info->lowl != &lowl_mcp2210)
 	{
+		bfg_probe_result_flags = BPR_WRONG_DEVTYPE;
 		if (info->lowl != &lowl_hid && info->lowl != &lowl_usb)
 			applog(LOG_DEBUG, "%s: Matched \"%s\" serial \"%s\", but lowlevel driver is not mcp2210!",
 			       __func__, product, serial);

+ 1 - 0
driver-x6500.c

@@ -137,6 +137,7 @@ bool x6500_lowl_probe(const struct lowlevel_device_info * const info)
 	const char * const serial = info->serial;
 	if (info->lowl != &lowl_ft232r)
 	{
+		bfg_probe_result_flags = BPR_WRONG_DEVTYPE;
 		if (info->lowl != &lowl_usb)
 			applog(LOG_DEBUG, "%s: Matched \"%s\" serial \"%s\", but lowlevel driver is not ft232r!",
 			       __func__, product, serial);

+ 1 - 0
driver-ztex.c

@@ -89,6 +89,7 @@ bool ztex_lowl_probe(const struct lowlevel_device_info * const info)
 	const char * const serial = info->serial;
 	if (info->lowl != &lowl_usb)
 	{
+		bfg_probe_result_flags = BPR_WRONG_DEVTYPE;
 		applog(LOG_DEBUG, "%s: Matched \"%s\" serial \"%s\", but lowlevel driver is not usb!",
 		       __func__, product, serial);
 		return false;

+ 1 - 0
lowl-vcom.c

@@ -684,6 +684,7 @@ bool vcom_lowl_probe_wrapper(const struct lowlevel_device_info * const info, det
 				bfg_need_detect_rescan = true;
 		}
 #endif
+		bfg_probe_result_flags = BPR_WRONG_DEVTYPE;
 		return false;
 	}
 	detectone_meta_info = (struct detectone_meta_info_t){

+ 23 - 11
miner.c

@@ -11233,6 +11233,21 @@ const struct device_drv *_probe_device_find_drv(const char * const _dname, const
 	return dreg->drv;
 }
 
+static
+bool _probe_device_do_probe(const struct device_drv * const drv, const struct lowlevel_device_info * const info, bool * const request_rescan_p)
+{
+	bfg_probe_result_flags = 0;
+	if (drv->lowl_probe(info))
+	{
+		if (!(bfg_probe_result_flags & BPR_CONTINUE_PROBES))
+			return true;
+	}
+	else
+	if (request_rescan_p && opt_hotplug && !(bfg_probe_result_flags & BPR_DONT_RESCAN))
+		*request_rescan_p = true;
+	return false;
+}
+
 static
 void *probe_device_thread(void *p)
 {
@@ -11269,11 +11284,8 @@ void *probe_device_thread(void *p)
 			const struct device_drv * const drv = _probe_device_find_drv(dname, dnamelen);
 			if (!(drv && drv->lowl_probe && drv_algo_check(drv)))
 				continue;
-			if (drv->lowl_probe(info))
+			if (_probe_device_do_probe(drv, info, &request_rescan))
 				return NULL;
-			else
-			if (opt_hotplug)
-				request_rescan = true;
 		}
 	}
 	
@@ -11311,11 +11323,8 @@ void *probe_device_thread(void *p)
 			{
 				if (!drv->lowl_match(info))
 					continue;
-				if (drv->lowl_probe(info))
+				if (_probe_device_do_probe(drv, info, &request_rescan))
 					return NULL;
-				else
-				if (opt_hotplug)
-					bfg_need_detect_rescan = true;
 			}
 		}
 	}
@@ -11336,6 +11345,7 @@ void *probe_device_thread(void *p)
 #endif
 					_probe_device_match(info, (dname[0] == '@') ? &dname[1] : dname))
 				{
+					bool dont_rescan = false;
 					BFG_FOREACH_DRIVER_BY_PRIORITY(dreg, dreg_tmp)
 					{
 						const struct device_drv * const drv = dreg->drv;
@@ -11345,10 +11355,12 @@ void *probe_device_thread(void *p)
 							continue;
 						if (!drv->lowl_probe)
 							continue;
-						if (drv->lowl_probe(info))
+						if (_probe_device_do_probe(drv, info, NULL))
 							return NULL;
+						if (bfg_probe_result_flags & BPR_DONT_RESCAN)
+							dont_rescan = true;
 					}
-					if (opt_hotplug)
+					if (opt_hotplug && !dont_rescan)
 						request_rescan = true;
 					break;
 				}
@@ -11363,7 +11375,7 @@ void *probe_device_thread(void *p)
 			const struct device_drv * const drv = _probe_device_find_drv(dname, dnamelen);
 			if (!(drv && drv->lowl_probe && drv_algo_check(drv)))
 				continue;
-			if (drv->lowl_probe(info))
+			if (_probe_device_do_probe(drv, info, NULL))
 				return NULL;
 		}
 	}

+ 8 - 0
miner.h

@@ -282,6 +282,14 @@ struct thr_info;
 struct work;
 struct lowlevel_device_info;
 
+enum bfg_probe_result_flags_values {
+	BPR_CONTINUE_PROBES = 1<< 0,
+	BPR_DONT_RESCAN     = 1<< 1,
+	BPR_WRONG_DEVTYPE   = BPR_CONTINUE_PROBES | BPR_DONT_RESCAN,
+};
+extern enum bfg_probe_result_flags_values *_bfg_probe_result_flags();
+#define bfg_probe_result_flags (*_bfg_probe_result_flags())
+
 struct device_drv {
 	const char *dname;
 	const char *name;

+ 6 - 0
util.c

@@ -3006,6 +3006,7 @@ struct bfgtls_data {
 #ifdef NEED_BFG_LOWL_VCOM
 	struct detectone_meta_info_t __detectone_meta_info;
 #endif
+	enum bfg_probe_result_flags_values probe_result_flags;
 };
 
 static
@@ -3052,6 +3053,11 @@ struct detectone_meta_info_t *_detectone_meta_info()
 }
 #endif
 
+enum bfg_probe_result_flags_values *_bfg_probe_result_flags()
+{
+	return &get_bfgtls()->probe_result_flags;
+}
+
 void bfg_init_threadlocal()
 {
 	if (pthread_key_create(&key_bfgtls, bfgtls_free))