From patchwork Mon Apr 4 11:11:19 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Winkler, Tomas" X-Patchwork-Id: 8740261 Return-Path: X-Original-To: patchwork-linux-scsi@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id B67C59F7C9 for ; Mon, 4 Apr 2016 11:18:02 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id CAB0F200E1 for ; Mon, 4 Apr 2016 11:18:01 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id CFFA520121 for ; Mon, 4 Apr 2016 11:18:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755202AbcDDLRq (ORCPT ); Mon, 4 Apr 2016 07:17:46 -0400 Received: from mga09.intel.com ([134.134.136.24]:22774 "EHLO mga09.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755213AbcDDLM4 (ORCPT ); Mon, 4 Apr 2016 07:12:56 -0400 Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by orsmga102.jf.intel.com with ESMTP; 04 Apr 2016 04:12:57 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.24,440,1455004800"; d="scan'208";a="78640116" Received: from twinkler-dhg.jer.intel.com ([10.12.87.84]) by fmsmga004.fm.intel.com with ESMTP; 04 Apr 2016 04:12:52 -0700 From: Tomas Winkler To: gregkh@linuxfoundation.org, Ulf Hansson , Adrian Hunter , James Bottomley , "Martin K. Petersen" , Vinayak Holikatti , Andy Lutomirski Cc: Christoph Hellwig , Yaniv Gardi , Joao Pinto , linux-mmc@vger.kernel.org, linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org, Tomas Winkler Subject: [PATCH v2 3/8] char: rpmb: add device attributes Date: Mon, 4 Apr 2016 14:11:19 +0300 Message-Id: <1459768284-26997-4-git-send-email-tomas.winkler@intel.com> X-Mailer: git-send-email 2.4.3 In-Reply-To: <1459768284-26997-1-git-send-email-tomas.winkler@intel.com> References: <1459768284-26997-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-Spam-Status: No, score=-7.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.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 Signed-off-by: Tomas Winkler --- V2: resend Documentation/ABI/testing/sysfs-class-rpmb | 24 +++++++++++ drivers/char/rpmb/core.c | 64 ++++++++++++++++++++++++++++++ 2 files changed, 88 insertions(+) diff --git a/Documentation/ABI/testing/sysfs-class-rpmb b/Documentation/ABI/testing/sysfs-class-rpmb index 62d1959bf19e..9b2bf65dae95 100644 --- a/Documentation/ABI/testing/sysfs-class-rpmb +++ b/Documentation/ABI/testing/sysfs-class-rpmb @@ -13,3 +13,27 @@ Contact: Tomas Winkler Description: The /sys/class/rpmb/rpmbN directory is created for each RPMB registered device + +What: /sys/class/rpmb/rpmbN/id +Date: Mar 2016 +KernelVersion: TBD +Contact: Tomas Winkler +Description: + The /sys/class/rpmb/rpmbN/id file contains device id + in a binary form + +What: /sys/class/rpmb/rpmbN/type +Date: Mar 2016 +KernelVersion: TBD +Contact: Tomas Winkler +Description: + The /sys/class/rpmb/rpmbN/type file contains device + underlay storage type technology: EMMC, UFS + +What: /sys/class/rpmb/rpmbN/reliable_wr_cnt +Date: Mar 2016 +KernelVersion: TBD +Contact: Tomas Winkler +Description: + The /sys/class/rpmb/rpmbN/reliable_wr_cnt file contains + number of blocks that can be written in a single request diff --git a/drivers/char/rpmb/core.c b/drivers/char/rpmb/core.c index c9ea30aca6be..fb401331d345 100644 --- a/drivers/char/rpmb/core.c +++ b/drivers/char/rpmb/core.c @@ -230,6 +230,68 @@ 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 = scnprintf(buf, PAGE_SIZE, "EMMC\n"); + break; + case RPMB_TYPE_UFS: + ret = scnprintf(buf, PAGE_SIZE, "UFS\n"); + break; + default: + ret = scnprintf(buf, PAGE_SIZE, "UNKNOWN\n"); + break; + } + + return ret; +} +static DEVICE_ATTR_RO(type); + +static ssize_t id_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + 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; + + memcpy(buf, rdev->ops->dev_id, sz); + return sz; +} +static DEVICE_ATTR_RO(id); + +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 scnprintf(buf, PAGE_SIZE, "%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_id.attr, + &dev_attr_reliable_wr_cnt.attr, + NULL, +}; + +static struct attribute_group rpmb_attr_group = { + .attrs = rpmb_attrs, +}; + +static const struct attribute_group *rpmb_attr_groups[] = { + &rpmb_attr_group, + NULL +}; + /** * rpmb_dev_unregister - unregister RPMB partition from the RPMB subsystem * @@ -300,6 +362,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;