From patchwork Thu May 12 14:00:46 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sreekanth Reddy X-Patchwork-Id: 571983 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8925EC433F5 for ; Thu, 12 May 2022 13:50:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1354649AbiELNud (ORCPT ); Thu, 12 May 2022 09:50:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56510 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1354703AbiELNua (ORCPT ); Thu, 12 May 2022 09:50:30 -0400 Received: from mail-pl1-x62f.google.com (mail-pl1-x62f.google.com [IPv6:2607:f8b0:4864:20::62f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AB01224A397 for ; Thu, 12 May 2022 06:50:28 -0700 (PDT) Received: by mail-pl1-x62f.google.com with SMTP id q18so4904613pln.12 for ; Thu, 12 May 2022 06:50:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=broadcom.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version; bh=zdCnOF6Ba0xx/Y8+/HAY/7pVmQk9xCTkyF4P4CSvFB0=; b=X0vGoh8fTu9zNgMVNrfXfRdpRIYH/ikEsdkQUinuQWw/YUgoKQiqX0yYrpDiCTc6Lm vH4tFHCrjPi1aQun6uyQpOkIvFJSFTl+Ln71yVa98Tm/gh8YRPjwvJk4kxJpg40a74T9 KradyfZiL3pe5uBtKSLgYtqb8uzCYsIqK0fX0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version; bh=zdCnOF6Ba0xx/Y8+/HAY/7pVmQk9xCTkyF4P4CSvFB0=; b=xs7WED27cIySOqYPTksDhV5LsLHyllKQH8scc8NR1K/B8hg2Gb1z13PFH1IZ4wCHi6 4LEOoc6BhXpKBf3FWlo4GWkkWO7nbgs5dJfOI2JuS/IhVmapWtFhlq3i4iFZaaAvL+58 l7QCoNSHiQ5i7sOyVtJW316VRt2ogiwlV9Nv/veu9OMYGiIrqDbSlZSxwowtpFY5DFdj 4ty9BEX66pK/IQoxgeki3Nj3fMArbdktrAdnEToHuQJOvothDCo8ozi5lN4KitwcCmsC p7wBjRgxouPxjq0x97ueaZodGIa6jgIyy/DJWF7Py6bif45fyXNgWt0cYli/5pS1B+11 vhFA== X-Gm-Message-State: AOAM531JIn4p/oKi0CPq/jNQ9DNcoRxpwnAE8yMcpClHEs4JG39j2oJg fvlfKrpskTb0304YYrGFtL2iyDmgbrXSsYMLXjHRijgqW3ir2TuM8sMFRnRJkGBhSGFOjD1bWfz WA2MXOWcrm2NJ8aV6GluayQQ5eN47H3StVZc47eNJh0dCDG2DH1k5D9cnvZayIrHZnGt41CMOdx 58Ow73MdOl X-Google-Smtp-Source: ABdhPJwl9lNz8CE7Anl4t9GjM/949MlsaOz6sPUfj72aUyVhoGfxWN8LZR6BkqhuDvOkbGcWrSNDhg== X-Received: by 2002:a17:90a:884:b0:1d9:531c:9cd6 with SMTP id v4-20020a17090a088400b001d9531c9cd6mr10843726pjc.211.1652363427614; Thu, 12 May 2022 06:50:27 -0700 (PDT) Received: from dhcp-10-123-20-36.dhcp.broadcom.net ([192.19.252.250]) by smtp.gmail.com with ESMTPSA id t21-20020a17090ad15500b001cd4989ff47sm1872409pjw.14.2022.05.12.06.50.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 May 2022 06:50:27 -0700 (PDT) From: Sreekanth Reddy To: linux-scsi@vger.kernel.org Cc: martin.petersen@oracle.com, Sreekanth Reddy Subject: [PATCH 2/2] mpi3mr: Add target device related sysfs attributes Date: Thu, 12 May 2022 19:30:46 +0530 Message-Id: <20220512140046.19046-3-sreekanth.reddy@broadcom.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20220512140046.19046-1-sreekanth.reddy@broadcom.com> References: <20220512140046.19046-1-sreekanth.reddy@broadcom.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org Added sysfs attributes for exposing target device details such as SAS address, firmware device handle and persistent ID for the controller attached devices and RAID volumes. Signed-off-by: Sreekanth Reddy --- drivers/scsi/mpi3mr/mpi3mr.h | 1 + drivers/scsi/mpi3mr/mpi3mr_app.c | 120 +++++++++++++++++++++++++++++++ drivers/scsi/mpi3mr/mpi3mr_os.c | 1 + 3 files changed, 122 insertions(+) diff --git a/drivers/scsi/mpi3mr/mpi3mr.h b/drivers/scsi/mpi3mr/mpi3mr.h index 584659e..01cd017 100644 --- a/drivers/scsi/mpi3mr/mpi3mr.h +++ b/drivers/scsi/mpi3mr/mpi3mr.h @@ -1085,4 +1085,5 @@ int mpi3mr_pel_get_seqnum_post(struct mpi3mr_ioc *mrioc, void mpi3mr_app_save_logdata(struct mpi3mr_ioc *mrioc, char *event_data, u16 event_data_size); extern const struct attribute_group *mpi3mr_host_groups[]; +extern const struct attribute_group *mpi3mr_dev_groups[]; #endif /*MPI3MR_H_INCLUDED*/ diff --git a/drivers/scsi/mpi3mr/mpi3mr_app.c b/drivers/scsi/mpi3mr/mpi3mr_app.c index c9b153c..69054a8 100644 --- a/drivers/scsi/mpi3mr/mpi3mr_app.c +++ b/drivers/scsi/mpi3mr/mpi3mr_app.c @@ -1742,3 +1742,123 @@ const struct attribute_group *mpi3mr_host_groups[] = { &mpi3mr_host_attr_group, NULL, }; + + +/* + * SCSI Device attributes under sysfs + */ + +/** + * sas_address_show - SysFS callback for dev SASaddress display + * @dev: class device + * @attr: Device attributes + * @buf: Buffer to copy + * + * Return: snprintf() return after copying SAS address of the + * specific SAS/SATA end device. + */ +static ssize_t +sas_address_show(struct device *dev, struct device_attribute *attr, + char *buf) +{ + struct scsi_device *sdev = to_scsi_device(dev); + struct mpi3mr_sdev_priv_data *sdev_priv_data; + struct mpi3mr_stgt_priv_data *tgt_priv_data; + struct mpi3mr_tgt_dev *tgtdev; + + sdev_priv_data = sdev->hostdata; + if (!sdev_priv_data) + return 0; + + tgt_priv_data = sdev_priv_data->tgt_priv_data; + if (!tgt_priv_data) + return 0; + tgtdev = tgt_priv_data->tgt_dev; + if (!tgtdev || tgtdev->dev_type != MPI3_DEVICE_DEVFORM_SAS_SATA) + return 0; + return snprintf(buf, PAGE_SIZE, "0x%016llx\n", + (unsigned long long)tgtdev->dev_spec.sas_sata_inf.sas_address); +} + +static DEVICE_ATTR_RO(sas_address); + +/** + * device_handle_show - SysFS callback for device handle display + * @dev: class device + * @attr: Device attributes + * @buf: Buffer to copy + * + * Return: snprintf() return after copying firmware internal + * device handle of the specific device. + */ +static ssize_t +device_handle_show(struct device *dev, struct device_attribute *attr, + char *buf) +{ + struct scsi_device *sdev = to_scsi_device(dev); + struct mpi3mr_sdev_priv_data *sdev_priv_data; + struct mpi3mr_stgt_priv_data *tgt_priv_data; + struct mpi3mr_tgt_dev *tgtdev; + + sdev_priv_data = sdev->hostdata; + if (!sdev_priv_data) + return 0; + + tgt_priv_data = sdev_priv_data->tgt_priv_data; + if (!tgt_priv_data) + return 0; + tgtdev = tgt_priv_data->tgt_dev; + if (!tgtdev) + return 0; + return snprintf(buf, PAGE_SIZE, "0x%04x\n", tgtdev->dev_handle); +} + +static DEVICE_ATTR_RO(device_handle); + +/** + * persistent_id_show - SysFS callback for persisten ID display + * @dev: class device + * @attr: Device attributes + * @buf: Buffer to copy + * + * Return: snprintf() return after copying persistent ID of the + * of the specific device. + */ +static ssize_t +persistent_id_show(struct device *dev, struct device_attribute *attr, + char *buf) +{ + struct scsi_device *sdev = to_scsi_device(dev); + struct mpi3mr_sdev_priv_data *sdev_priv_data; + struct mpi3mr_stgt_priv_data *tgt_priv_data; + struct mpi3mr_tgt_dev *tgtdev; + + sdev_priv_data = sdev->hostdata; + if (!sdev_priv_data) + return 0; + + tgt_priv_data = sdev_priv_data->tgt_priv_data; + if (!tgt_priv_data) + return 0; + tgtdev = tgt_priv_data->tgt_dev; + if (!tgtdev) + return 0; + return snprintf(buf, PAGE_SIZE, "%d\n", tgtdev->perst_id); +} +static DEVICE_ATTR_RO(persistent_id); + +static struct attribute *mpi3mr_dev_attrs[] = { + &dev_attr_sas_address.attr, + &dev_attr_device_handle.attr, + &dev_attr_persistent_id.attr, + NULL, +}; + +static const struct attribute_group mpi3mr_dev_attr_group = { + .attrs = mpi3mr_dev_attrs +}; + +const struct attribute_group *mpi3mr_dev_groups[] = { + &mpi3mr_dev_attr_group, + NULL, +}; diff --git a/drivers/scsi/mpi3mr/mpi3mr_os.c b/drivers/scsi/mpi3mr/mpi3mr_os.c index f5c345d..d8c195b 100644 --- a/drivers/scsi/mpi3mr/mpi3mr_os.c +++ b/drivers/scsi/mpi3mr/mpi3mr_os.c @@ -4147,6 +4147,7 @@ static struct scsi_host_template mpi3mr_driver_template = { .track_queue_depth = 1, .cmd_size = sizeof(struct scmd_priv), .shost_groups = mpi3mr_host_groups, + .sdev_groups = mpi3mr_dev_groups, }; /**