From patchwork Mon Jul 27 13:38:34 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: 11686881 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 DBD7F913 for ; Mon, 27 Jul 2020 13:39:11 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id BF3F52083E for ; Mon, 27 Jul 2020 13:39:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1595857151; bh=Ssg0hCBrvkZt0mvlkHHrwrXugMvgz9amGvox14jD/BM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=mx0+qRWGHwqoUpGk+i0COFWUX7LgPugILxTFN4tMxSHG4CjTQl1+4yTpol3+VQWYH LhJiQ6rAjjeWivagOTpggS5rXrVOkXKjyARJS12/35nLvJD91vVvHaX7kT7KtFLA9h 1NNURoudVTLwkJNEaw3r1BKheSJldW5vrmj2zIvU= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729041AbgG0Nix (ORCPT ); Mon, 27 Jul 2020 09:38:53 -0400 Received: from mail.kernel.org ([198.145.29.99]:39264 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727026AbgG0Niw (ORCPT ); Mon, 27 Jul 2020 09:38:52 -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 42FDE2083B; Mon, 27 Jul 2020 13:38:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1595857132; bh=Ssg0hCBrvkZt0mvlkHHrwrXugMvgz9amGvox14jD/BM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=0fN3XHpEfRVx6LuFdGe/ak/aG3TWBPUg0XKdiLt8ylMgyZeGVGDthxUiDhTP/m0rd /bbDZls/paaH32rcoVHd8L8y+R9KRuL5jcQxTOAABScIeTEwk/SD6uAIDJTXznkrFE fsX9pWpPoR27zrmkjFdOXYGJf+k4Mez7pQFHX7Ws= Received: by pali.im (Postfix) id 8AD5EC89; Mon, 27 Jul 2020 15:38:50 +0200 (CEST) From: =?utf-8?q?Pali_Roh=C3=A1r?= To: Ulf Hansson Cc: linux-mmc@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 1/4] mmc: sdio: Check for CISTPL_VERS_1 buffer size Date: Mon, 27 Jul 2020 15:38:34 +0200 Message-Id: <20200727133837.19086-2-pali@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200727133837.19086-1-pali@kernel.org> References: <20200727133837.19086-1-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 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 --- 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; From patchwork Mon Jul 27 13:38:35 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: 11686875 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 358FF913 for ; Mon, 27 Jul 2020 13:38:56 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1DD892177B for ; Mon, 27 Jul 2020 13:38:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1595857136; bh=WBaMbqOzM7xTyiTHBeAekdobhisWTjL6P+5D2OeDLO0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=hGQv0afEyiTriaK3/eTjzdLh5Ce2DM3q1V+uEZvysg/lC3AarY7sZfPEVfEo3EFxw dUV84gGv7G7d5koellutbRvcCbI1CI5KZydEUxm8iZ/MLsD6DjeHyGCtPQqhmoSYGX wnfk1kktx/us9CZQWOhpBeGW2HSuFHadZIo7l3m4= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729058AbgG0Niy (ORCPT ); Mon, 27 Jul 2020 09:38:54 -0400 Received: from mail.kernel.org ([198.145.29.99]:39286 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729051AbgG0Niy (ORCPT ); Mon, 27 Jul 2020 09:38:54 -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 4F6312083B; Mon, 27 Jul 2020 13:38:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1595857133; bh=WBaMbqOzM7xTyiTHBeAekdobhisWTjL6P+5D2OeDLO0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=j8PRSVZZK4nQHBOp3WFeCS+yLq/YvOO3h5UYIxAAvB3AqBe5k4pR+S9nrJKQbh6kv V+VuhISouUl85Ma8r93SRM3BMl3i/cUxwKd/ZltZBfz7t+rmwPwp/JoULGug1U9HZe VZdUBi5MQS4E611KayVkmIjAFmtjTEpEXIdPtUjc= Received: by pali.im (Postfix) id 88D42CB0; Mon, 27 Jul 2020 15:38:51 +0200 (CEST) From: =?utf-8?q?Pali_Roh=C3=A1r?= To: Ulf Hansson Cc: linux-mmc@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 2/4] mmc: sdio: Parse CISTPL_VERS_1 major and minor revision numbers Date: Mon, 27 Jul 2020 15:38:35 +0200 Message-Id: <20200727133837.19086-3-pali@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200727133837.19086-1-pali@kernel.org> References: <20200727133837.19086-1-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 They should indicate compliance of standard. Signed-off-by: Pali Rohár --- 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 */ From patchwork Mon Jul 27 13:38:36 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: 11686879 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 BC3DE722 for ; Mon, 27 Jul 2020 13:39:09 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A42092173E for ; Mon, 27 Jul 2020 13:39:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1595857149; bh=K+Hvt4TqrFnW+IvY4RgwiyQKoPSqYctqgba73myhUgE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=rHsxngs2RQX7yOPWePYELGIdRxCOCTxHbjNYiI7KIMJp0o64oaMhoesGpvTPeHy1Z 7PGmxSsrdi+cg0QVsdj6r3/RWxBS04GMLopFfch5WipLU5pc0wjcJGPGR35grwsBCz Niw/XuhM6w05uDoHt4hSD0kIG3IJrwFFlKp+vxQ4= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728344AbgG0NjF (ORCPT ); Mon, 27 Jul 2020 09:39:05 -0400 Received: from mail.kernel.org ([198.145.29.99]:39306 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729057AbgG0Niy (ORCPT ); Mon, 27 Jul 2020 09:38:54 -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 1C0AE2086A; Mon, 27 Jul 2020 13:38:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1595857134; bh=K+Hvt4TqrFnW+IvY4RgwiyQKoPSqYctqgba73myhUgE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=FwBpFoHwZw2PYdcYYok127rFZRsljWuwtHWcNBm7ExZrdGJVgUZW2ptjBA54L6i5Q 2sWwvN22fh4K7doul17ivG2XSHY/YFusrZjUMq00hy2VgsXuPCE7zcQUpdCaYfJx84 f//aDzQZ+qagMRiMNvIi5f5Kca8x2D6zKYKbxrQs= Received: by pali.im (Postfix) id 58D67CB2; Mon, 27 Jul 2020 15:38:52 +0200 (CEST) From: =?utf-8?q?Pali_Roh=C3=A1r?= To: Ulf Hansson Cc: linux-mmc@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 3/4] mmc: sdio: Extend sdio_config_attr macro and use it also for modalias Date: Mon, 27 Jul 2020 15:38:36 +0200 Message-Id: <20200727133837.19086-4-pali@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200727133837.19086-1-pali@kernel.org> References: <20200727133837.19086-1-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 This simplify code for generating sdio config attributes and allows easily define new sdio attributes. Signed-off-by: Pali Rohár --- 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, From patchwork Mon Jul 27 13:38:37 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: 11686877 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 2EFE7722 for ; Mon, 27 Jul 2020 13:39:05 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 10F392086A for ; Mon, 27 Jul 2020 13:39:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1595857145; bh=Ch8foSKe0HJ0Blu8CEHeXIcdrEOxplMElgo0OhRZ1ZQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=iwt82Bfbi2OVrWMaIgc6j8+HihEVT0QAgJrv8IFWa1oThQaWdLFEHgFzzsHYmD3Cn 5wQASucNDBYPlWPW23fogKiUGQHaMV74o42o6yl72YbcxW00k2d69oWmPICIEGwPX8 APLQXDMzUTHwHFwv6A8x6/jNv0A80+5oZvGOy0PQ= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728312AbgG0Ni5 (ORCPT ); Mon, 27 Jul 2020 09:38:57 -0400 Received: from mail.kernel.org ([198.145.29.99]:39362 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729066AbgG0Ni4 (ORCPT ); Mon, 27 Jul 2020 09:38:56 -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 3BB2D2083B; Mon, 27 Jul 2020 13:38:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1595857135; bh=Ch8foSKe0HJ0Blu8CEHeXIcdrEOxplMElgo0OhRZ1ZQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=uxjlqctLtriqwSUVt8cH1f/HHrHHc+KbWo5gn1UMpZzNqoCSADAoR/MJRCunWW0UX h1BSVnl2xA9lAjY3nhSz84bONKAReQ1ZAd87HYkd1b64duP2lrWsFtlnKKiZJe/vLs KPDmZTsMR3QZX63LUx8QdkkSEaTwqUW9Nc/foGpg= Received: by pali.im (Postfix) id 8A270C89; Mon, 27 Jul 2020 15:38:53 +0200 (CEST) From: =?utf-8?q?Pali_Roh=C3=A1r?= To: Ulf Hansson Cc: linux-mmc@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 4/4] mmc: sdio: Export SDIO revision and info strings to userspace Date: Mon, 27 Jul 2020 15:38:37 +0200 Message-Id: <20200727133837.19086-5-pali@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200727133837.19086-1-pali@kernel.org> References: <20200727133837.19086-1-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 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 --- 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))