mmc: core: Do not export MMC_NAME= and MODALIAS=mmc:block for SDIO cards
PATCH 1/2 mmc: core: Do not export MMC_NAME= and MODALIAS=mmc:block for SDIO cards
SDIO non-combo cards are not handled by mmc_block driver and do not have accessible CID register which is used for MMC_NAME= construction.
--- drivers/mmc/core/bus.c | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-)
drivers/mmc/core/bus.c +14 -9
@@ -93,15 +93,20 @@ mmc_bus_uevent(struct device *dev, struct kobj_uevent_env *env)return retval; } - retval =add_uevent_var (env,"MMC_NAME=%s" ,mmc_card_name (card)); -if (retval) -return retval; - -/* -* Request the mmc_block device. Note: that this is a direct request -* for the module it carries no information as to what is inserted. -*/ - retval =add_uevent_var (env,"MODALIAS=mmc:block" ); +if (card->type !=MMC_TYPE_SDIO ) { + retval =add_uevent_var (env,"MMC_NAME=%s" ,mmc_card_name (card)); +if (retval) +return retval; + +/* +* Request the mmc_block device. +* Note: that this is a direct request for the module it carries +* no information as to what is inserted. +*/ + retval =add_uevent_var (env,"MODALIAS=mmc:block" ); +if (retval) +return retval; + }return retval; }
Signature · 1 line
2.20.1
PATCH 2/2 mmc: core: Export device/vendor ids from Common CIS for SDIO cards
Device/vendor ids from Common CIS (Card Information Structure) may be different as device/vendor ids from CIS on particular SDIO function.
Export these "main" device/vendor ids for SDIO and SD combo cards at top level mmc device in sysfs so userspace can do better identification of connected SDIO and SD combo cards.
--- drivers/mmc/core/bus.c | 7 +++++++ drivers/mmc/core/sd.c | 26 +++++++++++++++++++++++++- drivers/mmc/core/sdio.c | 20 +++++++++++++++++++- 3 files changed, 51 insertions(+), 2 deletions(-)
drivers/mmc/core/bus.c +7 -0
@@ -93,6 +93,13 @@ mmc_bus_uevent(struct device *dev, struct kobj_uevent_env *env)return retval; } +if (card->type ==MMC_TYPE_SDIO || card->type ==MMC_TYPE_SD_COMBO ) { + retval =add_uevent_var (env,"SDIO_ID=%04X:%04X" , + card->cis.vendor, card->cis.device); +if (retval) +return retval; + } +if (card->type !=MMC_TYPE_SDIO ) { retval =add_uevent_var (env,"MMC_NAME=%s" ,mmc_card_name (card));if (retval)
drivers/mmc/core/sd.c +25 -1
@@ -707,7 +707,12 @@ static ssize_t mmc_dsr_show(struct device *dev, 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); +static struct attribute *sd_std_attrs[] = { + &dev_attr_vendor.attr, + &dev_attr_device.attr, &dev_attr_cid.attr, &dev_attr_csd.attr, &dev_attr_scr.attr,
@@ -726,7 +731,26 @@ static struct attribute *sd_std_attrs[] = { &dev_attr_dsr.attr, NULL, }; -ATTRIBUTE_GROUPS (sd_std); + +static umode_t sd_std_is_visible (struct kobject *kobj,struct attribute *attr, +int index) +{ + 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 ) +return 0 ; + +return attr->mode; +} + +static const struct attribute_group sd_std_group = { + .attrs = sd_std_attrs, + .is_visible = sd_std_is_visible, +}; +__ATTRIBUTE_GROUPS (sd_std);struct device_type sd_type = { .groups = sd_std_groups,
drivers/mmc/core/sdio.c +19 -1
@@ -27,6 +27,24 @@#include "sdio_ops.h" #include "sdio_cis.h" +MMC_DEV_ATTR (vendor,"0x%04x\n" , card->cis.vendor); +MMC_DEV_ATTR (device,"0x%04x\n" , card->cis.device); +MMC_DEV_ATTR (ocr,"0x%08x\n" , card->ocr); +MMC_DEV_ATTR (rca,"0x%04x\n" , card->rca); + +static struct attribute *sdio_std_attrs[] = { + &dev_attr_vendor.attr, + &dev_attr_device.attr, + &dev_attr_ocr.attr, + &dev_attr_rca.attr, +NULL , +}; +ATTRIBUTE_GROUPS (sdio_std); + +struct device_type sdio_type = { + .groups = sdio_std_groups, +}; +static int sdio_read_fbr (struct sdio_func *func) {int ret;
@@ -598,7 +616,7 @@ static int mmc_sdio_init_card(struct mmc_host *host, u32 ocr,/* * Allocate card structure. */ - card =mmc_alloc_card (host,NULL ); + card =mmc_alloc_card (host, &sdio_type);if (IS_ERR (card)) { err =PTR_ERR (card); goto err;
Signature · 1 line
2.20.1
Quoted 45 lines · Pali Rohár
SDIO non-combo cards are not handled by
mmc_blockdriver and do not have accessible CID register which is used for MMC_NAME= construction.Signed-off-by Pali Rohár <[email protected]>Reviewed-by Marek Behún <[email protected]>--- drivers/mmc/core/bus.c | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-)drivers/mmc/core/bus.c +14
-10@@ -93,15 +93,20 @@ mmc_bus_uevent(struct device *dev, struct kobj_uevent_env *env)return retval; } - retval =add_uevent_var (env,"MMC_NAME=%s" ,mmc_card_name (card)); -if (retval) -return retval; - -/* -* Request the mmc_block device. Note: that this is a direct request -* for the module it carries no information as to what is inserted. -*/ - retval =add_uevent_var (env,"MODALIAS=mmc:block" ); +if (card->type !=MMC_TYPE_SDIO ) { + retval =add_uevent_var (env,"MMC_NAME=%s" ,mmc_card_name (card)); +if (retval) +return retval; + +/* +* Request the mmc_block device. +* Note: that this is a direct request for the module it carries +* no information as to what is inserted. +*/ + retval =add_uevent_var (env,"MODALIAS=mmc:block" ); +if (retval) +return retval; + }return retval; } --
Quoted 2 lines
2.20.1
Overall this change makes sense to me, but at nitpick...
Rather than adding new nestled if-sentences, I suggest converting the function into using the "early returns" pattern instead.
For example, already in the switch loop, above the code you change, we could just return 0 instead of setting type = NULL. Likewise, you can check "if (card->type == MMC_TYPE_SDIO) return 0;"
Kind regards
Uffe
Re: [PATCH 2/2] mmc: core: Export device/vendor ids from Common CIS for SDIO cards
In reply to Pali RohárQuoted 7 lines · Pali Rohár
Device/vendor ids from Common CIS (Card Information Structure) may be different as device/vendor ids from CIS on particular SDIO function.
Export these "main" device/vendor ids for SDIO and SD combo cards at top level mmc device in sysfs so userspace can do better identification of connected SDIO and SD combo cards.
What would userspace do with this information, more exactly?
Isn't it just sufficient to give events per SDIO func, as we already do in sdio_bus_uevent()?
Kind regards
Uffe
Quoted 113 lines
Signed-off-by Pali Rohár <[email protected]>Reviewed-by Marek Behún <[email protected]>--- drivers/mmc/core/bus.c | 7 +++++++ drivers/mmc/core/sd.c | 26 +++++++++++++++++++++++++- drivers/mmc/core/sdio.c | 20 +++++++++++++++++++- 3 files changed, 51 insertions(+), 2 deletions(-)drivers/mmc/core/bus.c +7
-0@@ -93,6 +93,13 @@ mmc_bus_uevent(struct device *dev, struct kobj_uevent_env *env)return retval; } +if (card->type ==MMC_TYPE_SDIO || card->type ==MMC_TYPE_SD_COMBO ) { + retval =add_uevent_var (env,"SDIO_ID=%04X:%04X" , + card->cis.vendor, card->cis.device); +if (retval) +return retval; + } +if (card->type !=MMC_TYPE_SDIO ) { retval =add_uevent_var (env,"MMC_NAME=%s" ,mmc_card_name (card));if (retval)drivers/mmc/core/sd.c +25
-1@@ -707,7 +707,12 @@ static ssize_t mmc_dsr_show(struct device *dev, 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); +static struct attribute *sd_std_attrs[] = { + &dev_attr_vendor.attr, + &dev_attr_device.attr, &dev_attr_cid.attr, &dev_attr_csd.attr, &dev_attr_scr.attr,@@ -726,7 +731,26 @@ static struct attribute *sd_std_attrs[] = { &dev_attr_dsr.attr, NULL, }; -ATTRIBUTE_GROUPS (sd_std); + +static umode_t sd_std_is_visible (struct kobject *kobj,struct attribute *attr, +int index) +{ + 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 ) +return 0 ; + +return attr->mode; +} + +static const struct attribute_group sd_std_group = { + .attrs = sd_std_attrs, + .is_visible = sd_std_is_visible, +}; +__ATTRIBUTE_GROUPS (sd_std);struct device_type sd_type = { .groups = sd_std_groups,drivers/mmc/core/sdio.c +19
-2@@ -27,6 +27,24 @@#include "sdio_ops.h" #include "sdio_cis.h" +MMC_DEV_ATTR (vendor,"0x%04x\n" , card->cis.vendor); +MMC_DEV_ATTR (device,"0x%04x\n" , card->cis.device); +MMC_DEV_ATTR (ocr,"0x%08x\n" , card->ocr); +MMC_DEV_ATTR (rca,"0x%04x\n" , card->rca); + +static struct attribute *sdio_std_attrs[] = { + &dev_attr_vendor.attr, + &dev_attr_device.attr, + &dev_attr_ocr.attr, + &dev_attr_rca.attr, +NULL , +}; +ATTRIBUTE_GROUPS (sdio_std); + +struct device_type sdio_type = { + .groups = sdio_std_groups, +}; +static int sdio_read_fbr (struct sdio_func *func) {int ret;@@ -598,7 +616,7 @@ static int mmc_sdio_init_card(struct mmc_host *host, u32 ocr,/* * Allocate card structure. */ - card =mmc_alloc_card (host,NULL ); + card =mmc_alloc_card (host, &sdio_type);if (IS_ERR (card)) { err =PTR_ERR (card); goto err; --2.20.1
Re: [PATCH 2/2] mmc: core: Export device/vendor ids from Common CIS for SDIO cards
Quoted 10 lines · On Wednesday 27 May 2020 09:39:50 Ulf Hansson wrote:
Quoted 7 lines · Pali Rohár
Device/vendor ids from Common CIS (Card Information Structure) may be different as device/vendor ids from CIS on particular SDIO function.
Export these "main" device/vendor ids for SDIO and SD combo cards at top level mmc device in sysfs so userspace can do better identification of connected SDIO and SD combo cards.
What would userspace do with this information, more exactly?
Userspace can e.g. write udev rules based on Common CIS vendor/device id. Or can exactly identify SDIO card by CIS vendor/device id. Also it can be suitable for "lssdio" tool to print all information about SDIO card.
Currently I do not know any way how userspace can retrieve these ids for particular SDIO card. And correct identification is important.
Other important thing is that kernel on some places (e.g. mmc quirks) uses Common CIS vendor/device id and on other places (e.g. binding drivers) it uses SDIO function device/vendor ids.
So for debugging and developing kernel drivers it is needed to know correct Common CIS vendor/device id and SDIO functions vendor/device ids.
Quoted 2 lines
Isn't it just sufficient to give events per SDIO func, as we already do in
sdio_bus_uevent()?
No because some SDIO cards have different Common CIS vendor/device id and different vendor/device ids for particular SDIO functions.
Common CIS vendor/device id is the "main" identification of SDIO card, functions vendor/device ids just identify one of those functions.
For example look at my patch "mmc: sdio: Fix macro name for Marvell device with ID 0x9134" [1]. Without knowing correct CIS vendor/device id I was not able to fully understand problem and mess with names and ids. Because mmc quirks list uses CIS vendor/device ids (I guess for obvious reason as SDIO functions are not enumerated yet).
[1] - https://lore.kernel.org/linux-mmc/[email protected]/
Quoted 116 lines
Kind regards
UffeQuoted 113 lines
Signed-off-by Pali Rohár <[email protected]>Reviewed-by Marek Behún <[email protected]>--- drivers/mmc/core/bus.c | 7 +++++++ drivers/mmc/core/sd.c | 26 +++++++++++++++++++++++++- drivers/mmc/core/sdio.c | 20 +++++++++++++++++++- 3 files changed, 51 insertions(+), 2 deletions(-)drivers/mmc/core/bus.c +7
-0@@ -93,6 +93,13 @@ mmc_bus_uevent(struct device *dev, struct kobj_uevent_env *env)return retval; } +if (card->type ==MMC_TYPE_SDIO || card->type ==MMC_TYPE_SD_COMBO ) { + retval =add_uevent_var (env,"SDIO_ID=%04X:%04X" , + card->cis.vendor, card->cis.device); +if (retval) +return retval; + } +if (card->type !=MMC_TYPE_SDIO ) { retval =add_uevent_var (env,"MMC_NAME=%s" ,mmc_card_name (card));if (retval)drivers/mmc/core/sd.c +25
-1@@ -707,7 +707,12 @@ static ssize_t mmc_dsr_show(struct device *dev, 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); +static struct attribute *sd_std_attrs[] = { + &dev_attr_vendor.attr, + &dev_attr_device.attr, &dev_attr_cid.attr, &dev_attr_csd.attr, &dev_attr_scr.attr,@@ -726,7 +731,26 @@ static struct attribute *sd_std_attrs[] = { &dev_attr_dsr.attr, NULL, }; -ATTRIBUTE_GROUPS (sd_std); + +static umode_t sd_std_is_visible (struct kobject *kobj,struct attribute *attr, +int index) +{ + 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 ) +return 0 ; + +return attr->mode; +} + +static const struct attribute_group sd_std_group = { + .attrs = sd_std_attrs, + .is_visible = sd_std_is_visible, +}; +__ATTRIBUTE_GROUPS (sd_std);struct device_type sd_type = { .groups = sd_std_groups,drivers/mmc/core/sdio.c +19
-2@@ -27,6 +27,24 @@#include "sdio_ops.h" #include "sdio_cis.h" +MMC_DEV_ATTR (vendor,"0x%04x\n" , card->cis.vendor); +MMC_DEV_ATTR (device,"0x%04x\n" , card->cis.device); +MMC_DEV_ATTR (ocr,"0x%08x\n" , card->ocr); +MMC_DEV_ATTR (rca,"0x%04x\n" , card->rca); + +static struct attribute *sdio_std_attrs[] = { + &dev_attr_vendor.attr, + &dev_attr_device.attr, + &dev_attr_ocr.attr, + &dev_attr_rca.attr, +NULL , +}; +ATTRIBUTE_GROUPS (sdio_std); + +struct device_type sdio_type = { + .groups = sdio_std_groups, +}; +static int sdio_read_fbr (struct sdio_func *func) {int ret;@@ -598,7 +616,7 @@ static int mmc_sdio_init_card(struct mmc_host *host, u32 ocr,/* * Allocate card structure. */ - card =mmc_alloc_card (host,NULL ); + card =mmc_alloc_card (host, &sdio_type);if (IS_ERR (card)) { err =PTR_ERR (card); goto err; --2.20.1
Re: [PATCH 2/2] mmc: core: Export device/vendor ids from Common CIS for SDIO cards
Quoted 35 lines · Pali Rohár
Quoted 10 lines · On Wednesday 27 May 2020 09:39:50 Ulf Hansson wrote:
Quoted 7 lines · Pali Rohár
Device/vendor ids from Common CIS (Card Information Structure) may be different as device/vendor ids from CIS on particular SDIO function.
Export these "main" device/vendor ids for SDIO and SD combo cards at top level mmc device in sysfs so userspace can do better identification of connected SDIO and SD combo cards.
What would userspace do with this information, more exactly?
Userspace can e.g. write udev rules based on Common CIS vendor/device id. Or can exactly identify SDIO card by CIS vendor/device id. Also it can be suitable for "lssdio" tool to print all information about SDIO card.
Currently I do not know any way how userspace can retrieve these ids for particular SDIO card. And correct identification is important.
Other important thing is that kernel on some places (e.g. mmc quirks) uses Common CIS vendor/device id and on other places (e.g. binding drivers) it uses SDIO function device/vendor ids.
So for debugging and developing kernel drivers it is needed to know correct Common CIS vendor/device id and SDIO functions vendor/device ids.
Quoted 2 lines
Isn't it just sufficient to give events per SDIO func, as we already do in
sdio_bus_uevent()?No because some SDIO cards have different Common CIS vendor/device id and different vendor/device ids for particular SDIO functions.
Quoted 8 lines
Common CIS vendor/device id is the "main" identification of SDIO card, functions vendor/device ids just identify one of those functions.
For example look at my patch "mmc: sdio: Fix macro name for Marvell device with ID
0x9134" [1]. Without knowing correct CIS vendor/device id I was not able to fully understand problem and mess with names and ids. Because mmc quirks list uses CIS vendor/device ids (I guess for obvious reason as SDIO functions are not enumerated yet).
Good points, much appreciated to understand the use cases better!
May I suggest that you put some of this information into the commit message?
Quoted 3 lines
[...]
Kind regards
Uffe
kbuild test robot
build botRe: [PATCH 2/2] mmc: core: Export device/vendor ids from Common CIS for SDIO cards
In reply to Pali RohárI love your patch! Perhaps something to improve:
Hi "Pali,
I love your patch! Perhaps something to improve:
[auto build test WARNING on linus/master]
[also build test WARNING on ulf.hansson-mmc/next linux/master v5.7-rc7] [cannot apply to next-20200526]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system. BTW, we also suggest to use '--base' option to specify the base tree in git format-patch, please see https://stackoverflow.com/a/37406982]
url: https://github.com/0day-ci/linux/commits/Pali-Roh-r/mmc-core-Do-not-export-MMC_NAME-and-MODALIAS-mmc-block-for-SDIO-cards/20200526-235837 base: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git 9cb1fd0efd195590b828b9b865421ad345a4a145 config: i386-randconfig-s001-20200527 (attached as .config) compiler: gcc-9 (Debian 9.3.0-13) 9.3.0 reproduce: # apt-get install sparse # sparse version: v0.6.1-240-gf0fe1cd9-dirty # save the attached .config to linux build tree make W=1 C=1 ARCH=i386 CF='-fdiagnostic-prefix -D__CHECK_ENDIAN__'
If you fix the issue, kindly add following tag as appropriate
sparse warnings: (new ones prefixed by >>)
>> drivers/mmc/core/sdio.c:44:20: sparse: sparse: symbol 'sdio_type' was not declared. Should it be static?
Please review and possibly fold the followup patch.
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org
kbuild test robot
build bot[RFC PATCH] mmc: core: sdio_type can be static
In reply to Pali RohárSigned-off-by: kbuild test robot <[email protected]>
--- sdio.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/mmc/core/sdio.c +1 -1
@@ -41,7 +41,7 @@ static struct attribute *sdio_std_attrs[] = { };ATTRIBUTE_GROUPS (sdio_std); -struct device_type sdio_type = { +static struct device_type sdio_type = { .groups = sdio_std_groups, };
PATCH v2 1/2 mmc: core: Do not export MMC_NAME= and MODALIAS=mmc:block for SDIO cards
SDIO non-combo cards are not handled by mmc_block driver and do not have accessible CID register which is used for MMC_NAME= construction.
---
Changes in V2:
* Use early returns pattern
--- drivers/mmc/core/bus.c | 7 +++++++ 1 file changed, 7 insertions(+)
drivers/mmc/core/bus.c +7 -0
@@ -93,6 +93,13 @@ mmc_bus_uevent(struct device *dev, struct kobj_uevent_env *env)return retval; } +/* +* SDIO (non-combo) cards are not handled by mmc_block driver and do not +* have accessible CID register which used by mmc_card_name() function. +*/ +if (card->type ==MMC_TYPE_SDIO ) +return 0 ; + retval =add_uevent_var (env,"MMC_NAME=%s" ,mmc_card_name (card));if (retval)return retval;
Signature · 1 line
2.20.1
PATCH v2 2/2 mmc: core: Export device/vendor ids from Common CIS for SDIO cards
Device/vendor ids from Common CIS (Card Information Structure) may be different as device/vendor ids from CIS on particular SDIO function.
Kernel currently exports only device/vendor ids from SDIO functions and not "main" device/vendor ids from Common CIS.
This patch exports "main" device/vendor ids for SDIO and SD combo cards at top level mmc device in sysfs hierarchy.
Userspace can use e.g. udev rules to correctly match whole SDIO card based on Common CIS device/vendor id and not only one particular SDIO function. Having this information in userspace also helps developers to debug whole SDIO card as e.g. kernel mmc quirks use device/vendor ids from Common CIS and not from particular SDIO function. Also it allows to write userspace applications which list all connected SDIO cards based on CIS ids.
---
Changes in V2:
* Make sd_std_group static
* Put more information into commit message
--- drivers/mmc/core/bus.c | 7 +++++++ drivers/mmc/core/sd.c | 26 +++++++++++++++++++++++++- drivers/mmc/core/sdio.c | 20 +++++++++++++++++++- 3 files changed, 51 insertions(+), 2 deletions(-)
drivers/mmc/core/bus.c +7 -0
@@ -93,6 +93,13 @@ mmc_bus_uevent(struct device *dev, struct kobj_uevent_env *env)return retval; } +if (card->type ==MMC_TYPE_SDIO || card->type ==MMC_TYPE_SD_COMBO ) { + retval =add_uevent_var (env,"SDIO_ID=%04X:%04X" , + card->cis.vendor, card->cis.device); +if (retval) +return retval; + } +/* * SDIO (non-combo) cards are not handled by mmc_block driver and do not * have accessible CID register which used by mmc_card_name() function.
drivers/mmc/core/sd.c +25 -1
@@ -707,7 +707,12 @@ static ssize_t mmc_dsr_show(struct device *dev, 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); +static struct attribute *sd_std_attrs[] = { + &dev_attr_vendor.attr, + &dev_attr_device.attr, &dev_attr_cid.attr, &dev_attr_csd.attr, &dev_attr_scr.attr,
@@ -726,7 +731,26 @@ static struct attribute *sd_std_attrs[] = { &dev_attr_dsr.attr, NULL, }; -ATTRIBUTE_GROUPS (sd_std); + +static umode_t sd_std_is_visible (struct kobject *kobj,struct attribute *attr, +int index) +{ + 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 ) +return 0 ; + +return attr->mode; +} + +static const struct attribute_group sd_std_group = { + .attrs = sd_std_attrs, + .is_visible = sd_std_is_visible, +}; +__ATTRIBUTE_GROUPS (sd_std);struct device_type sd_type = { .groups = sd_std_groups,
drivers/mmc/core/sdio.c +19 -1
@@ -27,6 +27,24 @@#include "sdio_ops.h" #include "sdio_cis.h" +MMC_DEV_ATTR (vendor,"0x%04x\n" , card->cis.vendor); +MMC_DEV_ATTR (device,"0x%04x\n" , card->cis.device); +MMC_DEV_ATTR (ocr,"0x%08x\n" , card->ocr); +MMC_DEV_ATTR (rca,"0x%04x\n" , card->rca); + +static struct attribute *sdio_std_attrs[] = { + &dev_attr_vendor.attr, + &dev_attr_device.attr, + &dev_attr_ocr.attr, + &dev_attr_rca.attr, +NULL , +}; +ATTRIBUTE_GROUPS (sdio_std); + +static struct device_type sdio_type = { + .groups = sdio_std_groups, +}; +static int sdio_read_fbr (struct sdio_func *func) {int ret;
@@ -598,7 +616,7 @@ static int mmc_sdio_init_card(struct mmc_host *host, u32 ocr,/* * Allocate card structure. */ - card =mmc_alloc_card (host,NULL ); + card =mmc_alloc_card (host, &sdio_type);if (IS_ERR (card)) { err =PTR_ERR (card); goto err;
Signature · 1 line
2.20.1
Quoted 6 lines · Pali Rohár
SDIO non-combo cards are not handled by
mmc_blockdriver and do not have accessible CID register which is used for MMC_NAME= construction.Signed-off-by Pali Rohár <[email protected]>Reviewed-by Marek Behún <[email protected]>
Applied for next, thanks!
Kind regards
Uffe
Quoted 29 lines
---
Changes in V2:
* Use early returns pattern--- drivers/mmc/core/bus.c | 7 +++++++ 1 file changed, 7 insertions(+)drivers/mmc/core/bus.c +7
-1@@ -93,6 +93,13 @@ mmc_bus_uevent(struct device *dev, struct kobj_uevent_env *env)return retval; } +/* +* SDIO (non-combo) cards are not handled by mmc_block driver and do not +* have accessible CID register which used by mmc_card_name() function. +*/ +if (card->type ==MMC_TYPE_SDIO ) +return 0 ; + retval =add_uevent_var (env,"MMC_NAME=%s" ,mmc_card_name (card));if (retval)return retval; --2.20.1
Re: [PATCH v2 2/2] mmc: core: Export device/vendor ids from Common CIS for SDIO cards
In reply to Pali RohárQuoted 17 lines · Pali Rohár
Device/vendor ids from Common CIS (Card Information Structure) may be different as device/vendor ids from CIS on particular SDIO function.
Kernel currently exports only device/vendor ids from SDIO functions and not "main" device/vendor ids from Common CIS.
This patch exports "main" device/vendor ids for SDIO and SD combo cards at top level mmc device in sysfs hierarchy.
Userspace can use e.g. udev rules to correctly match whole SDIO card based on Common CIS device/vendor id and not only one particular SDIO function. Having this information in userspace also helps developers to debug whole SDIO card as e.g. kernel mmc quirks use device/vendor ids from Common CIS and not from particular SDIO function. Also it allows to write userspace applications which list all connected SDIO cards based on CIS ids.
Quoted 2 lines
Signed-off-by Pali Rohár <[email protected]>Reviewed-by Marek Behún <[email protected]>
Applied for next, thanks!
Kind regards
Uffe
Quoted 115 lines
---
Changes in V2:
* Makesd_std_groupstatic
* Put more information into commit message--- drivers/mmc/core/bus.c | 7 +++++++ drivers/mmc/core/sd.c | 26 +++++++++++++++++++++++++- drivers/mmc/core/sdio.c | 20 +++++++++++++++++++- 3 files changed, 51 insertions(+), 2 deletions(-)drivers/mmc/core/bus.c +7
-0@@ -93,6 +93,13 @@ mmc_bus_uevent(struct device *dev, struct kobj_uevent_env *env)return retval; } +if (card->type ==MMC_TYPE_SDIO || card->type ==MMC_TYPE_SD_COMBO ) { + retval =add_uevent_var (env,"SDIO_ID=%04X:%04X" , + card->cis.vendor, card->cis.device); +if (retval) +return retval; + } +/* * SDIO (non-combo) cards are not handled by mmc_block driver and do not * have accessible CID register which used by mmc_card_name() function. drivers/mmc/core/sd.c +25
-1@@ -707,7 +707,12 @@ static ssize_t mmc_dsr_show(struct device *dev, 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); +static struct attribute *sd_std_attrs[] = { + &dev_attr_vendor.attr, + &dev_attr_device.attr, &dev_attr_cid.attr, &dev_attr_csd.attr, &dev_attr_scr.attr,@@ -726,7 +731,26 @@ static struct attribute *sd_std_attrs[] = { &dev_attr_dsr.attr, NULL, }; -ATTRIBUTE_GROUPS (sd_std); + +static umode_t sd_std_is_visible (struct kobject *kobj,struct attribute *attr, +int index) +{ + 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 ) +return 0 ; + +return attr->mode; +} + +static const struct attribute_group sd_std_group = { + .attrs = sd_std_attrs, + .is_visible = sd_std_is_visible, +}; +__ATTRIBUTE_GROUPS (sd_std);struct device_type sd_type = { .groups = sd_std_groups,drivers/mmc/core/sdio.c +19
-2@@ -27,6 +27,24 @@#include "sdio_ops.h" #include "sdio_cis.h" +MMC_DEV_ATTR (vendor,"0x%04x\n" , card->cis.vendor); +MMC_DEV_ATTR (device,"0x%04x\n" , card->cis.device); +MMC_DEV_ATTR (ocr,"0x%08x\n" , card->ocr); +MMC_DEV_ATTR (rca,"0x%04x\n" , card->rca); + +static struct attribute *sdio_std_attrs[] = { + &dev_attr_vendor.attr, + &dev_attr_device.attr, + &dev_attr_ocr.attr, + &dev_attr_rca.attr, +NULL , +}; +ATTRIBUTE_GROUPS (sdio_std); + +static struct device_type sdio_type = { + .groups = sdio_std_groups, +}; +static int sdio_read_fbr (struct sdio_func *func) {int ret;@@ -598,7 +616,7 @@ static int mmc_sdio_init_card(struct mmc_host *host, u32 ocr,/* * Allocate card structure. */ - card =mmc_alloc_card (host,NULL ); + card =mmc_alloc_card (host, &sdio_type);if (IS_ERR (card)) { err =PTR_ERR (card); goto err; --2.20.1