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=-8.2 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_SANE_1 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 9DC51C3F2D1 for ; Wed, 4 Mar 2020 15:22:19 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 4CD162166E for ; Wed, 4 Mar 2020 15:22:19 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 4CD162166E Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linux.ibm.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id F0E236B0005; Wed, 4 Mar 2020 10:22:18 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id EBF0A6B0006; Wed, 4 Mar 2020 10:22:18 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DAC1C6B0007; Wed, 4 Mar 2020 10:22:18 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0133.hostedemail.com [216.40.44.133]) by kanga.kvack.org (Postfix) with ESMTP id BFD946B0005 for ; Wed, 4 Mar 2020 10:22:18 -0500 (EST) Received: from smtpin02.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 526E282499A8 for ; Wed, 4 Mar 2020 15:22:18 +0000 (UTC) X-FDA: 76558045956.02.table59_3121a5432b663 X-HE-Tag: table59_3121a5432b663 X-Filterd-Recvd-Size: 16192 Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) by imf20.hostedemail.com (Postfix) with ESMTP for ; Wed, 4 Mar 2020 15:22:17 +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 024FMEBK035660 for ; Wed, 4 Mar 2020 10:22:16 -0500 Received: from e06smtp07.uk.ibm.com (e06smtp07.uk.ibm.com [195.75.94.103]) by mx0a-001b2d01.pphosted.com with ESMTP id 2yfmg2mq6w-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Wed, 04 Mar 2020 10:22:13 -0500 Received: from localhost by e06smtp07.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Wed, 4 Mar 2020 15:22:00 -0000 Received: from b06cxnps3075.portsmouth.uk.ibm.com (9.149.109.195) by e06smtp07.uk.ibm.com (192.168.101.137) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; (version=TLSv1/SSLv3 cipher=AES256-GCM-SHA384 bits=256/256) Wed, 4 Mar 2020 15:21:53 -0000 Received: from d06av26.portsmouth.uk.ibm.com (d06av26.portsmouth.uk.ibm.com [9.149.105.62]) by b06cxnps3075.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 024FLpLC47710386 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 4 Mar 2020 15:21:51 GMT Received: from d06av26.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 805F6AE051; Wed, 4 Mar 2020 15:21:51 +0000 (GMT) Received: from d06av26.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 703C3AE045; Wed, 4 Mar 2020 15:21:50 +0000 (GMT) Received: from pic2.home (unknown [9.145.145.27]) by d06av26.portsmouth.uk.ibm.com (Postfix) with ESMTP; Wed, 4 Mar 2020 15:21:50 +0000 (GMT) Subject: Re: [PATCH v3 23/27] powerpc/powernv/pmem: Add debug IOCTLs To: "Alastair D'Silva" , alastair@d-silva.org Cc: "Aneesh Kumar K . V" , "Oliver O'Halloran" , Benjamin Herrenschmidt , Paul Mackerras , Michael Ellerman , 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_Le_Goater?= , 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 References: <20200221032720.33893-1-alastair@au1.ibm.com> <20200221032720.33893-24-alastair@au1.ibm.com> From: Frederic Barrat Date: Wed, 4 Mar 2020 16:21:50 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.4.1 MIME-Version: 1.0 In-Reply-To: <20200221032720.33893-24-alastair@au1.ibm.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US X-TM-AS-GCONF: 00 x-cbid: 20030415-0028-0000-0000-000003E0DDD3 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 20030415-0029-0000-0000-000024A60F7B Message-Id: <7e0e3b71-d70c-1dee-b630-0c33596b7223@linux.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.138,18.0.572 definitions=2020-03-04_05:2020-03-04,2020-03-04 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxlogscore=995 clxscore=1015 lowpriorityscore=0 malwarescore=0 adultscore=0 suspectscore=0 priorityscore=1501 spamscore=0 mlxscore=0 bulkscore=0 phishscore=0 impostorscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2001150001 definitions=main-2003040114 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: Le 21/02/2020 =C3=A0 04:27, Alastair D'Silva a =C3=A9crit=C2=A0: > From: Alastair D'Silva >=20 > These IOCTLs provide low level access to the card to aid in debugging > controller/FPGA firmware. >=20 > Signed-off-by: Alastair D'Silva > --- > arch/powerpc/platforms/powernv/pmem/Kconfig | 6 + > arch/powerpc/platforms/powernv/pmem/ocxl.c | 249 +++++++++++++++++++= + > include/uapi/nvdimm/ocxl-pmem.h | 32 +++ > 3 files changed, 287 insertions(+) >=20 > diff --git a/arch/powerpc/platforms/powernv/pmem/Kconfig b/arch/powerpc= /platforms/powernv/pmem/Kconfig > index c5d927520920..3f44429d70c9 100644 > --- a/arch/powerpc/platforms/powernv/pmem/Kconfig > +++ b/arch/powerpc/platforms/powernv/pmem/Kconfig > @@ -12,4 +12,10 @@ config OCXL_PMEM > =20 > Select N if unsure. > =20 > +config OCXL_PMEM_DEBUG > + bool "OpenCAPI Persistent Memory debugging" > + depends on OCXL_PMEM > + help > + Enables low level IOCTLs for OpenCAPI Persistent Memory firmware de= velopment > + > endif > diff --git a/arch/powerpc/platforms/powernv/pmem/ocxl.c b/arch/powerpc/= platforms/powernv/pmem/ocxl.c > index e01f6f9fc180..d4ce5e9e0521 100644 > --- a/arch/powerpc/platforms/powernv/pmem/ocxl.c > +++ b/arch/powerpc/platforms/powernv/pmem/ocxl.c > @@ -1050,6 +1050,235 @@ int req_controller_health_perf(struct ocxlpmem = *ocxlpmem) > GLOBAL_MMIO_HCI_REQ_HEALTH_PERF); > } > =20 > +#ifdef CONFIG_OCXL_PMEM_DEBUG > +/** > + * enable_fwdebug() - Enable FW debug on the controller > + * @ocxlpmem: the device metadata > + * Return: 0 on success, negative on failure > + */ > +static int enable_fwdebug(const struct ocxlpmem *ocxlpmem) > +{ > + return ocxl_global_mmio_set64(ocxlpmem->ocxl_afu, GLOBAL_MMIO_HCI, > + OCXL_LITTLE_ENDIAN, > + GLOBAL_MMIO_HCI_FW_DEBUG); > +} > + > +/** > + * disable_fwdebug() - Disable FW debug on the controller > + * @ocxlpmem: the device metadata > + * Return: 0 on success, negative on failure > + */ > +static int disable_fwdebug(const struct ocxlpmem *ocxlpmem) > +{ > + return ocxl_global_mmio_set64(ocxlpmem->ocxl_afu, GLOBAL_MMIO_HCIC, > + OCXL_LITTLE_ENDIAN, > + GLOBAL_MMIO_HCI_FW_DEBUG); > +} > + > +static int ioctl_fwdebug(struct ocxlpmem *ocxlpmem, > + struct ioctl_ocxl_pmem_fwdebug __user *uarg) > +{ > + struct ioctl_ocxl_pmem_fwdebug args; > + u64 val; > + int i; > + int rc; > + > + if (copy_from_user(&args, uarg, sizeof(args))) > + return -EFAULT; > + > + // Buffer size must be a multiple of 8 > + if ((args.buf_size & 0x07)) > + return -EINVAL; > + > + if (args.buf_size > ocxlpmem->admin_command.data_size) > + return -EINVAL; > + > + mutex_lock(&ocxlpmem->admin_command.lock); > + > + rc =3D enable_fwdebug(ocxlpmem); > + if (rc) > + goto out; > + > + rc =3D admin_command_request(ocxlpmem, ADMIN_COMMAND_FW_DEBUG); > + if (rc) > + goto out; > + > + // Write DebugAction & FunctionCode > + val =3D ((u64)args.debug_action << 56) | ((u64)args.function_code << = 40); > + > + rc =3D ocxl_global_mmio_write64(ocxlpmem->ocxl_afu, > + ocxlpmem->admin_command.request_offset + 0x08, > + OCXL_LITTLE_ENDIAN, val); > + if (rc) > + goto out; > + > + rc =3D ocxl_global_mmio_write64(ocxlpmem->ocxl_afu, > + ocxlpmem->admin_command.request_offset + 0x10, > + OCXL_LITTLE_ENDIAN, args.debug_parameter_1); > + if (rc) > + goto out; > + > + rc =3D ocxl_global_mmio_write64(ocxlpmem->ocxl_afu, > + ocxlpmem->admin_command.request_offset + 0x18, > + OCXL_LITTLE_ENDIAN, args.debug_parameter_2); > + if (rc) > + goto out; > + > + for (i =3D 0x20; i < 0x38; i +=3D 0x08) > + rc =3D ocxl_global_mmio_write64(ocxlpmem->ocxl_afu, > + ocxlpmem->admin_command.request_offset + i, > + OCXL_LITTLE_ENDIAN, 0); > + if (rc) > + goto out; rc is the for loop body. The rc test is not. > + > + > + // Populate admin command buffer > + if (args.buf_size) { > + for (i =3D 0; i < args.buf_size; i +=3D sizeof(u64)) { > + u64 val; > + > + if (copy_from_user(&val, &args.buf[i], sizeof(u64))) > + return -EFAULT; need to get rc and goto out because of the mutex > + > + rc =3D ocxl_global_mmio_write64(ocxlpmem->ocxl_afu, > + ocxlpmem->admin_command.data_offset + i, > + OCXL_HOST_ENDIAN, val); > + if (rc) > + goto out; > + } > + } > + > + rc =3D admin_command_execute(ocxlpmem); > + if (rc) > + goto out; > + > + rc =3D admin_command_complete_timeout(ocxlpmem, > + ocxlpmem->timeouts[ADMIN_COMMAND_FW_DEBUG]); > + if (rc < 0) > + goto out; > + > + rc =3D admin_response(ocxlpmem); > + if (rc < 0) > + goto out; > + if (rc !=3D STATUS_SUCCESS) { > + warn_status(ocxlpmem, "Unexpected status from FW Debug", rc); > + goto out; > + } > + > + if (args.buf_size) { > + for (i =3D 0; i < args.buf_size; i +=3D sizeof(u64)) { > + u64 val; > + > + rc =3D ocxl_global_mmio_read64(ocxlpmem->ocxl_afu, > + ocxlpmem->admin_command.data_offset + i, > + OCXL_HOST_ENDIAN, &val); > + if (rc) > + goto out; > + > + if (copy_to_user(&args.buf[i], &val, sizeof(u64))) { > + rc =3D -EFAULT; > + goto out; > + } > + } > + } > + > + rc =3D admin_response_handled(ocxlpmem); > + if (rc) > + goto out; > + > + rc =3D disable_fwdebug(ocxlpmem); > + if (rc) > + goto out; > + > +out: > + mutex_unlock(&ocxlpmem->admin_command.lock); > + return rc; > +} > + > +static int ioctl_shutdown(struct ocxlpmem *ocxlpmem) > +{ > + int rc; > + > + mutex_lock(&ocxlpmem->admin_command.lock); > + > + rc =3D admin_command_request(ocxlpmem, ADMIN_COMMAND_SHUTDOWN); > + if (rc) > + goto out; > + > + rc =3D admin_command_execute(ocxlpmem); > + if (rc) > + goto out; > + > + rc =3D admin_command_complete_timeout(ocxlpmem, ADMIN_COMMAND_SHUTDOW= N); > + if (rc < 0) { > + dev_warn(&ocxlpmem->dev, "Shutdown timed out\n"); > + goto out; > + } > + > + rc =3D 0; > + goto out; We can remove that goto. No admin_response_handled()? Is that shutting down the full adapter and=20 we have nobody to talk to? What happens next? > + > +out: > + mutex_unlock(&ocxlpmem->admin_command.lock); > + return rc; > +} > + > +static int ioctl_mmio_write(struct ocxlpmem *ocxlpmem, > + struct ioctl_ocxl_pmem_mmio __user *uarg) > +{ > + struct scm_ioctl_mmio args; > + > + if (copy_from_user(&args, uarg, sizeof(args))) > + return -EFAULT; > + > + return ocxl_global_mmio_write64(ocxlpmem->ocxl_afu, args.address, > + OCXL_LITTLE_ENDIAN, args.val); > +} > + > +static int ioctl_mmio_read(struct ocxlpmem *ocxlpmem, > + struct ioctl_ocxl_pmem_mmio __user *uarg) > +{ > + struct ioctl_ocxl_pmem_mmio args; > + int rc; > + > + if (copy_from_user(&args, uarg, sizeof(args))) > + return -EFAULT; > + > + rc =3D ocxl_global_mmio_read64(ocxlpmem->ocxl_afu, args.address, > + OCXL_LITTLE_ENDIAN, &args.val); > + if (rc) > + return rc; > + > + if (copy_to_user(uarg, &args, sizeof(args))) > + return -EFAULT; > + > + return 0; > +} > +#else /* CONFIG_OCXL_PMEM_DEBUG */ > +static int ioctl_fwdebug(struct ocxlpmem *ocxlpmem, > + struct ioctl_ocxl_pmem_fwdebug __user *uarg) > +{ > + return -EPERM; > +} > + > +static int ioctl_shutdown(struct ocxlpmem *ocxlpmem) > +{ > + return -EPERM; > +} > + > +static int ioctl_mmio_write(struct ocxlpmem *ocxlpmem, > + struct ioctl_ocxl_pmem_mmio __user *uarg) > +{ > + return -EPERM; > +} > + > +static int ioctl_mmio_read(struct ocxlpmem *ocxlpmem, > + struct ioctl_ocxl_pmem_mmio __user *uarg) > +{ > + return -EPERM; > +} The 'else' clause could be dropped, the ioctls will return EINVAL, which=20 is fine, I think. > +#endif /* CONFIG_OCXL_PMEM_DEBUG */ > + > static long file_ioctl(struct file *file, unsigned int cmd, unsigned = long args) > { > struct ocxlpmem *ocxlpmem =3D file->private_data; > @@ -1091,6 +1320,26 @@ static long file_ioctl(struct file *file, unsign= ed int cmd, unsigned long args) > case IOCTL_OCXL_PMEM_REQUEST_HEALTH: > rc =3D req_controller_health_perf(ocxlpmem); > break; > + > + case IOCTL_OCXL_PMEM_FWDEBUG: > + rc =3D ioctl_fwdebug(ocxlpmem, > + (struct ioctl_ocxl_pmem_fwdebug __user *)args); > + break; > + > + case IOCTL_OCXL_PMEM_SHUTDOWN: > + rc =3D ioctl_shutdown(ocxlpmem); > + break; > + > + case IOCTL_OCXL_PMEM_MMIO_WRITE: > + rc =3D ioctl_mmio_write(ocxlpmem, > + (struct ioctl_ocxl_pmem_mmio __user *)args); > + break; > + > + case IOCTL_OCXL_PMEM_MMIO_READ: > + rc =3D ioctl_mmio_read(ocxlpmem, > + (struct ioctl_ocxl_pmem_mmio __user *)args); > + break; > + > } > =20 > return rc; > diff --git a/include/uapi/nvdimm/ocxl-pmem.h b/include/uapi/nvdimm/ocxl= -pmem.h > index 0d03abb44001..e20a4f8be82a 100644 > --- a/include/uapi/nvdimm/ocxl-pmem.h > +++ b/include/uapi/nvdimm/ocxl-pmem.h > @@ -6,6 +6,28 @@ > #include > #include > =20 > +enum ocxlpmem_fwdebug_action { > + OCXL_PMEM_FWDEBUG_READ_CONTROLLER_MEMORY =3D 0x01, > + OCXL_PMEM_FWDEBUG_WRITE_CONTROLLER_MEMORY =3D 0x02, > + OCXL_PMEM_FWDEBUG_ENABLE_FUNCTION =3D 0x03, > + OCXL_PMEM_FWDEBUG_DISABLE_FUNCTION =3D 0x04, > + OCXL_PMEM_FWDEBUG_GET_PEL =3D 0x05, // Retrieve Persistent Error Log > +}; > + > +struct ioctl_ocxl_pmem_buffer_info { > + __u32 admin_command_buffer_size; // out > + __u32 near_storage_buffer_size; // out > +}; > + > +struct ioctl_ocxl_pmem_fwdebug { // All args are inputs > + enum ocxlpmem_fwdebug_action debug_action; More kernel ABI problems. My interpretation of the "enumeration=20 specifiers" section of C99 is that we can't rely on the size of the enum. > + __u16 function_code; > + __u16 buf_size; // Size of optional data buffer > + __u64 debug_parameter_1; > + __u64 debug_parameter_2; > + __u8 *buf; // Pointer to optional in/out data buffer > +}; > + > #define OCXL_PMEM_ERROR_LOG_ACTION_RESET (1 << (32-32)) > #define OCXL_PMEM_ERROR_LOG_ACTION_CHKFW (1 << (53-32)) > #define OCXL_PMEM_ERROR_LOG_ACTION_REPLACE (1 << (54-32)) > @@ -66,6 +88,11 @@ struct ioctl_ocxl_pmem_controller_stats { > __u64 cache_write_latency; /* nanoseconds */ > }; > =20 > +struct ioctl_ocxl_pmem_mmio { > + __u64 address; /* Offset in global MMIO space */ > + __u64 val; /* value to write/was read */ > +}; Can we group all the debug data structures together in the header file,=20 with a comment indicating that they may not be available in the kernel,=20 depending on the config? Fred > + > struct ioctl_ocxl_pmem_eventfd { > __s32 eventfd; > __u32 reserved; > @@ -92,4 +119,9 @@ struct ioctl_ocxl_pmem_eventfd { > #define IOCTL_OCXL_PMEM_EVENT_CHECK _IOR(OCXL_PMEM_MAGIC, 0x07, __u= 64) > #define IOCTL_OCXL_PMEM_REQUEST_HEALTH _IO(OCXL_PMEM_MAGIC, 0x08) > =20 > +#define IOCTL_OCXL_PMEM_FWDEBUG _IOWR(OCXL_PMEM_MAGIC, 0xf0, struct i= octl_ocxl_pmem_fwdebug) > +#define IOCTL_OCXL_PMEM_MMIO_WRITE _IOW(OCXL_PMEM_MAGIC, 0xf1, struct = ioctl_ocxl_pmem_mmio) > +#define IOCTL_OCXL_PMEM_MMIO_READ _IOWR(OCXL_PMEM_MAGIC, 0xf2, struct = ioctl_ocxl_pmem_mmio) > +#define IOCTL_OCXL_PMEM_SHUTDOWN _IO(OCXL_PMEM_MAGIC, 0xf3) > + > #endif /* _UAPI_OCXL_SCM_H */ >=20