From patchwork Mon Nov 7 19:53:07 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Winkler, Tomas" X-Patchwork-Id: 9415873 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 409FF60512 for ; Mon, 7 Nov 2016 19:00:59 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2FE8228D1D for ; Mon, 7 Nov 2016 19:00:59 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 24BA828D89; Mon, 7 Nov 2016 19:00:59 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B03CE28D1D for ; Mon, 7 Nov 2016 19:00:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933274AbcKGTAl (ORCPT ); Mon, 7 Nov 2016 14:00:41 -0500 Received: from mga04.intel.com ([192.55.52.120]:12220 "EHLO mga04.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933093AbcKGS6Y (ORCPT ); Mon, 7 Nov 2016 13:58:24 -0500 Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga104.fm.intel.com with ESMTP; 07 Nov 2016 10:57:16 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.31,606,1473145200"; d="scan'208";a="188665088" Received: from twinkler-lnx.jer.intel.com ([10.12.87.167]) by fmsmga004.fm.intel.com with ESMTP; 07 Nov 2016 10:57:11 -0800 From: Tomas Winkler To: Greg Kroah-Hartman , Ulf Hansson , Adrian Hunter , James Bottomley , "Martin K . Petersen" , Vinayak Holikatti , Andy Lutomirski , =?UTF-8?q?Arve=20Hj=C3=B8nnev=C3=A5g?= , Michael Ryleev , Joao Pinto , Christoph Hellwig , Yaniv Gardi Cc: Avri Altman , linux-kernel@vger.kernel.org, linux-mmc@vger.kernel.org, linux-scsi@vger.kernel.org, linux-doc@vger.kernel.org, Tomas Winkler Subject: [PATCH v7 04/11] char: rpmb: add device attributes Date: Mon, 7 Nov 2016 21:53:07 +0200 Message-Id: <1478548394-8184-5-git-send-email-tomas.winkler@intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1478548394-8184-1-git-send-email-tomas.winkler@intel.com> References: <1478548394-8184-1-git-send-email-tomas.winkler@intel.com> Sender: linux-scsi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Add attribute type that displays underlay storage type technology EMMC, UFS, and attribute id, that displays underlay storage device id. For EMMC this would be content of CID and for UFS serial number from the device descriptor. V2: resend V3: set kernel version to 4.7 V4: update target date to Maj V5: update date and kernel version V6: 1. Add simulation device type 2. Update date and kernel version 3. Use binary attribute for id 4. use simple sprintf instead of scnprintf 5. Add more verbose documenation V7: resend Signed-off-by: Tomas Winkler --- Documentation/ABI/testing/sysfs-class-rpmb | 27 +++++++++++ drivers/char/rpmb/core.c | 72 ++++++++++++++++++++++++++++++ 2 files changed, 99 insertions(+) diff --git a/Documentation/ABI/testing/sysfs-class-rpmb b/Documentation/ABI/testing/sysfs-class-rpmb index 2ea6dbb91fac..3c01925e29dc 100644 --- a/Documentation/ABI/testing/sysfs-class-rpmb +++ b/Documentation/ABI/testing/sysfs-class-rpmb @@ -18,3 +18,30 @@ Contact: Tomas Winkler Description: The /sys/class/rpmb/rpmbN directory is created for each RPMB registered device. + +What: /sys/class/rpmb/rpmbN/type +Date: Nov 2016 +KernelVersion: 4.10 +Contact: Tomas Winkler +Description: + The /sys/class/rpmb/rpmbN/type file contains device + underlaying storage type technology: EMMC, UFS, SIM. + +What: /sys/class/rpmb/rpmbN/id +Date: Nov 2016 +KernelVersion: 4.10 +Contact: Tomas Winkler +Description: + The /sys/class/rpmb/rpmbN/id file contains unique device id + in a binary form as defined by underlying storage device. + In case of multiple RPMB devices a user can determine correct + device. + The content can be parsed according the storage device type. + +What: /sys/class/rpmb/rpmbN/reliable_wr_cnt +Date: Nov 2016 +KernelVersion: 4.10 +Contact: Tomas Winkler +Description: + The /sys/class/rpmb/rpmbN/reliable_wr_cnt file contains + number of blocks that can be reliable written in a single request. diff --git a/drivers/char/rpmb/core.c b/drivers/char/rpmb/core.c index 8cfbbb721538..f6b4cabb0982 100644 --- a/drivers/char/rpmb/core.c +++ b/drivers/char/rpmb/core.c @@ -338,6 +338,76 @@ struct rpmb_dev *rpmb_dev_find_by_device(struct device *parent) } EXPORT_SYMBOL_GPL(rpmb_dev_find_by_device); +static ssize_t type_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + struct rpmb_dev *rdev = to_rpmb_dev(dev); + ssize_t ret; + + switch (rdev->ops->type) { + case RPMB_TYPE_EMMC: + ret = sprintf(buf, "EMMC\n"); + break; + case RPMB_TYPE_UFS: + ret = sprintf(buf, "UFS\n"); + break; + case RPMB_TYPE_SIM: + ret = sprintf(buf, "SIM\n"); + break; + default: + ret = sprintf(buf, "UNKNOWN\n"); + break; + } + + return ret; +} +static DEVICE_ATTR_RO(type); + +static ssize_t id_read(struct file *file, struct kobject *kobj, + struct bin_attribute *attr, char *buf, + loff_t off, size_t count) +{ + struct device *dev = kobj_to_dev(kobj); + struct rpmb_dev *rdev = to_rpmb_dev(dev); + size_t sz = min_t(size_t, rdev->ops->dev_id_len, PAGE_SIZE); + + if (!rdev->ops->dev_id) + return 0; + + return memory_read_from_buffer(buf, count, &off, rdev->ops->dev_id, sz); +} +static BIN_ATTR_RO(id, 0); + +static ssize_t reliable_wr_cnt_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + struct rpmb_dev *rdev = to_rpmb_dev(dev); + + return sprintf(buf, "%u\n", rdev->ops->reliable_wr_cnt); +} +static DEVICE_ATTR_RO(reliable_wr_cnt); + +static struct attribute *rpmb_attrs[] = { + &dev_attr_type.attr, + &dev_attr_reliable_wr_cnt.attr, + NULL, +}; + +static struct bin_attribute *rpmb_bin_attributes[] = { + &bin_attr_id, + NULL, +}; + +static struct attribute_group rpmb_attr_group = { + .attrs = rpmb_attrs, + .bin_attrs = rpmb_bin_attributes, +}; + +static const struct attribute_group *rpmb_attr_groups[] = { + &rpmb_attr_group, + NULL +}; + /** * rpmb_dev_unregister - unregister RPMB partition from the RPMB subsystem * @@ -407,6 +477,8 @@ struct rpmb_dev *rpmb_dev_register(struct device *dev, dev_set_name(&rdev->dev, "rpmb%d", id); rdev->dev.class = &rpmb_class; rdev->dev.parent = dev; + rdev->dev.groups = rpmb_attr_groups; + ret = device_register(&rdev->dev); if (ret) goto exit;