Browse Source

ztex: Provide manuf/product/serial to cgpu interface

Luke Dashjr 12 years ago
parent
commit
d46f61e7f0
6 changed files with 30 additions and 6 deletions
  1. 3 3
      deviceapi.c
  2. 3 0
      driver-ztex.c
  3. 12 0
      libztex.c
  4. 2 0
      libztex.h
  5. 3 3
      miner.h
  6. 7 0
      util.h

+ 3 - 3
deviceapi.c

@@ -618,9 +618,9 @@ bool add_cgpu(struct cgpu_info *cgpu)
 	strcpy(cgpu->proc_repr, cgpu->dev_repr);
 	strcpy(cgpu->proc_repr, cgpu->dev_repr);
 	sprintf(cgpu->proc_repr_ns, "%s%u", cgpu->drv->name, cgpu->device_id);
 	sprintf(cgpu->proc_repr_ns, "%s%u", cgpu->drv->name, cgpu->device_id);
 	
 	
-	cgpu->dev_manufacturer = maybe_strdup(detectone_meta_info.manufacturer);
-	cgpu->dev_product = maybe_strdup(detectone_meta_info.product);
-	cgpu->dev_serial = maybe_strdup(detectone_meta_info.serial);
+	maybe_strdup_if_null(&cgpu->dev_manufacturer, detectone_meta_info.manufacturer);
+	maybe_strdup_if_null(&cgpu->dev_product,      detectone_meta_info.product);
+	maybe_strdup_if_null(&cgpu->dev_serial,       detectone_meta_info.serial);
 	
 	
 	devices_new = realloc(devices_new, sizeof(struct cgpu_info *) * (total_devices_new + lpcount + 1));
 	devices_new = realloc(devices_new, sizeof(struct cgpu_info *) * (total_devices_new + lpcount + 1));
 	devices_new[total_devices_new++] = cgpu;
 	devices_new[total_devices_new++] = cgpu;

+ 3 - 0
driver-ztex.c

@@ -61,6 +61,9 @@ static struct cgpu_info *ztex_setup(struct libztex_device *dev, int fpgacount)
 	ztex->device_ztex = dev;
 	ztex->device_ztex = dev;
 	ztex->procs = fpgacount;
 	ztex->procs = fpgacount;
 	ztex->threads = fpgacount;
 	ztex->threads = fpgacount;
+	ztex->dev_manufacturer = dev->dev_manufacturer;
+	ztex->dev_product = dev->dev_product;
+	ztex->dev_serial = (char*)&dev->snString[0];
 	add_cgpu(ztex);
 	add_cgpu(ztex);
 	strcpy(ztex->device_ztex->repr, ztex->dev_repr);
 	strcpy(ztex->device_ztex->repr, ztex->dev_repr);
 	ztex->name = fpganame;
 	ztex->name = fpganame;

+ 12 - 0
libztex.c

@@ -627,6 +627,18 @@ int libztex_prepare_device(struct libusb_device *dev, struct libztex_device** zt
 		applog(LOG_ERR, "Ztex check device: Failed to read device snString with err %d", cnt);
 		applog(LOG_ERR, "Ztex check device: Failed to read device snString with err %d", cnt);
 		return cnt;
 		return cnt;
 	}
 	}
+	
+	cnt = libztex_get_string_descriptor_ascii(newdev->hndl, newdev->descriptor.iProduct, buf, sizeof(buf));
+	if (unlikely(cnt < 0))
+		applog(LOG_WARNING, "Ztex check device: Failed to read device product with err %d", cnt);
+	else
+		newdev->dev_product = buf[0] ? strdup((void*)buf) : NULL;
+	
+	cnt = libztex_get_string_descriptor_ascii(newdev->hndl, newdev->descriptor.iManufacturer, buf, sizeof(buf));
+	if (unlikely(cnt < 0))
+		applog(LOG_WARNING, "Ztex check device: Failed to read device manufacturer with err %d", cnt);
+	else
+		newdev->dev_manufacturer = buf[0] ? strdup((void*)buf) : NULL;
 
 
 	cnt = libusb_control_transfer(newdev->hndl, 0xc0, 0x22, 0, 0, buf, 40, 500);
 	cnt = libusb_control_transfer(newdev->hndl, 0xc0, 0x22, 0, 0, buf, 40, 500);
 	if (unlikely(cnt < 0)) {
 	if (unlikely(cnt < 0)) {

+ 2 - 0
libztex.h

@@ -27,6 +27,8 @@ struct libztex_device {
 	libusb_device_handle *hndl; 
 	libusb_device_handle *hndl; 
 	unsigned char usbbus;
 	unsigned char usbbus;
 	unsigned char usbaddress;
 	unsigned char usbaddress;
+	char *dev_manufacturer;
+	char *dev_product;
 	unsigned char snString[LIBZTEX_SNSTRING_LEN+1];
 	unsigned char snString[LIBZTEX_SNSTRING_LEN+1];
 	unsigned char productId[4];
 	unsigned char productId[4];
 	unsigned char fwVersion;
 	unsigned char fwVersion;

+ 3 - 3
miner.h

@@ -446,9 +446,9 @@ struct cgpu_info {
 	
 	
 	const char *device_path;
 	const char *device_path;
 	void *device_data;
 	void *device_data;
-	char *dev_manufacturer;
-	char *dev_product;
-	char *dev_serial;
+	const char *dev_manufacturer;
+	const char *dev_product;
+	const char *dev_serial;
 	union {
 	union {
 #ifdef USE_ZTEX
 #ifdef USE_ZTEX
 		struct libztex_device *device_ztex;
 		struct libztex_device *device_ztex;

+ 7 - 0
util.h

@@ -203,5 +203,12 @@ char *maybe_strdup(const char *s)
 	return s ? strdup(s) : NULL;
 	return s ? strdup(s) : NULL;
 }
 }
 
 
+static inline
+void maybe_strdup_if_null(const char **p, const char *s)
+{
+	if (!*p)
+		*p = maybe_strdup(s);
+}
+
 
 
 #endif /* __UTIL_H__ */
 #endif /* __UTIL_H__ */