From patchwork Wed Dec 20 17:27:24 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Lombard X-Patchwork-Id: 851584 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3z22C65CHKz9sNr for ; Thu, 21 Dec 2017 04:41:54 +1100 (AEDT) Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 3z22C600rWzF0FX for ; Thu, 21 Dec 2017 04:41:54 +1100 (AEDT) X-Original-To: linuxppc-dev@lists.ozlabs.org Delivered-To: linuxppc-dev@lists.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=linux.vnet.ibm.com (client-ip=148.163.158.5; helo=mx0a-001b2d01.pphosted.com; envelope-from=clombard@linux.vnet.ibm.com; receiver=) Received: from mx0a-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 3z21tY1qmczDwNN for ; Thu, 21 Dec 2017 04:27:33 +1100 (AEDT) Received: from pps.filterd (m0098420.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.21/8.16.0.21) with SMTP id vBKHPfZd033119 for ; Wed, 20 Dec 2017 12:27:30 -0500 Received: from e06smtp15.uk.ibm.com (e06smtp15.uk.ibm.com [195.75.94.111]) by mx0b-001b2d01.pphosted.com with ESMTP id 2eyt3tnsnb-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Wed, 20 Dec 2017 12:27:29 -0500 Received: from localhost by e06smtp15.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Wed, 20 Dec 2017 17:27:28 -0000 Received: from b06cxnps3075.portsmouth.uk.ibm.com (9.149.109.195) by e06smtp15.uk.ibm.com (192.168.101.145) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Wed, 20 Dec 2017 17:27:26 -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 vBKHRQpY65667150; Wed, 20 Dec 2017 17:27:26 GMT Received: from d06av26.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 02ED5AE04D; Wed, 20 Dec 2017 17:20:00 +0000 (GMT) Received: from d06av26.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 21A1EAE045; Wed, 20 Dec 2017 17:19:59 +0000 (GMT) Received: from lombard-w520.ibm.com (unknown [9.164.187.104]) by d06av26.portsmouth.uk.ibm.com (Postfix) with ESMTP; Wed, 20 Dec 2017 17:19:58 +0000 (GMT) From: Christophe Lombard To: linuxppc-dev@lists.ozlabs.org, fbarrat@linux.vnet.ibm.com, vaibhav@linux.vnet.ibm.com, andrew.donnellan@au1.ibm.com Subject: [PATCH V5] cxl: Add support for ASB_Notify on POWER9 Date: Wed, 20 Dec 2017 18:27:24 +0100 X-Mailer: git-send-email 2.7.4 X-TM-AS-GCONF: 00 x-cbid: 17122017-0020-0000-0000-000003E20845 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17122017-0021-0000-0000-000042732141 Message-Id: <1513790844-27779-1-git-send-email-clombard@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-12-20_07:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=0 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 impostorscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1709140000 definitions=main-1712200248 X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.24 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: linuxppc-dev-bounces+patchwork-incoming=ozlabs.org@lists.ozlabs.org Sender: "Linuxppc-dev" The POWER9 core supports a new feature: ASB_Notify which requires the support of the Special Purpose Register: TIDR. The ASB_Notify command, generated by the AFU, will attempt to wake-up the host thread identified by the particular LPID:PID:TID. This patch assign a unique TIDR (thread id) for the current thread which will be used in the process element entry. A next patch will handle a new kind of "compatible" property in the device-tree (PHB DT node) indicating which version of CAPI and which features are supported, instead of handling PVR values. Signed-off-by: Christophe Lombard Reviewed-by: Philippe Bergheaud --- Changelog[v5] - Rebased to latest upstream. - Updated the ioctl interface. - Returned the tid in the ioctl structure. Changelog[v4] - Rebased to latest upstream. - Updated the ioctl interface. - Removed the field tid in the context structure. Changelog[v3] - Rebased to latest upstream. - Updated attr->tid field in cxllib_get_PE_attributes(). Changelog[v2] - Rebased to latest upstream. - Updated the ioctl interface. - Added a checking to allow updating the TIDR if a P9 chip is present. --- arch/powerpc/kernel/process.c | 1 + drivers/misc/cxl/context.c | 15 +++++++++++++++ drivers/misc/cxl/cxl.h | 3 +++ drivers/misc/cxl/cxllib.c | 3 ++- drivers/misc/cxl/file.c | 19 +++++++++++++++++-- drivers/misc/cxl/native.c | 2 +- drivers/misc/cxl/trace.h | 12 ++++++++---- include/uapi/misc/cxl.h | 10 ++++++---- 8 files changed, 53 insertions(+), 12 deletions(-) diff --git a/arch/powerpc/kernel/process.c b/arch/powerpc/kernel/process.c index 5acb5a1..a6a70e2 100644 --- a/arch/powerpc/kernel/process.c +++ b/arch/powerpc/kernel/process.c @@ -1589,6 +1589,7 @@ int set_thread_tidr(struct task_struct *t) return 0; } +EXPORT_SYMBOL_GPL(set_thread_tidr); #endif /* CONFIG_PPC64 */ diff --git a/drivers/misc/cxl/context.c b/drivers/misc/cxl/context.c index 12a41b2..e309d35 100644 --- a/drivers/misc/cxl/context.c +++ b/drivers/misc/cxl/context.c @@ -22,6 +22,7 @@ #include #include #include +#include #include "cxl.h" @@ -362,3 +363,17 @@ void cxl_context_mm_count_put(struct cxl_context *ctx) if (ctx->mm) mmdrop(ctx->mm); } + +int cxl_context_thread_tidr(struct cxl_context *ctx) +{ + int rc = 0; + + if (!cxl_is_power9()) + return -ENODEV; + + rc = set_thread_tidr(current); + pr_devel("%s: current tidr: %ld\n", __func__, + current->thread.tidr); + + return rc; +} diff --git a/drivers/misc/cxl/cxl.h b/drivers/misc/cxl/cxl.h index e46a406..1a5db0b 100644 --- a/drivers/misc/cxl/cxl.h +++ b/drivers/misc/cxl/cxl.h @@ -1169,4 +1169,7 @@ void cxl_context_mm_count_get(struct cxl_context *ctx); /* Decrements the reference count to "struct mm_struct" */ void cxl_context_mm_count_put(struct cxl_context *ctx); +/* Handles an unique TIDR (thread id) for the current thread */ +int cxl_context_thread_tidr(struct cxl_context *ctx); + #endif diff --git a/drivers/misc/cxl/cxllib.c b/drivers/misc/cxl/cxllib.c index dc9bc18..30ccba4 100644 --- a/drivers/misc/cxl/cxllib.c +++ b/drivers/misc/cxl/cxllib.c @@ -199,10 +199,11 @@ int cxllib_get_PE_attributes(struct task_struct *task, */ attr->pid = mm->context.id; mmput(mm); + attr->tid = task->thread.tidr; } else { attr->pid = 0; + attr->tid = 0; } - attr->tid = 0; return 0; } EXPORT_SYMBOL_GPL(cxllib_get_PE_attributes); diff --git a/drivers/misc/cxl/file.c b/drivers/misc/cxl/file.c index 76c0b0c..788b3af 100644 --- a/drivers/misc/cxl/file.c +++ b/drivers/misc/cxl/file.c @@ -173,7 +173,7 @@ static long afu_ioctl_start_work(struct cxl_context *ctx, * flags are set it's invalid */ if (work.reserved1 || work.reserved2 || work.reserved3 || - work.reserved4 || work.reserved5 || work.reserved6 || + work.reserved4 || work.reserved5 || (work.flags & ~CXL_START_WORK_ALL)) { rc = -EINVAL; goto out; @@ -248,7 +248,19 @@ static long afu_ioctl_start_work(struct cxl_context *ctx, */ smp_mb(); - trace_cxl_attach(ctx, work.work_element_descriptor, work.num_interrupts, amr); + /* Assign a unique TIDR (thread id) for the current thread */ + if (work.flags & CXL_START_WORK_TID) { + rc = cxl_context_thread_tidr(ctx); + if (rc) + goto out; + } + work.tid = current->thread.tidr; + + trace_cxl_attach(ctx, + work.work_element_descriptor, + work.num_interrupts, + amr, + work.tid); if ((rc = cxl_ops->attach_process(ctx, false, work.work_element_descriptor, amr))) { @@ -263,6 +275,9 @@ static long afu_ioctl_start_work(struct cxl_context *ctx, goto out; } + if (copy_to_user(uwork, &work, sizeof(work))) + return -EFAULT; + ctx->status = STARTED; rc = 0; out: diff --git a/drivers/misc/cxl/native.c b/drivers/misc/cxl/native.c index 02b6b45..036fe5b 100644 --- a/drivers/misc/cxl/native.c +++ b/drivers/misc/cxl/native.c @@ -673,7 +673,7 @@ static int process_element_entry_psl9(struct cxl_context *ctx, u64 wed, u64 amr) pid = ctx->mm->context.id; } - ctx->elem->common.tid = 0; + ctx->elem->common.tid = cpu_to_be32(current->thread.tidr); ctx->elem->common.pid = cpu_to_be32(pid); ctx->elem->sr = cpu_to_be64(calculate_sr(ctx)); diff --git a/drivers/misc/cxl/trace.h b/drivers/misc/cxl/trace.h index b8e300a..08436b8 100644 --- a/drivers/misc/cxl/trace.h +++ b/drivers/misc/cxl/trace.h @@ -90,9 +90,10 @@ DECLARE_EVENT_CLASS(cxl_pe_class, TRACE_EVENT(cxl_attach, - TP_PROTO(struct cxl_context *ctx, u64 wed, s16 num_interrupts, u64 amr), + TP_PROTO(struct cxl_context *ctx, u64 wed, s16 num_interrupts, + u64 amr, s16 tidr), - TP_ARGS(ctx, wed, num_interrupts, amr), + TP_ARGS(ctx, wed, num_interrupts, amr, tidr), TP_STRUCT__entry( __field(u8, card) @@ -102,6 +103,7 @@ TRACE_EVENT(cxl_attach, __field(u64, wed) __field(u64, amr) __field(s16, num_interrupts) + __field(s16, tidr) ), TP_fast_assign( @@ -112,16 +114,18 @@ TRACE_EVENT(cxl_attach, __entry->wed = wed; __entry->amr = amr; __entry->num_interrupts = num_interrupts; + __entry->tidr = tidr; ), - TP_printk("afu%i.%i pid=%i pe=%i wed=0x%016llx irqs=%i amr=0x%llx", + TP_printk("afu%i.%i pid=%i pe=%i wed=0x%016llx irqs=%i amr=0x%llx tidr=%i", __entry->card, __entry->afu, __entry->pid, __entry->pe, __entry->wed, __entry->num_interrupts, - __entry->amr + __entry->amr, + __entry->tidr ) ); diff --git a/include/uapi/misc/cxl.h b/include/uapi/misc/cxl.h index 49e8fd0..3ea2d4b4 100644 --- a/include/uapi/misc/cxl.h +++ b/include/uapi/misc/cxl.h @@ -20,20 +20,22 @@ struct cxl_ioctl_start_work { __u64 work_element_descriptor; __u64 amr; __s16 num_interrupts; - __s16 reserved1; - __s32 reserved2; + __s16 tid; + __s32 reserved1; + __u64 reserved2; __u64 reserved3; __u64 reserved4; __u64 reserved5; - __u64 reserved6; }; #define CXL_START_WORK_AMR 0x0000000000000001ULL #define CXL_START_WORK_NUM_IRQS 0x0000000000000002ULL #define CXL_START_WORK_ERR_FF 0x0000000000000004ULL +#define CXL_START_WORK_TID 0x0000000000000008ULL #define CXL_START_WORK_ALL (CXL_START_WORK_AMR |\ CXL_START_WORK_NUM_IRQS |\ - CXL_START_WORK_ERR_FF) + CXL_START_WORK_ERR_FF |\ + CXL_START_WORK_TID) /* Possible modes that an afu can be in */