From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 74835C11D00 for ; Fri, 21 Feb 2020 03:38:17 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 250AE208C4 for ; Fri, 21 Feb 2020 03:38:17 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 250AE208C4 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=au1.ibm.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id AFB756B009B; Thu, 20 Feb 2020 22:38:16 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id AABD66B009F; Thu, 20 Feb 2020 22:38:16 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 99A5C6B00A0; Thu, 20 Feb 2020 22:38:16 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0241.hostedemail.com [216.40.44.241]) by kanga.kvack.org (Postfix) with ESMTP id 7FF1A6B009B for ; Thu, 20 Feb 2020 22:38:16 -0500 (EST) Received: from smtpin25.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 53382181AEF1F for ; Fri, 21 Feb 2020 03:38:16 +0000 (UTC) X-FDA: 76512726192.25.wood42_2b0953ef24b62 X-HE-Tag: wood42_2b0953ef24b62 X-Filterd-Recvd-Size: 15291 Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) by imf28.hostedemail.com (Postfix) with ESMTP for ; Fri, 21 Feb 2020 03:38:15 +0000 (UTC) Received: from pps.filterd (m0187473.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 01L3JKFM021297 for ; Thu, 20 Feb 2020 22:28:23 -0500 Received: from e06smtp03.uk.ibm.com (e06smtp03.uk.ibm.com [195.75.94.99]) by mx0a-001b2d01.pphosted.com with ESMTP id 2y8ucnrcf4-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Thu, 20 Feb 2020 22:28:22 -0500 Received: from localhost by e06smtp03.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Fri, 21 Feb 2020 03:28:17 -0000 Received: from b06cxnps4075.portsmouth.uk.ibm.com (9.149.109.197) by e06smtp03.uk.ibm.com (192.168.101.133) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; (version=TLSv1/SSLv3 cipher=AES256-GCM-SHA384 bits=256/256) Fri, 21 Feb 2020 03:28:10 -0000 Received: from b06wcsmtp001.portsmouth.uk.ibm.com (b06wcsmtp001.portsmouth.uk.ibm.com [9.149.105.160]) by b06cxnps4075.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 01L3S9V659506906 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 21 Feb 2020 03:28:09 GMT Received: from b06wcsmtp001.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id C8BD5A405C; Fri, 21 Feb 2020 03:28:09 +0000 (GMT) Received: from b06wcsmtp001.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 2E7F9A4065; Fri, 21 Feb 2020 03:28:09 +0000 (GMT) Received: from ozlabs.au.ibm.com (unknown [9.192.253.14]) by b06wcsmtp001.portsmouth.uk.ibm.com (Postfix) with ESMTP; Fri, 21 Feb 2020 03:28:09 +0000 (GMT) Received: from adsilva.ozlabs.ibm.com (haven.au.ibm.com [9.192.254.114]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.au.ibm.com (Postfix) with ESMTPSA id 605ACA03D2; Fri, 21 Feb 2020 14:28:03 +1100 (AEDT) From: "Alastair D'Silva" To: alastair@d-silva.org Cc: "Aneesh Kumar K . V" , "Oliver O'Halloran" , Benjamin Herrenschmidt , Paul Mackerras , Michael Ellerman , Frederic Barrat , Andrew Donnellan , Arnd Bergmann , Greg Kroah-Hartman , Dan Williams , Vishal Verma , Dave Jiang , Ira Weiny , Andrew Morton , Mauro Carvalho Chehab , "David S. Miller" , Rob Herring , Anton Blanchard , Krzysztof Kozlowski , Mahesh Salgaonkar , Madhavan Srinivasan , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , Anju T Sudhakar , Hari Bathini , Thomas Gleixner , Greg Kurz , Nicholas Piggin , Masahiro Yamada , Alexey Kardashevskiy , linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-nvdimm@lists.01.org, linux-mm@kvack.org Subject: [PATCH v3 14/27] powerpc/powernv/pmem: Add support for Admin commands Date: Fri, 21 Feb 2020 14:27:07 +1100 X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200221032720.33893-1-alastair@au1.ibm.com> References: <20200221032720.33893-1-alastair@au1.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 x-cbid: 20022103-0012-0000-0000-00000388D1CC X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 20022103-0013-0000-0000-000021C56A6F Message-Id: <20200221032720.33893-15-alastair@au1.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.138,18.0.572 definitions=2020-02-20_19:2020-02-19,2020-02-20 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 malwarescore=0 adultscore=0 impostorscore=0 spamscore=0 phishscore=0 mlxlogscore=999 priorityscore=1501 clxscore=1015 suspectscore=1 bulkscore=0 mlxscore=0 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2001150001 definitions=main-2002210020 Content-Transfer-Encoding: quoted-printable X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: From: Alastair D'Silva This patch requests the metadata required to issue admin commands, as wel= l as some helper functions to construct and check the completion of the commands. Signed-off-by: Alastair D'Silva --- arch/powerpc/platforms/powernv/pmem/ocxl.c | 65 ++++++++ .../platforms/powernv/pmem/ocxl_internal.c | 153 ++++++++++++++++++ .../platforms/powernv/pmem/ocxl_internal.h | 61 +++++++ 3 files changed, 279 insertions(+) diff --git a/arch/powerpc/platforms/powernv/pmem/ocxl.c b/arch/powerpc/pl= atforms/powernv/pmem/ocxl.c index 431212c9f0cc..4e782d22605b 100644 --- a/arch/powerpc/platforms/powernv/pmem/ocxl.c +++ b/arch/powerpc/platforms/powernv/pmem/ocxl.c @@ -216,6 +216,58 @@ static int register_lpc_mem(struct ocxlpmem *ocxlpme= m) return 0; } =20 +/** + * extract_command_metadata() - Extract command data from MMIO & save it= for further use + * @ocxlpmem: the device metadata + * @offset: The base address of the command data structures (address of = CREQO) + * @command_metadata: A pointer to the command metadata to populate + * Return: 0 on success, negative on failure + */ +static int extract_command_metadata(struct ocxlpmem *ocxlpmem, u32 offse= t, + struct command_metadata *command_metadata) +{ + int rc; + u64 tmp; + + rc =3D ocxl_global_mmio_read64(ocxlpmem->ocxl_afu, offset, OCXL_LITTLE_= ENDIAN, + &tmp); + if (rc) + return rc; + + command_metadata->request_offset =3D tmp >> 32; + command_metadata->response_offset =3D tmp & 0xFFFFFFFF; + + rc =3D ocxl_global_mmio_read64(ocxlpmem->ocxl_afu, offset + 8, OCXL_LIT= TLE_ENDIAN, + &tmp); + if (rc) + return rc; + + command_metadata->data_offset =3D tmp >> 32; + command_metadata->data_size =3D tmp & 0xFFFFFFFF; + + command_metadata->id =3D 0; + + return 0; +} + +/** + * setup_command_metadata() - Set up the command metadata + * @ocxlpmem: the device metadata + */ +static int setup_command_metadata(struct ocxlpmem *ocxlpmem) +{ + int rc; + + mutex_init(&ocxlpmem->admin_command.lock); + + rc =3D extract_command_metadata(ocxlpmem, GLOBAL_MMIO_ACMA_CREQO, + &ocxlpmem->admin_command); + if (rc) + return rc; + + return 0; +} + /** * is_usable() - Is a controller usable? * @ocxlpmem: the device metadata @@ -456,6 +508,14 @@ static int probe(struct pci_dev *pdev, const struct = pci_device_id *ent) } ocxlpmem->pdev =3D pdev; =20 + ocxlpmem->timeouts[ADMIN_COMMAND_ERRLOG] =3D 2000; // ms + ocxlpmem->timeouts[ADMIN_COMMAND_HEARTBEAT] =3D 100; // ms + ocxlpmem->timeouts[ADMIN_COMMAND_SMART] =3D 100; // ms + ocxlpmem->timeouts[ADMIN_COMMAND_CONTROLLER_DUMP] =3D 1000; // ms + ocxlpmem->timeouts[ADMIN_COMMAND_CONTROLLER_STATS] =3D 100; // ms + ocxlpmem->timeouts[ADMIN_COMMAND_SHUTDOWN] =3D 1000; // ms + ocxlpmem->timeouts[ADMIN_COMMAND_FW_UPDATE] =3D 16000; // ms + pci_set_drvdata(pdev, ocxlpmem); =20 ocxlpmem->ocxl_fn =3D ocxl_function_open(pdev); @@ -501,6 +561,11 @@ static int probe(struct pci_dev *pdev, const struct = pci_device_id *ent) goto err; } =20 + if (setup_command_metadata(ocxlpmem)) { + dev_err(&pdev->dev, "Could not read OCXL command matada\n"); + goto err; + } + elapsed =3D 0; timeout =3D ocxlpmem->readiness_timeout + ocxlpmem->memory_available_ti= meout; while (!is_usable(ocxlpmem, false)) { diff --git a/arch/powerpc/platforms/powernv/pmem/ocxl_internal.c b/arch/p= owerpc/platforms/powernv/pmem/ocxl_internal.c index 617ca943b1b8..583f48023025 100644 --- a/arch/powerpc/platforms/powernv/pmem/ocxl_internal.c +++ b/arch/powerpc/platforms/powernv/pmem/ocxl_internal.c @@ -17,3 +17,156 @@ int ocxlpmem_chi(const struct ocxlpmem *ocxlpmem, u64= *chi) =20 return 0; } + +#define COMMAND_REQUEST_SIZE (8 * sizeof(u64)) +static int scm_command_request(const struct ocxlpmem *ocxlpmem, + struct command_metadata *cmd, u8 op_code) +{ + u64 val =3D op_code; + int rc; + u8 i; + + cmd->op_code =3D op_code; + cmd->id++; + + val |=3D ((u64)cmd->id) << 16; + + rc =3D ocxl_global_mmio_write64(ocxlpmem->ocxl_afu, cmd->request_offset= , + OCXL_LITTLE_ENDIAN, val); + if (rc) + return rc; + + for (i =3D sizeof(u64); i < COMMAND_REQUEST_SIZE; i +=3D sizeof(u64)) { + rc =3D ocxl_global_mmio_write64(ocxlpmem->ocxl_afu, + cmd->request_offset + i, + OCXL_LITTLE_ENDIAN, 0); + if (rc) + return rc; + } + + return 0; +} + +int admin_command_request(struct ocxlpmem *ocxlpmem, u8 op_code) +{ + u64 val; + int rc =3D ocxl_global_mmio_read64(ocxlpmem->ocxl_afu, GLOBAL_MMIO_CHI, + OCXL_LITTLE_ENDIAN, &val); + if (rc) + return rc; + + return scm_command_request(ocxlpmem, &ocxlpmem->admin_command, op_code)= ; +} + +static int command_response(const struct ocxlpmem *ocxlpmem, + const struct command_metadata *cmd) +{ + u64 val; + u16 id; + u8 status; + int rc =3D ocxl_global_mmio_read64(ocxlpmem->ocxl_afu, + cmd->response_offset, + OCXL_LITTLE_ENDIAN, &val); + if (rc) + return rc; + + status =3D val & 0xff; + id =3D (val >> 16) & 0xffff; + + if (id !=3D cmd->id) { + dev_warn(&ocxlpmem->dev, + "Expected response for command %d, but received response for command= %d instead.\n", + cmd->id, id); + } + + return status; +} + +int admin_response(const struct ocxlpmem *ocxlpmem) +{ + return command_response(ocxlpmem, &ocxlpmem->admin_command); +} + + +int admin_command_execute(const struct ocxlpmem *ocxlpmem) +{ + return ocxl_global_mmio_set64(ocxlpmem->ocxl_afu, GLOBAL_MMIO_HCI, + OCXL_LITTLE_ENDIAN, GLOBAL_MMIO_HCI_ACRW); +} + +static bool admin_command_complete(const struct ocxlpmem *ocxlpmem) +{ + u64 val =3D 0; + + int rc =3D ocxlpmem_chi(ocxlpmem, &val); + + WARN_ON(rc); + + return (val & GLOBAL_MMIO_CHI_ACRA) !=3D 0; +} + +int admin_command_complete_timeout(const struct ocxlpmem *ocxlpmem, + int command) +{ + u32 timeout =3D ocxlpmem->timeouts[command]; + // 32 is the next power of 2 greater than the 20ms minimum for msleep +#define TIMEOUT_SLEEP_MILLIS 32 + timeout /=3D TIMEOUT_SLEEP_MILLIS; + if (!timeout) + timeout =3D DEFAULT_TIMEOUT / TIMEOUT_SLEEP_MILLIS; + + while (timeout-- > 0) { + if (admin_command_complete(ocxlpmem)) + return 0; + msleep(TIMEOUT_SLEEP_MILLIS); + } + + if (admin_command_complete(ocxlpmem)) + return 0; + + return -EBUSY; +} + +int admin_response_handled(const struct ocxlpmem *ocxlpmem) +{ + return ocxl_global_mmio_set64(ocxlpmem->ocxl_afu, GLOBAL_MMIO_CHIC, + OCXL_LITTLE_ENDIAN, GLOBAL_MMIO_CHI_ACRA); +} + +void warn_status(const struct ocxlpmem *ocxlpmem, const char *message, + u8 status) +{ + const char *text =3D "Unknown"; + + switch (status) { + case STATUS_SUCCESS: + text =3D "Success"; + break; + + case STATUS_MEM_UNAVAILABLE: + text =3D "Persistent memory unavailable"; + break; + + case STATUS_BAD_OPCODE: + text =3D "Bad opcode"; + break; + + case STATUS_BAD_REQUEST_PARM: + text =3D "Bad request parameter"; + break; + + case STATUS_BAD_DATA_PARM: + text =3D "Bad data parameter"; + break; + + case STATUS_DEBUG_BLOCKED: + text =3D "Debug action blocked"; + break; + + case STATUS_FAIL: + text =3D "Failed"; + break; + } + + dev_warn(&ocxlpmem->dev, "%s: %s (%x)\n", message, text, status); +} diff --git a/arch/powerpc/platforms/powernv/pmem/ocxl_internal.h b/arch/p= owerpc/platforms/powernv/pmem/ocxl_internal.h index ba0301533d00..2fef68c71271 100644 --- a/arch/powerpc/platforms/powernv/pmem/ocxl_internal.h +++ b/arch/powerpc/platforms/powernv/pmem/ocxl_internal.h @@ -7,6 +7,7 @@ #include =20 #define LABEL_AREA_SIZE (1UL << PA_SECTION_SHIFT) +#define DEFAULT_TIMEOUT 100 =20 #define GLOBAL_MMIO_CHI 0x000 #define GLOBAL_MMIO_CHIC 0x008 @@ -80,6 +81,16 @@ #define STATUS_FW_ARG_INVALID 0x51 #define STATUS_FW_INVALID 0x52 =20 +struct command_metadata { + u32 request_offset; + u32 response_offset; + u32 data_offset; + u32 data_size; + struct mutex lock; + u16 id; + u8 op_code; +}; + struct ocxlpmem_function0 { struct pci_dev *pdev; struct ocxl_fn *ocxl_fn; @@ -95,9 +106,11 @@ struct ocxlpmem { struct ocxl_afu *ocxl_afu; struct ocxl_context *ocxl_context; void *metadata_addr; + struct command_metadata admin_command; struct resource pmem_res; struct nd_region *nd_region; char fw_version[8+1]; + u32 timeouts[ADMIN_COMMAND_MAX+1]; =20 u32 max_controller_dump_size; u16 scm_revision; // major/minor @@ -122,3 +135,51 @@ struct ocxlpmem { * Returns 0 on success, negative on error */ int ocxlpmem_chi(const struct ocxlpmem *ocxlpmem, u64 *chi); + +/** + * admin_command_request() - Issue an admin command request + * @ocxlpmem: the device metadata + * @op_code: The op-code for the command + * + * Returns an identifier for the command, or negative on error + */ +int admin_command_request(struct ocxlpmem *ocxlpmem, u8 op_code); + +/** + * admin_response() - Validate an admin response + * @ocxlpmem: the device metadata + * Returns the status code of the command, or negative on error + */ +int admin_response(const struct ocxlpmem *ocxlpmem); + +/** + * admin_command_execute() - Notify the controller to start processing a= pending admin command + * @ocxlpmem: the device metadata + * Returns 0 on success, negative on error + */ +int admin_command_execute(const struct ocxlpmem *ocxlpmem); + +/** + * admin_command_complete_timeout() - Wait for an admin command to finis= h executing + * @ocxlpmem: the device metadata + * @command: the admin command to wait for completion (determines the ti= meout) + * Returns 0 on success, -EBUSY on timeout + */ +int admin_command_complete_timeout(const struct ocxlpmem *ocxlpmem, + int command); + +/** + * admin_response_handled() - Notify the controller that the admin respo= nse has been handled + * @ocxlpmem: the device metadata + * Returns 0 on success, negative on failure + */ +int admin_response_handled(const struct ocxlpmem *ocxlpmem); + +/** + * warn_status() - Emit a kernel warning showing a command status. + * @ocxlpmem: the device metadata + * @message: A message to accompany the warning + * @status: The command status + */ +void warn_status(const struct ocxlpmem *ocxlpmem, const char *message, + u8 status); --=20 2.24.1