From patchwork Thu Apr 7 19:29:11 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sumit Saxena X-Patchwork-Id: 559411 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 357B6C433F5 for ; Thu, 7 Apr 2022 19:34:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229810AbiDGTgG (ORCPT ); Thu, 7 Apr 2022 15:36:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35140 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229469AbiDGTgF (ORCPT ); Thu, 7 Apr 2022 15:36:05 -0400 Received: from mail-pj1-x1036.google.com (mail-pj1-x1036.google.com [IPv6:2607:f8b0:4864:20::1036]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1AA432C73A7 for ; Thu, 7 Apr 2022 12:33:35 -0700 (PDT) Received: by mail-pj1-x1036.google.com with SMTP id gt4so6523959pjb.4 for ; Thu, 07 Apr 2022 12:33:35 -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=S60XJoNKCcxcvXan3WKRA4CycrfiFjExKP9uveDLI5I=; b=ErtUN5/IJEWQiBYHh+EK7gMUqdw16CToiRmSIudWEOmEldXMGKEBLuXWur/atjtNiQ Gy9lSmgHI36EjYmOEuQ3yWBwSku1BK2+sM1+4O/kS8QWn6VO9i5yTLinVyyXjqNFj8bj F2TySSgCkluUWXbJuRmdSYv2eBLmck/cAFeaM= 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=S60XJoNKCcxcvXan3WKRA4CycrfiFjExKP9uveDLI5I=; b=YUUTAnJmBEsqTiiOupsZ3XQhNhgOuv2bS5aMOowG8jSNBm2qQiW+p6PNFW4doZD1gn kKG0wwQKiHR5tE270G60s9YGSOKHFnICc8L7aHf5rwiVNMnsHU8B+/kmmczUDtnOLbKV GuRh45Y/wFKNC30tcwjqomGawyVI2GUtDmMi1Gm1aoPlM0/zNw+yCpHkodnwOYAbT7Te e2ocP6o0GnO72n+Sf+B/UcpV0Fkgd9XXfUeD2TCg8zVp/TWihmplBPisCCE+MxXIAKBO HyoHBq8QdVaI2jOrSTzlogx+q1YixjTgr7wVaSDk21/00qjMOCxYLy/cwebpmOPndepz OooA== X-Gm-Message-State: AOAM531Vb4GyTIxFYN2k4Y+qy1yq/xB74O4OSITGq+/vj8gKoIrFT93e Uy55XVteLy4Tbhi+JNN9nCOUvHtDJO+PQtNtVuNycc5SGLwYBNWgQMxdptiDfnASb+e4puhq0lL A/VomufoUtWyO9cFCffd5Z+wgY0ll0eHrNEMtGMofVgtMzUlWGgOaEkh4gLu0+IW11wj9/OfOUS CATgvAQWUuZQ== X-Google-Smtp-Source: ABdhPJzRdeVgi1CMbytDuZ8iZcF68VfL8e8R8mm3o6i24VLqIjo3WlM0tS6RUfZlo29QZSoY5kPd6A== X-Received: by 2002:a17:902:8ec4:b0:156:b8a6:f9d8 with SMTP id x4-20020a1709028ec400b00156b8a6f9d8mr15905889plo.122.1649359807978; Thu, 07 Apr 2022 12:30:07 -0700 (PDT) Received: from dhcp-10-123-20-15.dhcp.broadcom.net ([192.19.234.250]) by smtp.gmail.com with ESMTPSA id o3-20020a056a0015c300b004fb24adc4b8sm23579275pfu.159.2022.04.07.12.30.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Apr 2022 12:30:07 -0700 (PDT) From: Sumit Saxena To: linux-scsi@vger.kernel.org Cc: martin.petersen@oracle.com, bvanassche@acm.org, hch@lst.de, sathya.prakash@broadcom.com, kashyap.desai@broadcom.com, chandrakanth.patil@broadcom.com, sreekanth.reddy@broadcom.com, prayas.patel@broadcom.com, Sumit Saxena Subject: [PATCH v3 6/8] mpi3mr: expose adapter state to sysfs Date: Thu, 7 Apr 2022 15:29:11 -0400 Message-Id: <20220407192913.345411-7-sumit.saxena@broadcom.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20220407192913.345411-1-sumit.saxena@broadcom.com> References: <20220407192913.345411-1-sumit.saxena@broadcom.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org Signed-off-by: Sumit Saxena --- drivers/scsi/mpi3mr/mpi3mr.h | 2 +- drivers/scsi/mpi3mr/mpi3mr_app.c | 46 ++++++++++++++++++++++++++++++++ drivers/scsi/mpi3mr/mpi3mr_os.c | 1 + 3 files changed, 48 insertions(+), 1 deletion(-) diff --git a/drivers/scsi/mpi3mr/mpi3mr.h b/drivers/scsi/mpi3mr/mpi3mr.h index 2c043e6b9d6a..c4370c5b87d8 100644 --- a/drivers/scsi/mpi3mr/mpi3mr.h +++ b/drivers/scsi/mpi3mr/mpi3mr.h @@ -1055,5 +1055,5 @@ int mpi3mr_pel_get_seqnum_post(struct mpi3mr_ioc *mrioc, struct mpi3mr_drv_cmd *drv_cmd); void mpi3mr_app_save_logdata(struct mpi3mr_ioc *mrioc, char *event_data, u16 event_data_size); - +extern const struct attribute_group *mpi3mr_host_groups[]; #endif /*MPI3MR_H_INCLUDED*/ diff --git a/drivers/scsi/mpi3mr/mpi3mr_app.c b/drivers/scsi/mpi3mr/mpi3mr_app.c index 0b9710c83065..7037ca7f8136 100644 --- a/drivers/scsi/mpi3mr/mpi3mr_app.c +++ b/drivers/scsi/mpi3mr/mpi3mr_app.c @@ -1222,3 +1222,49 @@ void mpi3mr_bsg_init(struct mpi3mr_ioc *mrioc) err_device_add: kfree(mrioc->bsg_dev); } + +/** + * adapter_state_show - SysFS callback for adapter state show + * @dev: class device + * @attr: Device attributes + * @buf: Buffer to copy + * + * Return: snprintf() return after copying adapter state + */ +static ssize_t +adp_state_show(struct device *dev, struct device_attribute *attr, + char *buf) +{ + struct Scsi_Host *shost = class_to_shost(dev); + struct mpi3mr_ioc *mrioc = shost_priv(shost); + enum mpi3mr_iocstate ioc_state; + uint8_t adp_state; + + ioc_state = mpi3mr_get_iocstate(mrioc); + if (ioc_state == MRIOC_STATE_UNRECOVERABLE) + adp_state = MPI3MR_BSG_ADPSTATE_UNRECOVERABLE; + else if ((mrioc->reset_in_progress) || (mrioc->stop_bsgs)) + adp_state = MPI3MR_BSG_ADPSTATE_IN_RESET; + else if (ioc_state == MRIOC_STATE_FAULT) + adp_state = MPI3MR_BSG_ADPSTATE_FAULT; + else + adp_state = MPI3MR_BSG_ADPSTATE_OPERATIONAL; + + return snprintf(buf, PAGE_SIZE, "%u\n", adp_state); +} + +static DEVICE_ATTR_RO(adp_state); + +static struct attribute *mpi3mr_host_attrs[] = { + &dev_attr_adp_state.attr, + NULL, +}; + +static const struct attribute_group mpi3mr_host_attr_group = { + .attrs = mpi3mr_host_attrs +}; + +const struct attribute_group *mpi3mr_host_groups[] = { + &mpi3mr_host_attr_group, + NULL, +}; diff --git a/drivers/scsi/mpi3mr/mpi3mr_os.c b/drivers/scsi/mpi3mr/mpi3mr_os.c index 19298136edb6..89a4918c4a9e 100644 --- a/drivers/scsi/mpi3mr/mpi3mr_os.c +++ b/drivers/scsi/mpi3mr/mpi3mr_os.c @@ -4134,6 +4134,7 @@ static struct scsi_host_template mpi3mr_driver_template = { .max_segment_size = 0xffffffff, .track_queue_depth = 1, .cmd_size = sizeof(struct scmd_priv), + .shost_groups = mpi3mr_host_groups, }; /**