Linux-mmc Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH 0/4] mmc: sdio: Export CISTPL_VERS_1 attributes to userspace
@ 2020-07-27 13:38 Pali Rohár
  2020-07-27 13:38 ` [PATCH 1/4] mmc: sdio: Check for CISTPL_VERS_1 buffer size Pali Rohár
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Pali Rohár @ 2020-07-27 13:38 UTC (permalink / raw)
  To: Ulf Hansson; +Cc: linux-mmc, linux-kernel

CISTPL_VERS_1 structure contains useful information for identification
of SDIO cards. It contains revision number according to which standard
is SDIO card compliant. And also it contain human readable info strings
which should contain manufacturer name or product information, like for
old PCMCIA cards. SDIO simplified specification 3.00 just contain
reference to PCMCIA metaformat specification for definition of that
CISTPL_VERS_1 structure itself.

Human readable SDIO card strings can be useful for userspace to do card
identification. Until now kernel exported to userspace only vendor and
device numbers but these numbers do not help to identify new or unknown
cards.


I have tested these patches with Marwell 88W8997 SDIO card (WiFi+Bluetooth)
and here is content of attributes available in userspace:

$ grep . /sys/class/mmc_host/mmc0/mmc0:0001/* /sys/class/mmc_host/mmc0/mmc0:0001/*/*
/sys/class/mmc_host/mmc0/mmc0:0001/device:0x9140
/sys/class/mmc_host/mmc0/mmc0:0001/info1:Marvell
/sys/class/mmc_host/mmc0/mmc0:0001/info2:Wireless Device ID: 50
/sys/class/mmc_host/mmc0/mmc0:0001/ocr:0x00200000
/sys/class/mmc_host/mmc0/mmc0:0001/rca:0x0001
/sys/class/mmc_host/mmc0/mmc0:0001/revision:1.0
/sys/class/mmc_host/mmc0/mmc0:0001/type:SDIO
/sys/class/mmc_host/mmc0/mmc0:0001/uevent:MMC_TYPE=SDIO
/sys/class/mmc_host/mmc0/mmc0:0001/uevent:SDIO_ID=02DF:9140
/sys/class/mmc_host/mmc0/mmc0:0001/uevent:SDIO_REVISION=1.0
/sys/class/mmc_host/mmc0/mmc0:0001/uevent:SDIO_INFO1=Marvell
/sys/class/mmc_host/mmc0/mmc0:0001/uevent:SDIO_INFO2=Wireless Device ID: 50
/sys/class/mmc_host/mmc0/mmc0:0001/uevent:SDIO_INFO3=
/sys/class/mmc_host/mmc0/mmc0:0001/vendor:0x02df
/sys/class/mmc_host/mmc0/mmc0:0001/mmc0:0001:1/class:0x00
/sys/class/mmc_host/mmc0/mmc0:0001/mmc0:0001:1/device:0x9141
/sys/class/mmc_host/mmc0/mmc0:0001/mmc0:0001:1/info1:Marvell WiFi Device
/sys/class/mmc_host/mmc0/mmc0:0001/mmc0:0001:1/modalias:sdio:c00v02DFd9141
/sys/class/mmc_host/mmc0/mmc0:0001/mmc0:0001:1/revision:1.0
/sys/class/mmc_host/mmc0/mmc0:0001/mmc0:0001:1/uevent:DRIVER=mwifiex_sdio
/sys/class/mmc_host/mmc0/mmc0:0001/mmc0:0001:1/uevent:SDIO_CLASS=00
/sys/class/mmc_host/mmc0/mmc0:0001/mmc0:0001:1/uevent:SDIO_ID=02DF:9141
/sys/class/mmc_host/mmc0/mmc0:0001/mmc0:0001:1/uevent:SDIO_REVISION=1.0
/sys/class/mmc_host/mmc0/mmc0:0001/mmc0:0001:1/uevent:SDIO_INFO1=Marvell WiFi Device
/sys/class/mmc_host/mmc0/mmc0:0001/mmc0:0001:1/uevent:SDIO_INFO2=
/sys/class/mmc_host/mmc0/mmc0:0001/mmc0:0001:1/uevent:MODALIAS=sdio:c00v02DFd9141
/sys/class/mmc_host/mmc0/mmc0:0001/mmc0:0001:1/vendor:0x02df
/sys/class/mmc_host/mmc0/mmc0:0001/mmc0:0001:2/class:0x00
/sys/class/mmc_host/mmc0/mmc0:0001/mmc0:0001:2/device:0x9142
/sys/class/mmc_host/mmc0/mmc0:0001/mmc0:0001:2/info1:Marvell Bluetooth Device
/sys/class/mmc_host/mmc0/mmc0:0001/mmc0:0001:2/modalias:sdio:c00v02DFd9142
/sys/class/mmc_host/mmc0/mmc0:0001/mmc0:0001:2/revision:1.0
/sys/class/mmc_host/mmc0/mmc0:0001/mmc0:0001:2/uevent:DRIVER=btmrvl_sdio
/sys/class/mmc_host/mmc0/mmc0:0001/mmc0:0001:2/uevent:SDIO_CLASS=00
/sys/class/mmc_host/mmc0/mmc0:0001/mmc0:0001:2/uevent:SDIO_ID=02DF:9142
/sys/class/mmc_host/mmc0/mmc0:0001/mmc0:0001:2/uevent:SDIO_REVISION=1.0
/sys/class/mmc_host/mmc0/mmc0:0001/mmc0:0001:2/uevent:SDIO_INFO1=Marvell Bluetooth Device
/sys/class/mmc_host/mmc0/mmc0:0001/mmc0:0001:2/uevent:SDIO_INFO2=
/sys/class/mmc_host/mmc0/mmc0:0001/mmc0:0001:2/uevent:MODALIAS=sdio:c00v02DFd9142
/sys/class/mmc_host/mmc0/mmc0:0001/mmc0:0001:2/vendor:0x02df
/sys/class/mmc_host/mmc0/mmc0:0001/power/control:auto
/sys/class/mmc_host/mmc0/mmc0:0001/power/runtime_active_time:0
/sys/class/mmc_host/mmc0/mmc0:0001/power/runtime_status:unsupported
/sys/class/mmc_host/mmc0/mmc0:0001/power/runtime_suspended_time:0
/sys/class/mmc_host/mmc0/mmc0:0001/subsystem/drivers_autoprobe:1

As can be seen SDIO card does not provide all 4 info strings as required by
SDIO/PCMCIA specificaion and the third and the second strings are empty.


Pali Rohár (4):
  mmc: sdio: Check for CISTPL_VERS_1 buffer size
  mmc: sdio: Parse CISTPL_VERS_1 major and minor revision numbers
  mmc: sdio: Extend sdio_config_attr macro and use it also for modalias
  mmc: sdio: Export SDIO revision and info strings to userspace

 drivers/mmc/core/bus.c        | 12 ++++++++
 drivers/mmc/core/sd.c         | 36 +++++++++++++++++++++--
 drivers/mmc/core/sdio.c       | 24 ++++++++++++++++
 drivers/mmc/core/sdio_bus.c   | 54 ++++++++++++++++++++++++++---------
 drivers/mmc/core/sdio_cis.c   | 11 +++++++
 include/linux/mmc/card.h      |  2 ++
 include/linux/mmc/sdio_func.h |  2 ++
 7 files changed, 124 insertions(+), 17 deletions(-)

-- 
2.20.1


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 1/4] mmc: sdio: Check for CISTPL_VERS_1 buffer size
  2020-07-27 13:38 [PATCH 0/4] mmc: sdio: Export CISTPL_VERS_1 attributes to userspace Pali Rohár
@ 2020-07-27 13:38 ` Pali Rohár
  2020-07-27 13:38 ` [PATCH 2/4] mmc: sdio: Parse CISTPL_VERS_1 major and minor revision numbers Pali Rohár
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Pali Rohár @ 2020-07-27 13:38 UTC (permalink / raw)
  To: Ulf Hansson; +Cc: linux-mmc, linux-kernel

Before parsing CISTPL_VERS_1 structure check that its size is at least two
bytes to prevent buffer overflow.

Signed-off-by: Pali Rohár <pali@kernel.org>
---
 drivers/mmc/core/sdio_cis.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/mmc/core/sdio_cis.c b/drivers/mmc/core/sdio_cis.c
index e0655278c5c3..3efaa9534a77 100644
--- a/drivers/mmc/core/sdio_cis.c
+++ b/drivers/mmc/core/sdio_cis.c
@@ -24,10 +24,13 @@ static int cistpl_vers_1(struct mmc_card *card, struct sdio_func *func,
 			 const unsigned char *buf, unsigned size)
 {
 	unsigned i, nr_strings;
 	char **buffer, *string;
 
+	if (size < 2)
+		return 0;
+
 	/* Find all null-terminated (including zero length) strings in
 	   the TPLLV1_INFO field. Trailing garbage is ignored. */
 	buf += 2;
 	size -= 2;
 
-- 
2.20.1


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 2/4] mmc: sdio: Parse CISTPL_VERS_1 major and minor revision numbers
  2020-07-27 13:38 [PATCH 0/4] mmc: sdio: Export CISTPL_VERS_1 attributes to userspace Pali Rohár
  2020-07-27 13:38 ` [PATCH 1/4] mmc: sdio: Check for CISTPL_VERS_1 buffer size Pali Rohár
@ 2020-07-27 13:38 ` Pali Rohár
  2020-07-27 13:38 ` [PATCH 3/4] mmc: sdio: Extend sdio_config_attr macro and use it also for modalias Pali Rohár
  2020-07-27 13:38 ` [PATCH 4/4] mmc: sdio: Export SDIO revision and info strings to userspace Pali Rohár
  3 siblings, 0 replies; 5+ messages in thread
From: Pali Rohár @ 2020-07-27 13:38 UTC (permalink / raw)
  To: Ulf Hansson; +Cc: linux-mmc, linux-kernel

They should indicate compliance of standard.

Signed-off-by: Pali Rohár <pali@kernel.org>
---
 drivers/mmc/core/sdio_cis.c   | 8 ++++++++
 include/linux/mmc/card.h      | 2 ++
 include/linux/mmc/sdio_func.h | 2 ++
 3 files changed, 12 insertions(+)

diff --git a/drivers/mmc/core/sdio_cis.c b/drivers/mmc/core/sdio_cis.c
index 3efaa9534a77..44bea5e4aeda 100644
--- a/drivers/mmc/core/sdio_cis.c
+++ b/drivers/mmc/core/sdio_cis.c
@@ -23,12 +23,16 @@
 static int cistpl_vers_1(struct mmc_card *card, struct sdio_func *func,
 			 const unsigned char *buf, unsigned size)
 {
+	u8 major_rev, minor_rev;
 	unsigned i, nr_strings;
 	char **buffer, *string;
 
 	if (size < 2)
 		return 0;
 
+	major_rev = buf[0];
+	minor_rev = buf[1];
+
 	/* Find all null-terminated (including zero length) strings in
 	   the TPLLV1_INFO field. Trailing garbage is ignored. */
 	buf += 2;
@@ -60,9 +64,13 @@ static int cistpl_vers_1(struct mmc_card *card, struct sdio_func *func,
 	}
 
 	if (func) {
+		func->major_rev = major_rev;
+		func->minor_rev = minor_rev;
 		func->num_info = nr_strings;
 		func->info = (const char**)buffer;
 	} else {
+		card->major_rev = major_rev;
+		card->minor_rev = minor_rev;
 		card->num_info = nr_strings;
 		card->info = (const char**)buffer;
 	}
diff --git a/include/linux/mmc/card.h b/include/linux/mmc/card.h
index 7d46411ffaa2..42df06c6b19c 100644
--- a/include/linux/mmc/card.h
+++ b/include/linux/mmc/card.h
@@ -297,6 +297,8 @@ struct mmc_card {
 	struct sdio_cis		cis;		/* common tuple info */
 	struct sdio_func	*sdio_func[SDIO_MAX_FUNCS]; /* SDIO functions (devices) */
 	struct sdio_func	*sdio_single_irq; /* SDIO function when only one IRQ active */
+	u8			major_rev;	/* major revision number */
+	u8			minor_rev;	/* minor revision number */
 	unsigned		num_info;	/* number of info strings */
 	const char		**info;		/* info strings */
 	struct sdio_func_tuple	*tuples;	/* unknown common tuples */
diff --git a/include/linux/mmc/sdio_func.h b/include/linux/mmc/sdio_func.h
index fa2aaab5e57a..478855b8e406 100644
--- a/include/linux/mmc/sdio_func.h
+++ b/include/linux/mmc/sdio_func.h
@@ -51,6 +51,8 @@ struct sdio_func {
 
 	u8			*tmpbuf;	/* DMA:able scratch buffer */
 
+	u8			major_rev;	/* major revision number */
+	u8			minor_rev;	/* minor revision number */
 	unsigned		num_info;	/* number of info strings */
 	const char		**info;		/* info strings */
 
-- 
2.20.1


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 3/4] mmc: sdio: Extend sdio_config_attr macro and use it also for modalias
  2020-07-27 13:38 [PATCH 0/4] mmc: sdio: Export CISTPL_VERS_1 attributes to userspace Pali Rohár
  2020-07-27 13:38 ` [PATCH 1/4] mmc: sdio: Check for CISTPL_VERS_1 buffer size Pali Rohár
  2020-07-27 13:38 ` [PATCH 2/4] mmc: sdio: Parse CISTPL_VERS_1 major and minor revision numbers Pali Rohár
@ 2020-07-27 13:38 ` Pali Rohár
  2020-07-27 13:38 ` [PATCH 4/4] mmc: sdio: Export SDIO revision and info strings to userspace Pali Rohár
  3 siblings, 0 replies; 5+ messages in thread
From: Pali Rohár @ 2020-07-27 13:38 UTC (permalink / raw)
  To: Ulf Hansson; +Cc: linux-mmc, linux-kernel

This simplify code for generating sdio config attributes and allows easily
define new sdio attributes.

Signed-off-by: Pali Rohár <pali@kernel.org>
---
 drivers/mmc/core/sdio_bus.c | 20 ++++++--------------
 1 file changed, 6 insertions(+), 14 deletions(-)

diff --git a/drivers/mmc/core/sdio_bus.c b/drivers/mmc/core/sdio_bus.c
index 3cc928282af7..2384829c8fb2 100644
--- a/drivers/mmc/core/sdio_bus.c
+++ b/drivers/mmc/core/sdio_bus.c
@@ -28,29 +28,21 @@
 #define to_sdio_driver(d)	container_of(d, struct sdio_driver, drv)
 
 /* show configuration fields */
-#define sdio_config_attr(field, format_string)				\
+#define sdio_config_attr(field, format_string, args...)			\
 static ssize_t								\
 field##_show(struct device *dev, struct device_attribute *attr, char *buf)				\
 {									\
 	struct sdio_func *func;						\
 									\
 	func = dev_to_sdio_func (dev);					\
-	return sprintf (buf, format_string, func->field);		\
+	return sprintf(buf, format_string, args);			\
 }									\
 static DEVICE_ATTR_RO(field)
 
-sdio_config_attr(class, "0x%02x\n");
-sdio_config_attr(vendor, "0x%04x\n");
-sdio_config_attr(device, "0x%04x\n");
-
-static ssize_t modalias_show(struct device *dev, struct device_attribute *attr, char *buf)
-{
-	struct sdio_func *func = dev_to_sdio_func (dev);
-
-	return sprintf(buf, "sdio:c%02Xv%04Xd%04X\n",
-			func->class, func->vendor, func->device);
-}
-static DEVICE_ATTR_RO(modalias);
+sdio_config_attr(class, "0x%02x\n", func->class);
+sdio_config_attr(vendor, "0x%04x\n", func->vendor);
+sdio_config_attr(device, "0x%04x\n", func->device);
+sdio_config_attr(modalias, "sdio:c%02Xv%04Xd%04X\n", func->class, func->vendor, func->device);
 
 static struct attribute *sdio_dev_attrs[] = {
 	&dev_attr_class.attr,
-- 
2.20.1


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 4/4] mmc: sdio: Export SDIO revision and info strings to userspace
  2020-07-27 13:38 [PATCH 0/4] mmc: sdio: Export CISTPL_VERS_1 attributes to userspace Pali Rohár
                   ` (2 preceding siblings ...)
  2020-07-27 13:38 ` [PATCH 3/4] mmc: sdio: Extend sdio_config_attr macro and use it also for modalias Pali Rohár
@ 2020-07-27 13:38 ` Pali Rohár
  3 siblings, 0 replies; 5+ messages in thread
From: Pali Rohár @ 2020-07-27 13:38 UTC (permalink / raw)
  To: Ulf Hansson; +Cc: linux-mmc, linux-kernel

For SDIO functions, SDIO cards and SD COMBO cards are exported revision
number and info strings from CISTPL_VERS_1 structure. Revision number
should indicate compliance of standard and info strings should contain
product information in same format as product information for PCMCIA cards.

Product information for PCMCIA cards should contain following strings in
this order: Manufacturer, Product Name, Lot number, Programming Conditions.

Note that not all SDIO cards export all those info strings in that order as
described in PCMCIA Metaformat Specification.

Signed-off-by: Pali Rohár <pali@kernel.org>
---
 drivers/mmc/core/bus.c      | 12 ++++++++++++
 drivers/mmc/core/sd.c       | 36 +++++++++++++++++++++++++++++++++---
 drivers/mmc/core/sdio.c     | 24 ++++++++++++++++++++++++
 drivers/mmc/core/sdio_bus.c | 34 ++++++++++++++++++++++++++++++++++
 4 files changed, 103 insertions(+), 3 deletions(-)

diff --git a/drivers/mmc/core/bus.c b/drivers/mmc/core/bus.c
index 70207f11a654..c2e70b757dd1 100644
--- a/drivers/mmc/core/bus.c
+++ b/drivers/mmc/core/bus.c
@@ -68,6 +68,7 @@ mmc_bus_uevent(struct device *dev, struct kobj_uevent_env *env)
 {
 	struct mmc_card *card = mmc_dev_to_card(dev);
 	const char *type;
+	unsigned int i;
 	int retval = 0;
 
 	switch (card->type) {
@@ -98,6 +99,17 @@ mmc_bus_uevent(struct device *dev, struct kobj_uevent_env *env)
 					card->cis.vendor, card->cis.device);
 		if (retval)
 			return retval;
+
+		retval = add_uevent_var(env, "SDIO_REVISION=%u.%u",
+					card->major_rev, card->minor_rev);
+		if (retval)
+			return retval;
+
+		for (i = 0; i < card->num_info; i++) {
+			retval = add_uevent_var(env, "SDIO_INFO%u=%s", i+1, card->info[i]);
+			if (retval)
+				return retval;
+		}
 	}
 
 	/*
diff --git a/drivers/mmc/core/sd.c b/drivers/mmc/core/sd.c
index 5a2210c25aa7..429ca14fa7e1 100644
--- a/drivers/mmc/core/sd.c
+++ b/drivers/mmc/core/sd.c
@@ -709,10 +709,34 @@ static DEVICE_ATTR(dsr, S_IRUGO, mmc_dsr_show, NULL);
 
 MMC_DEV_ATTR(vendor, "0x%04x\n", card->cis.vendor);
 MMC_DEV_ATTR(device, "0x%04x\n", card->cis.device);
+MMC_DEV_ATTR(revision, "%u.%u\n", card->major_rev, card->minor_rev);
+
+#define sdio_info_attr(num)									\
+static ssize_t info##num##_show(struct device *dev, struct device_attribute *attr, char *buf)	\
+{												\
+	struct mmc_card *card = mmc_dev_to_card(dev);						\
+												\
+	if (num > card->num_info)								\
+		return -ENODATA;								\
+	if (!card->info[num-1][0])								\
+		return 0;									\
+	return sprintf(buf, "%s\n", card->info[num-1]);						\
+}												\
+static DEVICE_ATTR_RO(info##num)
+
+sdio_info_attr(1);
+sdio_info_attr(2);
+sdio_info_attr(3);
+sdio_info_attr(4);
 
 static struct attribute *sd_std_attrs[] = {
 	&dev_attr_vendor.attr,
 	&dev_attr_device.attr,
+	&dev_attr_revision.attr,
+	&dev_attr_info1.attr,
+	&dev_attr_info2.attr,
+	&dev_attr_info3.attr,
+	&dev_attr_info4.attr,
 	&dev_attr_cid.attr,
 	&dev_attr_csd.attr,
 	&dev_attr_scr.attr,
@@ -738,9 +762,15 @@ static umode_t sd_std_is_visible(struct kobject *kobj, struct attribute *attr,
 	struct device *dev = container_of(kobj, struct device, kobj);
 	struct mmc_card *card = mmc_dev_to_card(dev);
 
-	/* CIS vendor and device ids are available only for Combo cards */
-	if ((attr == &dev_attr_vendor.attr || attr == &dev_attr_device.attr) &&
-	    card->type != MMC_TYPE_SD_COMBO)
+	/* CIS vendor and device ids, revision and info string are available only for Combo cards */
+	if ((attr == &dev_attr_vendor.attr ||
+	     attr == &dev_attr_device.attr ||
+	     attr == &dev_attr_revision.attr ||
+	     attr == &dev_attr_info1.attr ||
+	     attr == &dev_attr_info2.attr ||
+	     attr == &dev_attr_info3.attr ||
+	     attr == &dev_attr_info4.attr
+	    ) && card->type != MMC_TYPE_SD_COMBO)
 		return 0;
 
 	return attr->mode;
diff --git a/drivers/mmc/core/sdio.c b/drivers/mmc/core/sdio.c
index 61ae909730f3..c4a4e67ef0a6 100644
--- a/drivers/mmc/core/sdio.c
+++ b/drivers/mmc/core/sdio.c
@@ -29,12 +29,36 @@
 
 MMC_DEV_ATTR(vendor, "0x%04x\n", card->cis.vendor);
 MMC_DEV_ATTR(device, "0x%04x\n", card->cis.device);
+MMC_DEV_ATTR(revision, "%u.%u\n", card->major_rev, card->minor_rev);
 MMC_DEV_ATTR(ocr, "0x%08x\n", card->ocr);
 MMC_DEV_ATTR(rca, "0x%04x\n", card->rca);
 
+#define sdio_info_attr(num)									\
+static ssize_t info##num##_show(struct device *dev, struct device_attribute *attr, char *buf)	\
+{												\
+	struct mmc_card *card = mmc_dev_to_card(dev);						\
+												\
+	if (num > card->num_info)								\
+		return -ENODATA;								\
+	if (!card->info[num-1][0])								\
+		return 0;									\
+	return sprintf(buf, "%s\n", card->info[num-1]);						\
+}												\
+static DEVICE_ATTR_RO(info##num)
+
+sdio_info_attr(1);
+sdio_info_attr(2);
+sdio_info_attr(3);
+sdio_info_attr(4);
+
 static struct attribute *sdio_std_attrs[] = {
 	&dev_attr_vendor.attr,
 	&dev_attr_device.attr,
+	&dev_attr_revision.attr,
+	&dev_attr_info1.attr,
+	&dev_attr_info2.attr,
+	&dev_attr_info3.attr,
+	&dev_attr_info4.attr,
 	&dev_attr_ocr.attr,
 	&dev_attr_rca.attr,
 	NULL,
diff --git a/drivers/mmc/core/sdio_bus.c b/drivers/mmc/core/sdio_bus.c
index 2384829c8fb2..3d709029e07c 100644
--- a/drivers/mmc/core/sdio_bus.c
+++ b/drivers/mmc/core/sdio_bus.c
@@ -42,12 +42,36 @@ static DEVICE_ATTR_RO(field)
 sdio_config_attr(class, "0x%02x\n", func->class);
 sdio_config_attr(vendor, "0x%04x\n", func->vendor);
 sdio_config_attr(device, "0x%04x\n", func->device);
+sdio_config_attr(revision, "%u.%u\n", func->major_rev, func->minor_rev);
 sdio_config_attr(modalias, "sdio:c%02Xv%04Xd%04X\n", func->class, func->vendor, func->device);
 
+#define sdio_info_attr(num)									\
+static ssize_t info##num##_show(struct device *dev, struct device_attribute *attr, char *buf)	\
+{												\
+	struct sdio_func *func = dev_to_sdio_func(dev);						\
+												\
+	if (num > func->num_info)								\
+		return -ENODATA;								\
+	if (!func->info[num-1][0])								\
+		return 0;									\
+	return sprintf(buf, "%s\n", func->info[num-1]);						\
+}												\
+static DEVICE_ATTR_RO(info##num)
+
+sdio_info_attr(1);
+sdio_info_attr(2);
+sdio_info_attr(3);
+sdio_info_attr(4);
+
 static struct attribute *sdio_dev_attrs[] = {
 	&dev_attr_class.attr,
 	&dev_attr_vendor.attr,
 	&dev_attr_device.attr,
+	&dev_attr_revision.attr,
+	&dev_attr_info1.attr,
+	&dev_attr_info2.attr,
+	&dev_attr_info3.attr,
+	&dev_attr_info4.attr,
 	&dev_attr_modalias.attr,
 	NULL,
 };
@@ -98,6 +122,7 @@ static int
 sdio_bus_uevent(struct device *dev, struct kobj_uevent_env *env)
 {
 	struct sdio_func *func = dev_to_sdio_func(dev);
+	unsigned int i;
 
 	if (add_uevent_var(env,
 			"SDIO_CLASS=%02X", func->class))
@@ -107,6 +132,15 @@ sdio_bus_uevent(struct device *dev, struct kobj_uevent_env *env)
 			"SDIO_ID=%04X:%04X", func->vendor, func->device))
 		return -ENOMEM;
 
+	if (add_uevent_var(env,
+			"SDIO_REVISION=%u.%u", func->major_rev, func->minor_rev))
+		return -ENOMEM;
+
+	for (i = 0; i < func->num_info; i++) {
+		if (add_uevent_var(env, "SDIO_INFO%u=%s", i+1, func->info[i]))
+			return -ENOMEM;
+	}
+
 	if (add_uevent_var(env,
 			"MODALIAS=sdio:c%02Xv%04Xd%04X",
 			func->class, func->vendor, func->device))
-- 
2.20.1


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, back to index

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-27 13:38 [PATCH 0/4] mmc: sdio: Export CISTPL_VERS_1 attributes to userspace Pali Rohár
2020-07-27 13:38 ` [PATCH 1/4] mmc: sdio: Check for CISTPL_VERS_1 buffer size Pali Rohár
2020-07-27 13:38 ` [PATCH 2/4] mmc: sdio: Parse CISTPL_VERS_1 major and minor revision numbers Pali Rohár
2020-07-27 13:38 ` [PATCH 3/4] mmc: sdio: Extend sdio_config_attr macro and use it also for modalias Pali Rohár
2020-07-27 13:38 ` [PATCH 4/4] mmc: sdio: Export SDIO revision and info strings to userspace Pali Rohár

Linux-mmc Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-mmc/0 linux-mmc/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-mmc linux-mmc/ https://lore.kernel.org/linux-mmc \
		linux-mmc@vger.kernel.org
	public-inbox-index linux-mmc

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-mmc


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git