From patchwork Thu Jun 18 07:01:03 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vaibhav Jain X-Patchwork-Id: 11611479 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 DBCA814E3 for ; Thu, 18 Jun 2020 07:01:43 +0000 (UTC) Received: from ml01.01.org (ml01.01.org [198.145.21.10]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id C4D4820884 for ; Thu, 18 Jun 2020 07:01:43 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org C4D4820884 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linux.ibm.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-nvdimm-bounces@lists.01.org Received: from ml01.vlan13.01.org (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 7FFC310FC4F7E; Thu, 18 Jun 2020 00:01:43 -0700 (PDT) Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=148.163.156.1; helo=mx0a-001b2d01.pphosted.com; envelope-from=vaibhav@linux.ibm.com; receiver= Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 3525E10FC4F7D for ; Thu, 18 Jun 2020 00:01:41 -0700 (PDT) Received: from pps.filterd (m0098409.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 05I6WB0I186995; Thu, 18 Jun 2020 03:01:39 -0400 Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com with ESMTP id 31qy9j6trn-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 18 Jun 2020 03:01:39 -0400 Received: from m0098409.ppops.net (m0098409.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.36/8.16.0.36) with SMTP id 05I6WTdo188721; Thu, 18 Jun 2020 03:01:39 -0400 Received: from ppma03fra.de.ibm.com (6b.4a.5195.ip4.static.sl-reverse.com [149.81.74.107]) by mx0a-001b2d01.pphosted.com with ESMTP id 31qy9j6tq3-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 18 Jun 2020 03:01:38 -0400 Received: from pps.filterd (ppma03fra.de.ibm.com [127.0.0.1]) by ppma03fra.de.ibm.com (8.16.0.42/8.16.0.42) with SMTP id 05I70t7x005226; Thu, 18 Jun 2020 07:01:36 GMT Received: from b06cxnps4074.portsmouth.uk.ibm.com (d06relay11.portsmouth.uk.ibm.com [9.149.109.196]) by ppma03fra.de.ibm.com with ESMTP id 31r0u9g2rg-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 18 Jun 2020 07:01:36 +0000 Received: from d06av25.portsmouth.uk.ibm.com (d06av25.portsmouth.uk.ibm.com [9.149.105.61]) by b06cxnps4074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 05I71Wgg11993320 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 18 Jun 2020 07:01:32 GMT Received: from d06av25.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 8D2FA11C05C; Thu, 18 Jun 2020 07:01:32 +0000 (GMT) Received: from d06av25.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 9D8B811C04C; Thu, 18 Jun 2020 07:01:28 +0000 (GMT) Received: from vajain21-in-ibm-com (unknown [9.85.105.7]) by d06av25.portsmouth.uk.ibm.com (Postfix) with SMTP; Thu, 18 Jun 2020 07:01:28 +0000 (GMT) Received: by vajain21-in-ibm-com (sSMTP sendmail emulation); Thu, 18 Jun 2020 12:31:27 +0530 From: Vaibhav Jain To: linux-nvdimm@lists.01.org Subject: [ndctl PATCH v7 4/5] papr: Add scaffolding to issue and handle PDSM requests Date: Thu, 18 Jun 2020 12:31:03 +0530 Message-Id: <20200618070104.239446-5-vaibhav@linux.ibm.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200618070104.239446-1-vaibhav@linux.ibm.com> References: <20200618070104.239446-1-vaibhav@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.216,18.0.687 definitions=2020-06-18_03:2020-06-17,2020-06-18 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxlogscore=999 clxscore=1015 cotscore=-2147483648 suspectscore=1 phishscore=0 spamscore=0 bulkscore=0 lowpriorityscore=0 priorityscore=1501 adultscore=0 mlxscore=0 impostorscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2004280000 definitions=main-2006180046 Message-ID-Hash: FF7O7NXLOXE7FH3NHHOTDWBB4D2KXD73 X-Message-ID-Hash: FF7O7NXLOXE7FH3NHHOTDWBB4D2KXD73 X-MailFrom: vaibhav@linux.ibm.com X-Mailman-Rule-Hits: nonmember-moderation X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation CC: Vaibhav Jain , "Aneesh Kumar K . V" X-Mailman-Version: 3.1.1 Precedence: list List-Id: "Linux-nvdimm developer list." Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: This patch implement necessary infrastructure inside 'papr.c' to issue and handle PDSM requests. Changes implemented are: * New helper function allocate_cmd() to allocate command packages for a specific PDSM command and payload size. * Provide a skeleton implementation of 'dimm_ops->smart_get_flags' to check the submitted command for any errors. Presently no flags are returned from this callback and future patch will update this callback function to check submitted ndctl_cmd instance and return appropriate flags. * cmd_is_valid() to validate submitted 'struct ndctl_cmd' instance for correct command family and PDSM command id. * Implement callbacks for 'dimm_ops->get_firmware_status' and 'dimm_ops->get_xlat_firmware_status' to return translated firmware command status from 'struct ndctl_cmd'. * Logging helpers for papr_scm that use the underlying libndctl provided logging. Signed-off-by: Vaibhav Jain --- Changelog: v6..v7: * None v5..v6: * Reworked the patch based on recent changes introduced for layout changes to 'struct nd_cmd_pkg'. * Removed function update_dimm_stats() and papr_dimm_init/uninit() as they depended on an now a defunct patch "libndctl: Introduce new dimm-ops dimm_init() & dimm_uninit()" * Introduced various helper macros to_pdsm(), to_ndcmd(), to_payload() and to_pdsm_cmd(). v4..v5: * Updated papr_dbg/err macros to remove the 'scm' suffix. * s/NVDIMM_FAMILY_PAPR_SCM/NVDIMM_FAMILY_PAPR/g * s/PAPR_SCM_PDSM_*/PAPR_PDSM_*/g * Minor changes to various comments and patch-description to remove usage of term 'scm'. v3..v4: * Remove the initialization of 'nd_pdsm_cmd_pkg.payload_offset' field from allocate_cmd(). [ Aneesh ] v2..v3: * None v1..v2: * Added new dimm callback 'papr_get_firmware_status' * Switched to new papr_scm interface as described by papr_scm_dsm.h * Changed the case of logging functions [ Santosh Sivaraj ] * Removed redundant logging functions. * Minor updates to patch description to s/DSM/PDSM/ --- ndctl/lib/papr.c | 124 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 124 insertions(+) diff --git a/ndctl/lib/papr.c b/ndctl/lib/papr.c index 42372c3e2f7f..ebf31bac9a23 100644 --- a/ndctl/lib/papr.c +++ b/ndctl/lib/papr.c @@ -15,6 +15,29 @@ #include #include "papr.h" +/* Utility logging maros for simplify logging */ +#define papr_dbg(_dimm, _format_str, ...) dbg(_dimm->bus->ctx, \ + "%s:" _format_str, \ + ndctl_dimm_get_devname(_dimm), \ + ##__VA_ARGS__) + +#define papr_err(_dimm, _format_str, ...) err(_dimm->bus->ctx, \ + "%s:" _format_str, \ + ndctl_dimm_get_devname(_dimm), \ + ##__VA_ARGS__) + +/* Convert a ndctl_cmd to pdsm package */ +#define to_pdsm(C) (&(C)->papr[0].pdsm) + +/* Convert a ndctl_cmd to nd_cmd_pkg */ +#define to_ndcmd(C) (&(C)->papr[0].gen) + +/* Return payload from a ndctl_cmd */ +#define to_payload(C) (&(C)->papr[0].pdsm.payload) + +/* return the pdsm command */ +#define to_pdsm_cmd(C) ((enum papr_pdsm)to_ndcmd(C)->nd_command) + static bool papr_cmd_is_supported(struct ndctl_dimm *dimm, int cmd) { /* Handle this separately to support monitor mode */ @@ -24,6 +47,107 @@ static bool papr_cmd_is_supported(struct ndctl_dimm *dimm, int cmd) return !!(dimm->cmd_mask & (1ULL << cmd)); } +static u32 papr_get_firmware_status(struct ndctl_cmd *cmd) +{ + const struct nd_pkg_pdsm *pcmd = to_pdsm(cmd); + + return (u32) pcmd->cmd_status; +} + +static int papr_xlat_firmware_status(struct ndctl_cmd *cmd) +{ + const struct nd_pkg_pdsm *pcmd = to_pdsm(cmd); + + return pcmd->cmd_status; +} + +/* Verify if the given command is supported and valid */ +static bool cmd_is_valid(struct ndctl_cmd *cmd) +{ + const struct nd_cmd_pkg *ncmd = NULL; + + if (cmd == NULL) + return false; + + ncmd = to_ndcmd(cmd); + + /* Verify the command family */ + if (ncmd->nd_family != NVDIMM_FAMILY_PAPR) { + papr_err(cmd->dimm, "Invalid command family:0x%016llx\n", + ncmd->nd_family); + return false; + } + + /* Verify the PDSM */ + if (ncmd->nd_command <= PAPR_PDSM_MIN || + ncmd->nd_command >= PAPR_PDSM_MAX) { + papr_err(cmd->dimm, "Invalid command :0x%016llx\n", + ncmd->nd_command); + return false; + } + + return true; +} + +/* Allocate a struct ndctl_cmd for given pdsm request with payload size */ +static struct ndctl_cmd *allocate_cmd(struct ndctl_dimm *dimm, + enum papr_pdsm pdsm_cmd, + size_t payload_size) +{ + struct ndctl_cmd *cmd; + + /* Verify that payload size is within acceptable range */ + if (payload_size > ND_PDSM_PAYLOAD_MAX_SIZE) { + papr_err(dimm, "Requested payload size too large %lu bytes\n", + payload_size); + return NULL; + } + + cmd = calloc(1, sizeof(struct ndctl_cmd) + sizeof(struct nd_pkg_papr)); + if (!cmd) + return NULL; + + ndctl_cmd_ref(cmd); + cmd->dimm = dimm; + cmd->type = ND_CMD_CALL; + cmd->status = 0; + cmd->get_firmware_status = &papr_get_firmware_status; + + /* Populate the nd_cmd_pkg contained in nd_pkg_pdsm */ + *to_ndcmd(cmd) = (struct nd_cmd_pkg) { + .nd_family = NVDIMM_FAMILY_PAPR, + .nd_command = pdsm_cmd, + .nd_size_in = 0, + .nd_size_out = ND_PDSM_HDR_SIZE + payload_size, + .nd_fw_size = 0, + }; + return cmd; +} + +/* Validate the ndctl_cmd and return applicable flags */ +static unsigned int papr_smart_get_flags(struct ndctl_cmd *cmd) +{ + struct nd_pkg_pdsm *pcmd; + + if (!cmd_is_valid(cmd)) + return 0; + + pcmd = to_pdsm(cmd); + /* If error reported then return empty flags */ + if (pcmd->cmd_status) { + papr_err(cmd->dimm, "PDSM(0x%x) reported error:%d\n", + to_pdsm_cmd(cmd), pcmd->cmd_status); + return 0; + } + + /* return empty flags for now */ + return 0; +} + + struct ndctl_dimm_ops * const papr_dimm_ops = &(struct ndctl_dimm_ops) { .cmd_is_supported = papr_cmd_is_supported, + .smart_get_flags = papr_smart_get_flags, + .get_firmware_status = papr_get_firmware_status, + .xlat_firmware_status = papr_xlat_firmware_status, };