Browse Source

Merge branch 'monarch_201405' into bfgminer

Luke Dashjr 11 years ago
parent
commit
42e9b496c7
3 changed files with 56 additions and 8 deletions
  1. 38 8
      driver-bitforce.c
  2. 17 0
      lowl-vcom.c
  3. 1 0
      lowl-vcom.h

+ 38 - 8
driver-bitforce.c

@@ -32,6 +32,8 @@
 #define BFL_PCI_VENDOR_ID 0x1cf9
 
 #define BITFORCE_SLEEP_MS 500
+#define BITFORCE_VCOM_TIMEOUT_DSEC     250
+#define BITFORCE_VCOM_TIMEOUT_DSEC_ZCX  10
 #define BITFORCE_TIMEOUT_S 7
 #define BITFORCE_TIMEOUT_MS (BITFORCE_TIMEOUT_S * 1000)
 #define BITFORCE_LONG_TIMEOUT_S 25
@@ -81,6 +83,7 @@ struct bitforce_lowl_interface {
 	void (*close)(struct cgpu_info *);
 	void (*gets)(char *, size_t, struct cgpu_info *);
 	ssize_t (*write)(struct cgpu_info *, const void *, ssize_t);
+	bool (*set_timeout)(struct cgpu_info* , uint8_t);
 };
 
 struct bitforce_data {
@@ -125,7 +128,7 @@ bool bitforce_vcom_open(struct cgpu_info * const dev)
 {
 	struct bitforce_data * const devdata = dev->device_data;
 	const char * const devpath = dev->device_path;
-	dev->device_fd = serial_open(devpath, 0, 250, true);
+	dev->device_fd = serial_open(devpath, 0, BITFORCE_VCOM_TIMEOUT_DSEC, true);
 	devdata->is_open = (dev->device_fd != -1);
 	return devdata->is_open;
 }
@@ -164,11 +167,19 @@ ssize_t bitforce_vcom_write(struct cgpu_info * const dev, const void *buf, ssize
 		return bufLen;
 }
 
+static
+bool bitforce_vcom_set_timeout(struct cgpu_info * const dev, const uint8_t timeout)
+{
+	const int fd = dev->device_fd;
+	return vcom_set_timeout(fd, timeout);
+}
+
 static struct bitforce_lowl_interface bfllif_vcom = {
 	.open = bitforce_vcom_open,
 	.close = bitforce_vcom_close,
 	.gets = bitforce_vcom_gets,
 	.write = bitforce_vcom_write,
+	.set_timeout = bitforce_vcom_set_timeout,
 };
 
 #ifdef NEED_BFG_LOWL_PCI
@@ -284,10 +295,10 @@ void bitforce_gets(char * const buf, const size_t bufLen, struct cgpu_info * con
 	struct cgpu_info * const dev = proc->device;
 	struct bitforce_data * const devdata = dev->device_data;
 	
-	if (unlikely(!devdata->is_open))
-		return;
-	
-	devdata->lowlif->gets(buf, bufLen, dev);
+	if (likely(devdata->is_open))
+		devdata->lowlif->gets(buf, bufLen, dev);
+	else
+		buf[0] = '\0';
 	
 	if (unlikely(opt_dev_protocol))
 		applog(LOG_DEBUG, "DEVPROTO: %s: GETS: %s", dev->dev_repr, buf);
@@ -379,6 +390,22 @@ void bitforce_cmd2(struct cgpu_info * const proc, void *buf, size_t bufsz, const
 	bitforce_gets(buf, bufsz, proc);
 }
 
+static
+void bitforce_zgx(struct cgpu_info * const proc, void *buf, size_t bufsz)
+{
+	struct cgpu_info * const dev = proc->device;
+	struct bitforce_data * const devdata = dev->device_data;
+	
+	if (devdata->is_open && devdata->lowlif->set_timeout)
+	{
+		devdata->lowlif->set_timeout(dev, BITFORCE_VCOM_TIMEOUT_DSEC_ZCX);
+		bitforce_cmd1b(proc, buf, bufsz, "ZGX", 3);
+		devdata->lowlif->set_timeout(dev, BITFORCE_VCOM_TIMEOUT_DSEC);
+	}
+	else
+		bitforce_cmd1b(proc, buf, bufsz, "ZGX", 3);
+}
+
 struct bitforce_init_data {
 	struct bitforce_lowl_interface *lowlif;
 	enum bitforce_style style;
@@ -440,7 +467,7 @@ bool bitforce_detect_oneof(const char * const devpath, struct bitforce_lowl_inte
 		return false;
 	}
 
-	bitforce_cmd1b(&dummy_cgpu, pdevbuf, sizeof(pdevbuf), "ZGX", 3);
+	bitforce_zgx(&dummy_cgpu, pdevbuf, sizeof(pdevbuf));
 	if (unlikely(!pdevbuf[0])) {
 		applog(LOG_DEBUG, "BFL: Error reading/timeout (ZGX)");
 		bitforce_close(&dummy_cgpu);
@@ -482,6 +509,9 @@ bool bitforce_detect_oneof(const char * const devpath, struct bitforce_lowl_inte
 		if (!strncasecmp(pdevbuf, "PROCESSOR ", 10))
 			maxchipno = max(maxchipno, atoi(&pdevbuf[10]));
 		else
+		if (!strncasecmp(pdevbuf, "CHANNEL", 7))
+			maxchipno = max(maxchipno, atoi(&pdevbuf[7]));
+		else
 		if (!strncasecmp(pdevbuf, "DEVICES IN CHAIN:", 17))
 			procs = atoi(&pdevbuf[17]);
 		else
@@ -496,7 +526,7 @@ bool bitforce_detect_oneof(const char * const devpath, struct bitforce_lowl_inte
 		else
 		if (!strncasecmp(pdevbuf, "ASIC CHANNELS:", 14))
 		{
-			procs = parallel = atoi(&pdevbuf[14]);
+			parallel = atoi(&pdevbuf[14]);
 			initdata->style = BFS_28NM;
 		}
 		else
@@ -687,7 +717,7 @@ void bitforce_reinit(struct cgpu_info *bitforce)
 	__bitforce_clear_buffer(bitforce);
 	
 	do {
-		bitforce_cmd1b(bitforce, pdevbuf, sizeof(pdevbuf), "ZGX", 3);
+		bitforce_zgx(bitforce, pdevbuf, sizeof(pdevbuf));
 		if (unlikely(!pdevbuf[0])) {
 			mutex_unlock(mutexp);
 			bitforce_close(bitforce);

+ 17 - 0
lowl-vcom.c

@@ -936,6 +936,23 @@ bool valid_baud(int baud)
 	}
 }
 
+bool vcom_set_timeout(const int fdDev, const uint8_t timeout)
+{
+#ifdef WIN32
+	const HANDLE hSerial = (HANDLE)_get_osfhandle(fdDev);
+	// Code must specify a valid timeout value (0 means don't timeout)
+	const DWORD ctoms = ((DWORD)timeout * 100);
+	COMMTIMEOUTS cto = {ctoms, 0, ctoms, 0, ctoms};
+	SetCommTimeouts(hSerial, &cto);
+#else
+	struct termios my_termios;
+	
+	tcgetattr(fdDev, &my_termios);
+	my_termios.c_cc[VTIME] = (cc_t)timeout;
+	tcsetattr(fdDev, TCSANOW, &my_termios);
+#endif
+}
+
 /* NOTE: Linux only supports uint8_t (decisecond) timeouts; limiting it in
  *       this interface buys us warnings when bad constants are passed in.
  */

+ 1 - 0
lowl-vcom.h

@@ -39,6 +39,7 @@ extern ssize_t _serial_read(int fd, char *buf, size_t buflen, char *eol);
 	_serial_read(fd, buf, bufsiz, &eol)
 extern int serial_close(int fd);
 
+extern bool vcom_set_timeout(int fd, uint8_t timeout);
 extern enum bfg_gpio_value get_serial_cts(int fd);
 extern enum bfg_gpio_value set_serial_dtr(int fd, enum bfg_gpio_value dtr);
 extern enum bfg_gpio_value set_serial_rts(int fd, enum bfg_gpio_value rts);