From patchwork Wed May 27 11:08:57 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Pali_Roh=C3=A1r?= X-Patchwork-Id: 11572617 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B77B660D for ; Wed, 27 May 2020 11:09:11 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9F4412089D for ; Wed, 27 May 2020 11:09:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1590577751; bh=3diRTG4EYmBHANbsqVvKSY9n7VhyjG1AQZ7fBVDT5fw=; h=From:To:Cc:Subject:Date:List-ID:From; b=uekt+a0nqLcB9i/7FhyyBqvgj2PDMbJla4BG+gfN2pUW7mLTYJNlFeQCPuFRLzbbw ydJdEVEe9TBby8f87LjxERb4xiCUASrGFdMsPgL/tAmnhf6TAOvzfZgYTmgypYdXsc rDOnqtYKxFY893+A9XyqqM+vKCHIowCC07YRHylE= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388021AbgE0LJL (ORCPT ); Wed, 27 May 2020 07:09:11 -0400 Received: from mail.kernel.org ([198.145.29.99]:49308 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387534AbgE0LJK (ORCPT ); Wed, 27 May 2020 07:09:10 -0400 Received: from pali.im (pali.im [31.31.79.79]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 7902E2075A; Wed, 27 May 2020 11:09:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1590577750; bh=3diRTG4EYmBHANbsqVvKSY9n7VhyjG1AQZ7fBVDT5fw=; h=From:To:Cc:Subject:Date:From; b=mZouomnUotk3X2CsfpVxo+OBvqg04n7c9VZ4A8Iwwo6pLg8LIXuyLbHcjK0PzZIgH t4xujoUFhFAQMYEZ6mbg7FmTAD4S+WWgsIDhx3oAzETDGotud1HGQnYzlpaMbrv8uQ RgA6AbMHTUb+oXrASEw435R222pO3ASMgeebBTEI= Received: by pali.im (Postfix) id CF479BF4; Wed, 27 May 2020 13:09:07 +0200 (CEST) From: =?utf-8?q?Pali_Roh=C3=A1r?= To: Ulf Hansson Cc: linux-mmc@vger.kernel.org, linux-kernel@vger.kernel.org, =?utf-8?q?Marek?= =?utf-8?q?_Beh=C3=BAn?= Subject: [PATCH v2 1/2] mmc: core: Do not export MMC_NAME= and MODALIAS=mmc:block for SDIO cards Date: Wed, 27 May 2020 13:08:57 +0200 Message-Id: <20200527110858.17504-1-pali@kernel.org> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Sender: linux-mmc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-mmc@vger.kernel.org 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. Signed-off-by: Pali Rohár Reviewed-by: Marek Behún --- Changes in V2: * Use early returns pattern --- drivers/mmc/core/bus.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/drivers/mmc/core/bus.c b/drivers/mmc/core/bus.c index 74de3f2dd..b1cb447da 100644 --- a/drivers/mmc/core/bus.c +++ b/drivers/mmc/core/bus.c @@ -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; From patchwork Wed May 27 11:08:58 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Pali_Roh=C3=A1r?= X-Patchwork-Id: 11572619 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id D526290 for ; Wed, 27 May 2020 11:09:25 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id BD817207E8 for ; Wed, 27 May 2020 11:09:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1590577765; bh=9fcnFlasW8TUPD1jxPuiN0oTUQFwr24T9kaWUNOT8ao=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=n7jA0JHvh9gKlw00OYVp5OcMs37bUx9uvXF+/Qunflh3dddO+GerwAcjYhh7PbUiJ VV7H9jf/ggxRG/yUQP9sHSThYdId5NsRP2/6MQM4DaYrH8J07bcPa7wrUFzZIaFLVQ 1XiAWjd9s3CW99/sqeZesisTPt1rYa9FgJweuPL0= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388067AbgE0LJZ (ORCPT ); Wed, 27 May 2020 07:09:25 -0400 Received: from mail.kernel.org ([198.145.29.99]:49422 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387534AbgE0LJY (ORCPT ); Wed, 27 May 2020 07:09:24 -0400 Received: from pali.im (pali.im [31.31.79.79]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id CEC402075A; Wed, 27 May 2020 11:09:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1590577760; bh=9fcnFlasW8TUPD1jxPuiN0oTUQFwr24T9kaWUNOT8ao=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=rFd32wYNw1zd5ZosLr3p8o8FMTZ3S4IcBH7fHsLANne+C8oNJrbGV3PKm5WKXtgog V4JNAcKWUn/ZX/gzGxvUizj4fVHgB0BLHhTN+rtRxQS9bremASwyyNYDlvsEbO/4Rp G/fdjm6jDZNHLRhDC/QpGvZyCVuZ9kh1Z1ViwhXM= Received: by pali.im (Postfix) id 0CFCBBF4; Wed, 27 May 2020 13:09:19 +0200 (CEST) From: =?utf-8?q?Pali_Roh=C3=A1r?= To: Ulf Hansson Cc: linux-mmc@vger.kernel.org, linux-kernel@vger.kernel.org, =?utf-8?q?Marek?= =?utf-8?q?_Beh=C3=BAn?= Subject: [PATCH v2 2/2] mmc: core: Export device/vendor ids from Common CIS for SDIO cards Date: Wed, 27 May 2020 13:08:58 +0200 Message-Id: <20200527110858.17504-2-pali@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200527110858.17504-1-pali@kernel.org> References: <20200526154334.21222-2-pali@kernel.org> MIME-Version: 1.0 Sender: linux-mmc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-mmc@vger.kernel.org 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. Signed-off-by: Pali Rohár Reviewed-by: Marek Behún --- 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(-) diff --git a/drivers/mmc/core/bus.c b/drivers/mmc/core/bus.c index b1cb447da..70207f11a 100644 --- a/drivers/mmc/core/bus.c +++ b/drivers/mmc/core/bus.c @@ -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. diff --git a/drivers/mmc/core/sd.c b/drivers/mmc/core/sd.c index 76c7add36..ee1a51ff6 100644 --- a/drivers/mmc/core/sd.c +++ b/drivers/mmc/core/sd.c @@ -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, diff --git a/drivers/mmc/core/sdio.c b/drivers/mmc/core/sdio.c index ebb387aa5..2d86a9db5 100644 --- a/drivers/mmc/core/sdio.c +++ b/drivers/mmc/core/sdio.c @@ -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;