* [PATCH v1 0/4] Enable to set DbC strings through sysfs
@ 2025-09-29 9:02 Łukasz Bartosik
2025-09-29 9:02 ` [PATCH v1 1/4] xhci: dbc: prepare to expose " Łukasz Bartosik
` (3 more replies)
0 siblings, 4 replies; 8+ messages in thread
From: Łukasz Bartosik @ 2025-09-29 9:02 UTC (permalink / raw)
To: Mathias Nyman, Greg Kroah-Hartman; +Cc: linux-usb, Łukasz Bartosik
From: Łukasz Bartosik <ukaszb@chromium.org>
This patchset enables setting DbC serial number,
product name and manufacturer name through sysfs.
Testing performed with this patchset:
1.DbC is enabled and enumerates on host side with the following
default values of product, manufactuer and serial values:
"
[496803.112431] usb 2-4: new SuperSpeed USB device number 106 using xhci_hcd
[496803.128540] usb 2-4: LPM exit latency is zeroed, disabling LPM.
[496803.129387] usb 2-4: New USB device found, idVendor=18d1, idProduct=0010, bcdDevice= 0.10
[496803.130173] usb 2-4: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[496803.130858] usb 2-4: Product: Linux USB Debug Target
[496803.131343] usb 2-4: Manufacturer: Linux Foundation
[496803.131821] usb 2-4: SerialNumber: 0001
```
View default DbC values in sysfs:
"
cat /sys/bus/pci/devices/0000:00:14.0/dbc_iProduct
Linux USB Debug Target
cat /sys/bus/pci/devices/0000:00:14.0/dbc_iManufacturer
Linux Foundation
cat /sys/bus/pci/devices/0000:00:14.0/dbc_iSerial
0001
"
2. Set product, manufacturer and serial to empty:
echo disable > /sys/bus/pci/devices/0000:00:14.0/dbc
echo "" > /sys/bus/pci/devices/0000:00:14.0/dbc_iProduct
echo "" > /sys/bus/pci/devices/0000:00:14.0/dbc_iManufacturer
echo "" > /sys/bus/pci/devices/0000:00:14.0/dbc_iSerial
echo enable > /sys/bus/pci/devices/0000:00:14.0/dbc
Verify through sysfs empty values were set:
"
cat /sys/bus/pci/devices/0000:00:14.0/dbc_iProduct
cat /sys/bus/pci/devices/0000:00:14.0/dbc_iManufacturer
cat /sys/bus/pci/devices/0000:00:14.0/dbc_iSerial
"
Verify DbC enumerates with empty values:
"
lsusb -s 2:115 -v
Bus 002 Device 115: ID 18d1:0010 Google Inc.
Negotiated speed: SuperSpeed (5Gbps)
Device Descriptor:
bLength 18
bDescriptorType 1
bcdUSB 3.10
bDeviceClass 0 [unknown]
bDeviceSubClass 0 [unknown]
bDeviceProtocol 0
bMaxPacketSize0 9
idVendor 0x18d1 Google Inc.
idProduct 0x0010
bcdDevice 0.10
iManufacturer 1
iProduct 2
iSerial 3
"
3. Update product, manufacturer and serial values:
echo disable > /sys/bus/pci/devices/0000:00:14.0/dbc
echo "New_product_name" > /sys/bus/pci/devices/0000:00:14.0/dbc_iProduct
echo "New_manufacturer_name" > /sys/bus/pci/devices/0000:00:14.0/dbc_iManufacturer
echo "ABCDEF123456" > /sys/bus/pci/devices/0000:00:14.0/dbc_iSerial
echo enable > /sys/bus/pci/devices/0000:00:14.0/dbc
Verify through sysfs new values were set:
"
cat /sys/bus/pci/devices/0000:00:14.0/dbc_iProduct
New_product_name
cat /sys/bus/pci/devices/0000:00:14.0/dbc_iManufacturer
New_manufacturer_name
cat /sys/bus/pci/devices/0000:00:14.0/dbc_iSerial
ABCDEF123456
"
Verify DbC enumerates with new values:
"
[497908.814834] usb 2-4: new SuperSpeed USB device number 108 using xhci_hcd
[497908.831057] usb 2-4: LPM exit latency is zeroed, disabling LPM.
[497908.844994] usb 2-4: New USB device found, idVendor=18d1, idProduct=0010, bcdDevice= 0.10
[497908.845797] usb 2-4: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[497908.846482] usb 2-4: Product: New_product_name
[497908.846965] usb 2-4: Manufacturer: New_manufacturer_name
[497908.847505] usb 2-4: SerialNumber: ABCDEF123456
"
4. Try to update product, manufacturer and serial values with new values longer
than maximum 63 characters (half of USB_MAX_STRING_LEN):
echo disable > /sys/bus/pci/devices/0000:00:14.0/dbc
echo "AAAAAAAAA_BBBBBBBBB_CCCCCCCCC_DDDDDDDDD_EEEEEEEEE_FFFFFFFFF_GGGG" > /sys/bus/pci/devices/0000:00:14.0/dbc_iProduct
echo "HHHHHHHHH_IIIIIIIII_JJJJJJJJJ_KKKKKKKKK_LLLLLLLLL_MMMMMMMMM_NNNN" > /sys/bus/pci/devices/0000:00:14.0/dbc_iManufacturer
echo "OOOOOOOOO_PPPPPPPPP_RRRRRRRRR_SSSSSSSSS_TTTTTTTTT_WWWWWWWWW_YYYY" > /sys/bus/pci/devices/0000:00:14.0/dbc_iSerial
echo enable > /sys/bus/pci/devices/0000:00:14.0/dbc
Verify through sysfs new values were not set:
"
cat /sys/bus/pci/devices/0000:00:14.0/dbc_iProduct
New_product_name
cat /sys/bus/pci/devices/0000:00:14.0/dbc_iManufacturer
New_manufacturer_name
cat /sys/bus/pci/devices/0000:00:14.0/dbc_iSerial
ABCDEF123456
"
Verify DbC enumerates with previous values:
"
[497908.814834] usb 2-4: new SuperSpeed USB device number 108 using xhci_hcd
[497908.831057] usb 2-4: LPM exit latency is zeroed, disabling LPM.
[497908.844994] usb 2-4: New USB device found, idVendor=18d1, idProduct=0010, bcdDevice= 0.10
[497908.845797] usb 2-4: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[497908.846482] usb 2-4: Product: New_product_name
[497908.846965] usb 2-4: Manufacturer: New_manufacturer_name
[497908.847505] usb 2-4: SerialNumber: ABCDEF123456
"
5. Update product, manufacturer and serial values with new values
whose length is maximum 63 characters (half of USB_MAX_STRING_LEN):
echo disable > /sys/bus/pci/devices/0000:00:14.0/dbc
echo "AAAAAAAAA_BBBBBBBBB_CCCCCCCCC_DDDDDDDDD_EEEEEEEEE_FFFFFFFFF_GGG" > /sys/bus/pci/devices/0000:00:14.0/dbc_iProduct
echo "HHHHHHHHH_IIIIIIIII_JJJJJJJJJ_KKKKKKKKK_LLLLLLLLL_MMMMMMMMM_NNN" > /sys/bus/pci/devices/0000:00:14.0/dbc_iManufacturer
echo "OOOOOOOOO_PPPPPPPPP_RRRRRRRRR_SSSSSSSSS_TTTTTTTTT_WWWWWWWWW_YYY" > /sys/bus/pci/devices/0000:00:14.0/dbc_iSerial
echo enable > /sys/bus/pci/devices/0000:00:14.0/dbc
Verify through sysfs new values were set:
"
cat /sys/bus/pci/devices/0000:00:14.0/dbc_iProduct
AAAAAAAAA_BBBBBBBBB_CCCCCCCCC_DDDDDDDDD_EEEEEEEEE_FFFFFFFFF_GGG
cat /sys/bus/pci/devices/0000:00:14.0/dbc_iManufacturer
HHHHHHHHH_IIIIIIIII_JJJJJJJJJ_KKKKKKKKK_LLLLLLLLL_MMMMMMMMM_NNN
cat /sys/bus/pci/devices/0000:00:14.0/dbc_iSerial
OOOOOOOOO_PPPPPPPPP_RRRRRRRRR_SSSSSSSSS_TTTTTTTTT_WWWWWWWWW_YYY
"
Verify DbC enumerates with new values:
"
[499856.473572] usb 2-4: new SuperSpeed USB device number 119 using xhci_hcd
[499856.489786] usb 2-4: LPM exit latency is zeroed, disabling LPM.
[499856.492080] usb 2-4: New USB device found, idVendor=18d1, idProduct=0010, bcdDevice= 0.10
[499856.492871] usb 2-4: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[499856.493624] usb 2-4: Product: AAAAAAAAA_BBBBBBBBB_CCCCCCCCC_DDDDDDDDD_EEEEEEEEE_FFFFFFFFF_GGG
[499856.494445] usb 2-4: Manufacturer: HHHHHHHHH_IIIIIIIII_JJJJJJJJJ_KKKKKKKKK_LLLLLLLLL_MMMMMMMMM_NNN
[499856.495307] usb 2-4: SerialNumber: OOOOOOOOO_PPPPPPPPP_RRRRRRRRR_SSSSSSSSS_TTTTTTTTT_WWWWWWWWW_YYY
"
Łukasz Bartosik (4):
xhci: dbc: prepare to expose strings through sysfs
xhci: dbc: allow to set serial number through sysfs
xhci: dbc: allow to set product name through sysfs
xhci: dbc: allow to set manufacturer name through sysfs
drivers/usb/host/xhci-dbgcap.c | 240 ++++++++++++++++++++++++---------
drivers/usb/host/xhci-dbgcap.h | 24 ++--
2 files changed, 189 insertions(+), 75 deletions(-)
--
2.51.0.536.g15c5d4f767-goog
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH v1 1/4] xhci: dbc: prepare to expose strings through sysfs
2025-09-29 9:02 [PATCH v1 0/4] Enable to set DbC strings through sysfs Łukasz Bartosik
@ 2025-09-29 9:02 ` Łukasz Bartosik
2025-09-29 9:02 ` [PATCH v1 2/4] xhci: dbc: allow to set serial number " Łukasz Bartosik
` (2 subsequent siblings)
3 siblings, 0 replies; 8+ messages in thread
From: Łukasz Bartosik @ 2025-09-29 9:02 UTC (permalink / raw)
To: Mathias Nyman, Greg Kroah-Hartman; +Cc: linux-usb, Łukasz Bartosik
From: Łukasz Bartosik <ukaszb@chromium.org>
Reorganize the code to prepare ground for setting serial number,
product and manufacturer names through sysfs. This commit:
1. Introduces new buffers for storing serial number, product and
manufacturer name in utf8. The buffers will be used by sysfs
*_show and *_store functions.
2. Increases USB string descriptor data maximum length to the
value from USB specification (126 bytes of data).
3. Adds new helper functions get_str_desc_len, prepare_len
and xhci_dbc_populate_str_desc.
Signed-off-by: Łukasz Bartosik <ukaszb@chromium.org>
---
drivers/usb/host/xhci-dbgcap.c | 145 ++++++++++++++++++---------------
drivers/usb/host/xhci-dbgcap.h | 24 ++++--
2 files changed, 94 insertions(+), 75 deletions(-)
diff --git a/drivers/usb/host/xhci-dbgcap.c b/drivers/usb/host/xhci-dbgcap.c
index 63edf2d8f245..c2fecaffd6f3 100644
--- a/drivers/usb/host/xhci-dbgcap.c
+++ b/drivers/usb/host/xhci-dbgcap.c
@@ -52,55 +52,6 @@ static void dbc_ring_free(struct device *dev, struct xhci_ring *ring)
kfree(ring);
}
-static u32 xhci_dbc_populate_strings(struct dbc_str_descs *strings)
-{
- struct usb_string_descriptor *s_desc;
- u32 string_length;
-
- /* Serial string: */
- s_desc = (struct usb_string_descriptor *)strings->serial;
- utf8s_to_utf16s(DBC_STRING_SERIAL, strlen(DBC_STRING_SERIAL),
- UTF16_LITTLE_ENDIAN, (wchar_t *)s_desc->wData,
- DBC_MAX_STRING_LENGTH);
-
- s_desc->bLength = (strlen(DBC_STRING_SERIAL) + 1) * 2;
- s_desc->bDescriptorType = USB_DT_STRING;
- string_length = s_desc->bLength;
- string_length <<= 8;
-
- /* Product string: */
- s_desc = (struct usb_string_descriptor *)strings->product;
- utf8s_to_utf16s(DBC_STRING_PRODUCT, strlen(DBC_STRING_PRODUCT),
- UTF16_LITTLE_ENDIAN, (wchar_t *)s_desc->wData,
- DBC_MAX_STRING_LENGTH);
-
- s_desc->bLength = (strlen(DBC_STRING_PRODUCT) + 1) * 2;
- s_desc->bDescriptorType = USB_DT_STRING;
- string_length += s_desc->bLength;
- string_length <<= 8;
-
- /* Manufacture string: */
- s_desc = (struct usb_string_descriptor *)strings->manufacturer;
- utf8s_to_utf16s(DBC_STRING_MANUFACTURER,
- strlen(DBC_STRING_MANUFACTURER),
- UTF16_LITTLE_ENDIAN, (wchar_t *)s_desc->wData,
- DBC_MAX_STRING_LENGTH);
-
- s_desc->bLength = (strlen(DBC_STRING_MANUFACTURER) + 1) * 2;
- s_desc->bDescriptorType = USB_DT_STRING;
- string_length += s_desc->bLength;
- string_length <<= 8;
-
- /* String0: */
- strings->string0[0] = 4;
- strings->string0[1] = USB_DT_STRING;
- strings->string0[2] = 0x09;
- strings->string0[3] = 0x04;
- string_length += 4;
-
- return string_length;
-}
-
static void xhci_dbc_init_ep_contexts(struct xhci_dbc *dbc)
{
struct xhci_ep_ctx *ep_ctx;
@@ -124,7 +75,63 @@ static void xhci_dbc_init_ep_contexts(struct xhci_dbc *dbc)
ep_ctx->deq = cpu_to_le64(deq | dbc->ring_in->cycle_state);
}
-static void xhci_dbc_init_contexts(struct xhci_dbc *dbc, u32 string_length)
+static u8 get_str_desc_len(const char *desc)
+{
+ return ((struct usb_string_descriptor *)desc)->bLength;
+}
+
+static u32 prepare_len(struct dbc_str_descs *descs)
+{
+ u32 len;
+
+ len = get_str_desc_len(descs->serial);
+ len <<= 8;
+ len += get_str_desc_len(descs->product);
+ len <<= 8;
+ len += get_str_desc_len(descs->manufacturer);
+ len <<= 8;
+ len += get_str_desc_len(descs->string0);
+
+ return len;
+}
+
+static int xhci_dbc_populate_str_desc(char *desc, const char *src)
+{
+ struct usb_string_descriptor *s_desc;
+ int utf16_len;
+
+ s_desc = (struct usb_string_descriptor *)desc;
+ utf16_len = utf8s_to_utf16s(src, strlen(src), UTF16_LITTLE_ENDIAN,
+ (wchar_t *)s_desc->wData, USB_MAX_STRING_LEN);
+ if (utf16_len < 0)
+ return utf16_len;
+
+ s_desc->bLength = utf16_len * 2 + 2;
+ s_desc->bDescriptorType = USB_DT_STRING;
+
+ return s_desc->bLength;
+}
+
+static void xhci_dbc_populate_str_descs(struct dbc_str_descs *str_descs,
+ struct dbc_str *str)
+{
+ /* Serial string: */
+ xhci_dbc_populate_str_desc(str_descs->serial, str->serial);
+
+ /* Product string: */
+ xhci_dbc_populate_str_desc(str_descs->product, str->product);
+
+ /* Manufacturer string: */
+ xhci_dbc_populate_str_desc(str_descs->manufacturer, str->manufacturer);
+
+ /* String0: */
+ str_descs->string0[0] = 4;
+ str_descs->string0[1] = USB_DT_STRING;
+ str_descs->string0[2] = 0x09;
+ str_descs->string0[3] = 0x04;
+}
+
+static void xhci_dbc_init_contexts(struct xhci_dbc *dbc)
{
struct dbc_info_context *info;
u32 dev_info;
@@ -135,12 +142,12 @@ static void xhci_dbc_init_contexts(struct xhci_dbc *dbc, u32 string_length)
/* Populate info Context: */
info = (struct dbc_info_context *)dbc->ctx->bytes;
- dma = dbc->string_dma;
+ dma = dbc->str_descs_dma;
info->string0 = cpu_to_le64(dma);
- info->manufacturer = cpu_to_le64(dma + DBC_MAX_STRING_LENGTH);
- info->product = cpu_to_le64(dma + DBC_MAX_STRING_LENGTH * 2);
- info->serial = cpu_to_le64(dma + DBC_MAX_STRING_LENGTH * 3);
- info->length = cpu_to_le32(string_length);
+ info->manufacturer = cpu_to_le64(dma + USB_MAX_STRING_DESC_LEN);
+ info->product = cpu_to_le64(dma + USB_MAX_STRING_DESC_LEN*2);
+ info->serial = cpu_to_le64(dma + USB_MAX_STRING_DESC_LEN*3);
+ info->length = cpu_to_le32(prepare_len(dbc->str_descs));
/* Populate bulk in and out endpoint contexts: */
xhci_dbc_init_ep_contexts(dbc);
@@ -525,7 +532,6 @@ static int xhci_dbc_mem_init(struct xhci_dbc *dbc, gfp_t flags)
{
int ret;
dma_addr_t deq;
- u32 string_length;
struct device *dev = dbc->dev;
/* Allocate various rings for events and transfers: */
@@ -552,11 +558,11 @@ static int xhci_dbc_mem_init(struct xhci_dbc *dbc, gfp_t flags)
goto ctx_fail;
/* Allocate the string table: */
- dbc->string_size = sizeof(*dbc->string);
- dbc->string = dma_alloc_coherent(dev, dbc->string_size,
- &dbc->string_dma, flags);
- if (!dbc->string)
- goto string_fail;
+ dbc->str_descs_size = sizeof(*dbc->str_descs);
+ dbc->str_descs = dma_alloc_coherent(dev, dbc->str_descs_size,
+ &dbc->str_descs_dma, flags);
+ if (!dbc->str_descs)
+ goto str_descs_fail;
/* Setup ERST register: */
writel(dbc->erst.num_entries, &dbc->regs->ersts);
@@ -566,16 +572,16 @@ static int xhci_dbc_mem_init(struct xhci_dbc *dbc, gfp_t flags)
dbc->ring_evt->dequeue);
lo_hi_writeq(deq, &dbc->regs->erdp);
- /* Setup strings and contexts: */
- string_length = xhci_dbc_populate_strings(dbc->string);
- xhci_dbc_init_contexts(dbc, string_length);
+ /* Setup string descriptors and contexts: */
+ xhci_dbc_populate_str_descs(dbc->str_descs, &dbc->str);
+ xhci_dbc_init_contexts(dbc);
xhci_dbc_eps_init(dbc);
dbc->state = DS_INITIALIZED;
return 0;
-string_fail:
+str_descs_fail:
dbc_free_ctx(dev, dbc->ctx);
dbc->ctx = NULL;
ctx_fail:
@@ -600,8 +606,8 @@ static void xhci_dbc_mem_cleanup(struct xhci_dbc *dbc)
xhci_dbc_eps_exit(dbc);
- dma_free_coherent(dbc->dev, dbc->string_size, dbc->string, dbc->string_dma);
- dbc->string = NULL;
+ dma_free_coherent(dbc->dev, dbc->str_descs_size, dbc->str_descs, dbc->str_descs_dma);
+ dbc->str_descs = NULL;
dbc_free_ctx(dbc->dev, dbc->ctx);
dbc->ctx = NULL;
@@ -1314,6 +1320,11 @@ xhci_alloc_dbc(struct device *dev, void __iomem *base, const struct dbc_driver *
dbc->bInterfaceProtocol = DBC_PROTOCOL;
dbc->poll_interval = DBC_POLL_INTERVAL_DEFAULT;
+ /* initialize serial, product and manufacturer with default values */
+ memcpy(dbc->str.serial, DBC_STRING_SERIAL, strlen(DBC_STRING_SERIAL)+1);
+ memcpy(dbc->str.product, DBC_STRING_PRODUCT, strlen(DBC_STRING_PRODUCT)+1);
+ memcpy(dbc->str.manufacturer, DBC_STRING_MANUFACTURER, strlen(DBC_STRING_MANUFACTURER)+1);
+
if (readl(&dbc->regs->control) & DBC_CTRL_DBC_ENABLE)
goto err;
diff --git a/drivers/usb/host/xhci-dbgcap.h b/drivers/usb/host/xhci-dbgcap.h
index 47ac72c2286d..0e6addafea6c 100644
--- a/drivers/usb/host/xhci-dbgcap.h
+++ b/drivers/usb/host/xhci-dbgcap.h
@@ -47,7 +47,6 @@ struct dbc_info_context {
#define DBC_DOOR_BELL_TARGET(p) (((p) & 0xff) << 8)
#define DBC_MAX_PACKET 1024
-#define DBC_MAX_STRING_LENGTH 64
#define DBC_STRING_MANUFACTURER "Linux Foundation"
#define DBC_STRING_PRODUCT "Linux USB Debug Target"
#define DBC_STRING_SERIAL "0001"
@@ -63,11 +62,19 @@ struct dbc_info_context {
#define DBC_PORTSC_LINK_CHANGE BIT(22)
#define DBC_PORTSC_CONFIG_CHANGE BIT(23)
+#define USB_MAX_STRING_DESC_LEN (USB_MAX_STRING_LEN + 2)
+
struct dbc_str_descs {
- char string0[DBC_MAX_STRING_LENGTH];
- char manufacturer[DBC_MAX_STRING_LENGTH];
- char product[DBC_MAX_STRING_LENGTH];
- char serial[DBC_MAX_STRING_LENGTH];
+ char string0[USB_MAX_STRING_DESC_LEN];
+ char manufacturer[USB_MAX_STRING_DESC_LEN];
+ char product[USB_MAX_STRING_DESC_LEN];
+ char serial[USB_MAX_STRING_DESC_LEN];
+};
+
+struct dbc_str {
+ char manufacturer[USB_MAX_STRING_LEN/2+1];
+ char product[USB_MAX_STRING_LEN/2+1];
+ char serial[USB_MAX_STRING_LEN/2+1];
};
#define DBC_PROTOCOL 1 /* GNU Remote Debug Command */
@@ -132,9 +139,10 @@ struct xhci_dbc {
struct xhci_erst erst;
struct xhci_container_ctx *ctx;
- struct dbc_str_descs *string;
- dma_addr_t string_dma;
- size_t string_size;
+ struct dbc_str_descs *str_descs;
+ dma_addr_t str_descs_dma;
+ size_t str_descs_size;
+ struct dbc_str str;
u16 idVendor;
u16 idProduct;
u16 bcdDevice;
--
2.51.0.536.g15c5d4f767-goog
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH v1 2/4] xhci: dbc: allow to set serial number through sysfs
2025-09-29 9:02 [PATCH v1 0/4] Enable to set DbC strings through sysfs Łukasz Bartosik
2025-09-29 9:02 ` [PATCH v1 1/4] xhci: dbc: prepare to expose " Łukasz Bartosik
@ 2025-09-29 9:02 ` Łukasz Bartosik
2025-09-29 12:59 ` Greg Kroah-Hartman
2025-09-29 13:00 ` Greg Kroah-Hartman
2025-09-29 9:02 ` [PATCH v1 3/4] xhci: dbc: allow to set product name " Łukasz Bartosik
2025-09-29 9:02 ` [PATCH v1 4/4] xhci: dbc: allow to set manufacturer " Łukasz Bartosik
3 siblings, 2 replies; 8+ messages in thread
From: Łukasz Bartosik @ 2025-09-29 9:02 UTC (permalink / raw)
To: Mathias Nyman, Greg Kroah-Hartman; +Cc: linux-usb, Łukasz Bartosik
From: Łukasz Bartosik <ukaszb@chromium.org>
Add code which allows to set serial number of a DbC
device through sysfs.
Signed-off-by: Łukasz Bartosik <ukaszb@chromium.org>
---
drivers/usb/host/xhci-dbgcap.c | 32 ++++++++++++++++++++++++++++++++
1 file changed, 32 insertions(+)
diff --git a/drivers/usb/host/xhci-dbgcap.c b/drivers/usb/host/xhci-dbgcap.c
index c2fecaffd6f3..5cc201afe8f4 100644
--- a/drivers/usb/host/xhci-dbgcap.c
+++ b/drivers/usb/host/xhci-dbgcap.c
@@ -1200,6 +1200,36 @@ static ssize_t dbc_bcdDevice_store(struct device *dev,
return size;
}
+static ssize_t dbc_iSerial_show(struct device *dev,
+ struct device_attribute *attr,
+ char *buf)
+{
+ struct xhci_hcd *xhci = hcd_to_xhci(dev_get_drvdata(dev));
+ struct xhci_dbc *dbc = xhci->dbc;
+
+ return sysfs_emit(buf, "%s\n", dbc->str.serial);
+}
+
+static ssize_t dbc_iSerial_store(struct device *dev,
+ struct device_attribute *attr,
+ const char *buf, size_t size)
+{
+ struct xhci_hcd *xhci = hcd_to_xhci(dev_get_drvdata(dev));
+ struct xhci_dbc *dbc = xhci->dbc;
+
+ if (dbc->state != DS_DISABLED)
+ return -EBUSY;
+
+ if (size > USB_MAX_STRING_LEN/2+1)
+ return -E2BIG;
+
+ memcpy(dbc->str.serial, buf, size);
+ /* remove newline and terminate the string */
+ dbc->str.serial[size-1] = '\0';
+
+ return size;
+}
+
static ssize_t dbc_bInterfaceProtocol_show(struct device *dev,
struct device_attribute *attr,
char *buf)
@@ -1287,6 +1317,7 @@ static DEVICE_ATTR_RW(dbc);
static DEVICE_ATTR_RW(dbc_idVendor);
static DEVICE_ATTR_RW(dbc_idProduct);
static DEVICE_ATTR_RW(dbc_bcdDevice);
+static DEVICE_ATTR_RW(dbc_iSerial);
static DEVICE_ATTR_RW(dbc_bInterfaceProtocol);
static DEVICE_ATTR_RW(dbc_poll_interval_ms);
@@ -1295,6 +1326,7 @@ static struct attribute *dbc_dev_attrs[] = {
&dev_attr_dbc_idVendor.attr,
&dev_attr_dbc_idProduct.attr,
&dev_attr_dbc_bcdDevice.attr,
+ &dev_attr_dbc_iSerial.attr,
&dev_attr_dbc_bInterfaceProtocol.attr,
&dev_attr_dbc_poll_interval_ms.attr,
NULL
--
2.51.0.536.g15c5d4f767-goog
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH v1 3/4] xhci: dbc: allow to set product name through sysfs
2025-09-29 9:02 [PATCH v1 0/4] Enable to set DbC strings through sysfs Łukasz Bartosik
2025-09-29 9:02 ` [PATCH v1 1/4] xhci: dbc: prepare to expose " Łukasz Bartosik
2025-09-29 9:02 ` [PATCH v1 2/4] xhci: dbc: allow to set serial number " Łukasz Bartosik
@ 2025-09-29 9:02 ` Łukasz Bartosik
2025-09-29 9:02 ` [PATCH v1 4/4] xhci: dbc: allow to set manufacturer " Łukasz Bartosik
3 siblings, 0 replies; 8+ messages in thread
From: Łukasz Bartosik @ 2025-09-29 9:02 UTC (permalink / raw)
To: Mathias Nyman, Greg Kroah-Hartman; +Cc: linux-usb, Łukasz Bartosik
From: Łukasz Bartosik <ukaszb@chromium.org>
Add code which allows to set product name of a DbC
device through sysfs.
Signed-off-by: Łukasz Bartosik <ukaszb@chromium.org>
---
drivers/usb/host/xhci-dbgcap.c | 32 ++++++++++++++++++++++++++++++++
1 file changed, 32 insertions(+)
diff --git a/drivers/usb/host/xhci-dbgcap.c b/drivers/usb/host/xhci-dbgcap.c
index 5cc201afe8f4..31fa3c7c63e4 100644
--- a/drivers/usb/host/xhci-dbgcap.c
+++ b/drivers/usb/host/xhci-dbgcap.c
@@ -1200,6 +1200,36 @@ static ssize_t dbc_bcdDevice_store(struct device *dev,
return size;
}
+static ssize_t dbc_iProduct_show(struct device *dev,
+ struct device_attribute *attr,
+ char *buf)
+{
+ struct xhci_hcd *xhci = hcd_to_xhci(dev_get_drvdata(dev));
+ struct xhci_dbc *dbc = xhci->dbc;
+
+ return sysfs_emit(buf, "%s\n", dbc->str.product);
+}
+
+static ssize_t dbc_iProduct_store(struct device *dev,
+ struct device_attribute *attr,
+ const char *buf, size_t size)
+{
+ struct xhci_hcd *xhci = hcd_to_xhci(dev_get_drvdata(dev));
+ struct xhci_dbc *dbc = xhci->dbc;
+
+ if (dbc->state != DS_DISABLED)
+ return -EBUSY;
+
+ if (size > USB_MAX_STRING_LEN/2+1)
+ return -E2BIG;
+
+ memcpy(dbc->str.product, buf, size);
+ /* remove newline and terminate the string */
+ dbc->str.product[size-1] = '\0';
+
+ return size;
+}
+
static ssize_t dbc_iSerial_show(struct device *dev,
struct device_attribute *attr,
char *buf)
@@ -1317,6 +1347,7 @@ static DEVICE_ATTR_RW(dbc);
static DEVICE_ATTR_RW(dbc_idVendor);
static DEVICE_ATTR_RW(dbc_idProduct);
static DEVICE_ATTR_RW(dbc_bcdDevice);
+static DEVICE_ATTR_RW(dbc_iProduct);
static DEVICE_ATTR_RW(dbc_iSerial);
static DEVICE_ATTR_RW(dbc_bInterfaceProtocol);
static DEVICE_ATTR_RW(dbc_poll_interval_ms);
@@ -1326,6 +1357,7 @@ static struct attribute *dbc_dev_attrs[] = {
&dev_attr_dbc_idVendor.attr,
&dev_attr_dbc_idProduct.attr,
&dev_attr_dbc_bcdDevice.attr,
+ &dev_attr_dbc_iProduct.attr,
&dev_attr_dbc_iSerial.attr,
&dev_attr_dbc_bInterfaceProtocol.attr,
&dev_attr_dbc_poll_interval_ms.attr,
--
2.51.0.536.g15c5d4f767-goog
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH v1 4/4] xhci: dbc: allow to set manufacturer name through sysfs
2025-09-29 9:02 [PATCH v1 0/4] Enable to set DbC strings through sysfs Łukasz Bartosik
` (2 preceding siblings ...)
2025-09-29 9:02 ` [PATCH v1 3/4] xhci: dbc: allow to set product name " Łukasz Bartosik
@ 2025-09-29 9:02 ` Łukasz Bartosik
3 siblings, 0 replies; 8+ messages in thread
From: Łukasz Bartosik @ 2025-09-29 9:02 UTC (permalink / raw)
To: Mathias Nyman, Greg Kroah-Hartman; +Cc: linux-usb, Łukasz Bartosik
From: Łukasz Bartosik <ukaszb@chromium.org>
Add code which allows to set manufacturer name of a DbC
device through sysfs.
Signed-off-by: Łukasz Bartosik <ukaszb@chromium.org>
---
drivers/usb/host/xhci-dbgcap.c | 31 +++++++++++++++++++++++++++++++
1 file changed, 31 insertions(+)
diff --git a/drivers/usb/host/xhci-dbgcap.c b/drivers/usb/host/xhci-dbgcap.c
index 31fa3c7c63e4..b52735c1474a 100644
--- a/drivers/usb/host/xhci-dbgcap.c
+++ b/drivers/usb/host/xhci-dbgcap.c
@@ -1200,6 +1200,35 @@ static ssize_t dbc_bcdDevice_store(struct device *dev,
return size;
}
+static ssize_t dbc_iManufacturer_show(struct device *dev,
+ struct device_attribute *attr,
+ char *buf)
+{
+ struct xhci_hcd *xhci = hcd_to_xhci(dev_get_drvdata(dev));
+ struct xhci_dbc *dbc = xhci->dbc;
+
+ return sysfs_emit(buf, "%s\n", dbc->str.manufacturer);
+}
+
+static ssize_t dbc_iManufacturer_store(struct device *dev,
+ struct device_attribute *attr,
+ const char *buf, size_t size)
+{
+ struct xhci_hcd *xhci = hcd_to_xhci(dev_get_drvdata(dev));
+ struct xhci_dbc *dbc = xhci->dbc;
+
+ if (dbc->state != DS_DISABLED)
+ return -EBUSY;
+
+ if (size > USB_MAX_STRING_LEN/2+1)
+ return -E2BIG;
+
+ memcpy(dbc->str.manufacturer, buf, size);
+ /* remove newline and terminate the string */
+ dbc->str.manufacturer[size-1] = '\0';
+
+ return size;
+}
static ssize_t dbc_iProduct_show(struct device *dev,
struct device_attribute *attr,
char *buf)
@@ -1347,6 +1376,7 @@ static DEVICE_ATTR_RW(dbc);
static DEVICE_ATTR_RW(dbc_idVendor);
static DEVICE_ATTR_RW(dbc_idProduct);
static DEVICE_ATTR_RW(dbc_bcdDevice);
+static DEVICE_ATTR_RW(dbc_iManufacturer);
static DEVICE_ATTR_RW(dbc_iProduct);
static DEVICE_ATTR_RW(dbc_iSerial);
static DEVICE_ATTR_RW(dbc_bInterfaceProtocol);
@@ -1357,6 +1387,7 @@ static struct attribute *dbc_dev_attrs[] = {
&dev_attr_dbc_idVendor.attr,
&dev_attr_dbc_idProduct.attr,
&dev_attr_dbc_bcdDevice.attr,
+ &dev_attr_dbc_iManufacturer.attr,
&dev_attr_dbc_iProduct.attr,
&dev_attr_dbc_iSerial.attr,
&dev_attr_dbc_bInterfaceProtocol.attr,
--
2.51.0.536.g15c5d4f767-goog
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH v1 2/4] xhci: dbc: allow to set serial number through sysfs
2025-09-29 9:02 ` [PATCH v1 2/4] xhci: dbc: allow to set serial number " Łukasz Bartosik
@ 2025-09-29 12:59 ` Greg Kroah-Hartman
2025-09-29 13:00 ` Greg Kroah-Hartman
1 sibling, 0 replies; 8+ messages in thread
From: Greg Kroah-Hartman @ 2025-09-29 12:59 UTC (permalink / raw)
To: Łukasz Bartosik; +Cc: Mathias Nyman, linux-usb
On Mon, Sep 29, 2025 at 09:02:04AM +0000, Łukasz Bartosik wrote:
> From: Łukasz Bartosik <ukaszb@chromium.org>
>
> Add code which allows to set serial number of a DbC
> device through sysfs.
But why? Who needs this and what tools will do anything with this
information?
And where is the Documentation/ABI/ entries for all of these new ones? :)
thanks,
greg k-h
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH v1 2/4] xhci: dbc: allow to set serial number through sysfs
2025-09-29 9:02 ` [PATCH v1 2/4] xhci: dbc: allow to set serial number " Łukasz Bartosik
2025-09-29 12:59 ` Greg Kroah-Hartman
@ 2025-09-29 13:00 ` Greg Kroah-Hartman
2025-10-01 8:28 ` Łukasz Bartosik
1 sibling, 1 reply; 8+ messages in thread
From: Greg Kroah-Hartman @ 2025-09-29 13:00 UTC (permalink / raw)
To: Łukasz Bartosik; +Cc: Mathias Nyman, linux-usb
On Mon, Sep 29, 2025 at 09:02:04AM +0000, Łukasz Bartosik wrote:
> From: Łukasz Bartosik <ukaszb@chromium.org>
>
> Add code which allows to set serial number of a DbC
> device through sysfs.
>
> Signed-off-by: Łukasz Bartosik <ukaszb@chromium.org>
> ---
> drivers/usb/host/xhci-dbgcap.c | 32 ++++++++++++++++++++++++++++++++
> 1 file changed, 32 insertions(+)
>
> diff --git a/drivers/usb/host/xhci-dbgcap.c b/drivers/usb/host/xhci-dbgcap.c
> index c2fecaffd6f3..5cc201afe8f4 100644
> --- a/drivers/usb/host/xhci-dbgcap.c
> +++ b/drivers/usb/host/xhci-dbgcap.c
> @@ -1200,6 +1200,36 @@ static ssize_t dbc_bcdDevice_store(struct device *dev,
> return size;
> }
>
> +static ssize_t dbc_iSerial_show(struct device *dev,
> + struct device_attribute *attr,
> + char *buf)
> +{
> + struct xhci_hcd *xhci = hcd_to_xhci(dev_get_drvdata(dev));
> + struct xhci_dbc *dbc = xhci->dbc;
> +
> + return sysfs_emit(buf, "%s\n", dbc->str.serial);
> +}
> +
> +static ssize_t dbc_iSerial_store(struct device *dev,
> + struct device_attribute *attr,
> + const char *buf, size_t size)
> +{
> + struct xhci_hcd *xhci = hcd_to_xhci(dev_get_drvdata(dev));
> + struct xhci_dbc *dbc = xhci->dbc;
> +
> + if (dbc->state != DS_DISABLED)
> + return -EBUSY;
> +
> + if (size > USB_MAX_STRING_LEN/2+1)
> + return -E2BIG;
> +
> + memcpy(dbc->str.serial, buf, size);
> + /* remove newline and terminate the string */
> + dbc->str.serial[size-1] = '\0';
What if there is not a newline?
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH v1 2/4] xhci: dbc: allow to set serial number through sysfs
2025-09-29 13:00 ` Greg Kroah-Hartman
@ 2025-10-01 8:28 ` Łukasz Bartosik
0 siblings, 0 replies; 8+ messages in thread
From: Łukasz Bartosik @ 2025-10-01 8:28 UTC (permalink / raw)
To: Greg Kroah-Hartman; +Cc: Mathias Nyman, linux-usb
> On Mon, Sep 29, 2025 at 09:02:04AM +0000, Łukasz Bartosik wrote:
> > From: Łukasz Bartosik <ukaszb@chromium.org>
> >
> > Add code which allows to set serial number of a DbC
> > device through sysfs.
>
> But why? Who needs this and what tools will do anything with this
> information?
>
By default DbC serial number is set to "0001". ADB client on host side needs
to be able to differentiate devices using DbC and it uses serial number for
that purpose. Based on that this is the reason why we want to be able to assign
devices with unique serial numbers.
> And where is the Documentation/ABI/ entries for all of these new ones? :)
>
I will update the documentation ;).
> > Signed-off-by: Łukasz Bartosik <ukaszb@chromium.org>
> > ---
> > drivers/usb/host/xhci-dbgcap.c | 32 ++++++++++++++++++++++++++++++++
> > 1 file changed, 32 insertions(+)
> >
> > diff --git a/drivers/usb/host/xhci-dbgcap.c b/drivers/usb/host/xhci-dbgcap.c
> > index c2fecaffd6f3..5cc201afe8f4 100644
> > --- a/drivers/usb/host/xhci-dbgcap.c
> > +++ b/drivers/usb/host/xhci-dbgcap.c
> > @@ -1200,6 +1200,36 @@ static ssize_t dbc_bcdDevice_store(struct device *dev,
> > return size;
> > }
> >
> > +static ssize_t dbc_iSerial_show(struct device *dev,
> > + struct device_attribute *attr,
> > + char *buf)
> > +{
> > + struct xhci_hcd *xhci = hcd_to_xhci(dev_get_drvdata(dev));
> > + struct xhci_dbc *dbc = xhci->dbc;
> > +
> > + return sysfs_emit(buf, "%s\n", dbc->str.serial);
> > +}
> > +
> > +static ssize_t dbc_iSerial_store(struct device *dev,
> > + struct device_attribute *attr,
> > + const char *buf, size_t size)
> > +{
> > + struct xhci_hcd *xhci = hcd_to_xhci(dev_get_drvdata(dev));
> > + struct xhci_dbc *dbc = xhci->dbc;
> > +
> > + if (dbc->state != DS_DISABLED)
> > + return -EBUSY;
> > +
> > + if (size > USB_MAX_STRING_LEN/2+1)
> > + return -E2BIG;
> > +
> > + memcpy(dbc->str.serial, buf, size);
> > + /* remove newline and terminate the string */
> > + dbc->str.serial[size-1] = '\0';
>
> What if there is not a newline?
Thanks for pointing it out. I will fix it.
Thanks,
Łukasz
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2025-10-01 8:29 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-09-29 9:02 [PATCH v1 0/4] Enable to set DbC strings through sysfs Łukasz Bartosik
2025-09-29 9:02 ` [PATCH v1 1/4] xhci: dbc: prepare to expose " Łukasz Bartosik
2025-09-29 9:02 ` [PATCH v1 2/4] xhci: dbc: allow to set serial number " Łukasz Bartosik
2025-09-29 12:59 ` Greg Kroah-Hartman
2025-09-29 13:00 ` Greg Kroah-Hartman
2025-10-01 8:28 ` Łukasz Bartosik
2025-09-29 9:02 ` [PATCH v1 3/4] xhci: dbc: allow to set product name " Łukasz Bartosik
2025-09-29 9:02 ` [PATCH v1 4/4] xhci: dbc: allow to set manufacturer " Łukasz Bartosik
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox