Received: by 2002:a25:c593:0:0:0:0:0 with SMTP id v141csp5091524ybe; Tue, 17 Sep 2019 02:26:04 -0700 (PDT) X-Google-Smtp-Source: APXvYqyai9HJ80ZuKtW1nTpX+2rF46gADxSgj6vexiRT6q3Q6Lj/cFsFF/MZLR2WP8pIGo3Fay3p X-Received: by 2002:a50:c209:: with SMTP id n9mr3510850edf.215.1568712364380; Tue, 17 Sep 2019 02:26:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1568712364; cv=none; d=google.com; s=arc-20160816; b=wqdT4ppGUgB9vucx69Mil3AyAlOvP0mLYo57OpSJBcvURfCcW3rLL93p1W3n2nkIuI GY2DvFNXlryiyLDZFDwZT0y3moRljsLwcNPM1DjunCW7s5a9/lY2i4v6SUEEwGZUCK4E PRAQ293YU3w6Z7AlKukZX/UjvvlS5ZB0FrRJnL3Fos8lRNERuHS6X669NM6HZPRw4WSv Y7uKn0P6cHuQ3hhKVEsTLLsSDrDvLvk1BbGszM7MO75j+8Nlcky6uu6SaRnWTxup5o6l x6SfL3osz4CPPYrzu3W79469+6OchNx0fH3v7KIQHf52yLmxsIBetITZ/7fYXtOrrgCv E4Ig== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:content-transfer-encoding :mime-version:references:in-reply-to:date:subject:cc:to:from; bh=REdlJIOkscZomAjsfZOIntsbDRuO6cgs5ziV+Cp4vgM=; b=tvey+So3ewYF2dixO2zvVCwYpyaEoEa/lMBw7J3qo029/KOk3k/GZGBXffI9aaqs1B /GM/FCGh0cWgQ7K0+U/AtSY/imXkrMf1wmyiC1F/9ikKoozN3WhOvHFiFo5H8t7w/tSQ Pw6nurNCzaXm+lfSa1GbryGyMsyCRoMkDqIVsqUFcYh8MhcaoUyBTNlTN4tSBEywJTpg mlscXZ5IbqruXf7w3zZatszozANClDRqh5nKbWHG4CVNrcMNx2Jg26RH3xae73bo+YIK Cd58jyON/Q4dalhwG7jzOy4vnjVgOIeKLw94Y4iesX8B76QqjMxbqrawl+3OyU4QgWlr OuHA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z11si794034ejm.28.2019.09.17.02.25.41; Tue, 17 Sep 2019 02:26:04 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2391854AbfIQBrf (ORCPT + 99 others); Mon, 16 Sep 2019 21:47:35 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:33990 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728211AbfIQBre (ORCPT ); Mon, 16 Sep 2019 21:47:34 -0400 Received: from pps.filterd (m0098404.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.27/8.16.0.27) with SMTP id x8H1lGVx001130 for ; Mon, 16 Sep 2019 21:47:34 -0400 Received: from e06smtp03.uk.ibm.com (e06smtp03.uk.ibm.com [195.75.94.99]) by mx0a-001b2d01.pphosted.com with ESMTP id 2v2my69re6-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Mon, 16 Sep 2019 21:47:33 -0400 Received: from localhost by e06smtp03.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Tue, 17 Sep 2019 02:47:31 +0100 Received: from b06cxnps4076.portsmouth.uk.ibm.com (9.149.109.198) 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) Tue, 17 Sep 2019 02:47:26 +0100 Received: from d06av22.portsmouth.uk.ibm.com (d06av22.portsmouth.uk.ibm.com [9.149.105.58]) by b06cxnps4076.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id x8H1lQTQ37355770 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 17 Sep 2019 01:47:26 GMT Received: from d06av22.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id E59CF4C040; Tue, 17 Sep 2019 01:47:25 +0000 (GMT) Received: from d06av22.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 4C6FD4C044; Tue, 17 Sep 2019 01:47:25 +0000 (GMT) Received: from ozlabs.au.ibm.com (unknown [9.192.253.14]) by d06av22.portsmouth.uk.ibm.com (Postfix) with ESMTP; Tue, 17 Sep 2019 01:47:25 +0000 (GMT) Received: from adsilva.ozlabs.ibm.com (haven.au.ibm.com [9.192.254.114]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.au.ibm.com (Postfix) with ESMTPSA id E7F07A019A; Tue, 17 Sep 2019 11:47:23 +1000 (AEST) From: "Alastair D'Silva" To: alastair@d-silva.org Cc: Benjamin Herrenschmidt , Paul Mackerras , Michael Ellerman , Frederic Barrat , Andrew Donnellan , Arnd Bergmann , Greg Kroah-Hartman , Anju T Sudhakar , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , Mahesh Salgaonkar , Thomas Gleixner , David Gibson , Masahiro Yamada , Alexey Kardashevskiy , Nicholas Piggin , linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org Subject: [PATCH 3/5] ocxl: Tally up the LPC memory on a link & allow it to be mapped Date: Tue, 17 Sep 2019 11:42:59 +1000 X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190917014307.30485-1-alastair@au1.ibm.com> References: <20190917014307.30485-1-alastair@au1.ibm.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-TM-AS-GCONF: 00 x-cbid: 19091701-0012-0000-0000-0000034CE4E7 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 19091701-0013-0000-0000-000021875CCB Message-Id: <20190917014307.30485-4-alastair@au1.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2019-09-16_09:,, signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=3 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1908290000 definitions=main-1909170019 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Alastair D'Silva Tally up the LPC memory on an OpenCAPI link & allow it to be mapped Signed-off-by: Alastair D'Silva --- drivers/misc/ocxl/core.c | 9 +++++ drivers/misc/ocxl/link.c | 61 +++++++++++++++++++++++++++++++ drivers/misc/ocxl/ocxl_internal.h | 42 +++++++++++++++++++++ 3 files changed, 112 insertions(+) diff --git a/drivers/misc/ocxl/core.c b/drivers/misc/ocxl/core.c index b7a09b21ab36..fdfe4e0a34e1 100644 --- a/drivers/misc/ocxl/core.c +++ b/drivers/misc/ocxl/core.c @@ -230,8 +230,17 @@ static int configure_afu(struct ocxl_afu *afu, u8 afu_idx, struct pci_dev *dev) if (rc) goto err_free_pasid; + if (afu->config.lpc_mem_size || afu->config.special_purpose_mem_size) { + rc = ocxl_link_add_lpc_mem(afu->fn->link, + afu->config.lpc_mem_size + afu->config.special_purpose_mem_size); + if (rc) + goto err_free_mmio; + } + return 0; +err_free_mmio: + unmap_mmio_areas(afu); err_free_pasid: reclaim_afu_pasid(afu); err_free_actag: diff --git a/drivers/misc/ocxl/link.c b/drivers/misc/ocxl/link.c index 58d111afd9f6..2874811a4398 100644 --- a/drivers/misc/ocxl/link.c +++ b/drivers/misc/ocxl/link.c @@ -84,6 +84,11 @@ struct ocxl_link { int dev; atomic_t irq_available; struct spa *spa; + struct mutex lpc_mem_lock; + u64 lpc_mem_sz; /* Total amount of LPC memory presented on the link */ + u64 lpc_mem; + int lpc_consumers; + void *platform_data; }; static struct list_head links_list = LIST_HEAD_INIT(links_list); @@ -396,6 +401,8 @@ static int alloc_link(struct pci_dev *dev, int PE_mask, struct ocxl_link **out_l if (rc) goto err_spa; + mutex_init(&link->lpc_mem_lock); + /* platform specific hook */ rc = pnv_ocxl_spa_setup(dev, link->spa->spa_mem, PE_mask, &link->platform_data); @@ -711,3 +718,57 @@ void ocxl_link_free_irq(void *link_handle, int hw_irq) atomic_inc(&link->irq_available); } EXPORT_SYMBOL_GPL(ocxl_link_free_irq); + +int ocxl_link_add_lpc_mem(void *link_handle, u64 size) +{ + struct ocxl_link *link = (struct ocxl_link *) link_handle; + + u64 orig_size; + bool good = false; + + mutex_lock(&link->lpc_mem_lock); + orig_size = link->lpc_mem_sz; + link->lpc_mem_sz += size; + + good = orig_size < link->lpc_mem_sz; + mutex_unlock(&link->lpc_mem_lock); + + // Check for overflow + return (good) ? 0 : -EINVAL; +} +EXPORT_SYMBOL_GPL(ocxl_link_add_lpc_mem); + +u64 ocxl_link_lpc_map(void *link_handle, struct pci_dev *pdev) +{ + struct ocxl_link *link = (struct ocxl_link *) link_handle; + + mutex_lock(&link->lpc_mem_lock); + if (link->lpc_mem) { + u64 lpc_mem = link->lpc_mem; + + link->lpc_consumers++; + mutex_unlock(&link->lpc_mem_lock); + return lpc_mem; + } + + link->lpc_mem = pnv_ocxl_platform_lpc_setup(pdev, link->lpc_mem_sz); + if (link->lpc_mem) + link->lpc_consumers++; + mutex_unlock(&link->lpc_mem_lock); + + return link->lpc_mem; +} + +void ocxl_link_lpc_release(void *link_handle, struct pci_dev *pdev) +{ + struct ocxl_link *link = (struct ocxl_link *) link_handle; + + mutex_lock(&link->lpc_mem_lock); + link->lpc_consumers--; + if (link->lpc_consumers == 0) { + pnv_ocxl_platform_lpc_release(pdev); + link->lpc_mem = 0; + } + + mutex_unlock(&link->lpc_mem_lock); +} diff --git a/drivers/misc/ocxl/ocxl_internal.h b/drivers/misc/ocxl/ocxl_internal.h index 97415afd79f3..db2647a90fc8 100644 --- a/drivers/misc/ocxl/ocxl_internal.h +++ b/drivers/misc/ocxl/ocxl_internal.h @@ -141,4 +141,46 @@ int ocxl_irq_offset_to_id(struct ocxl_context *ctx, u64 offset); u64 ocxl_irq_id_to_offset(struct ocxl_context *ctx, int irq_id); void ocxl_afu_irq_free_all(struct ocxl_context *ctx); +/** + * Increment the amount of memory required by an OpenCAPI link + * + * link_handle: The OpenCAPI link handle + * size: The amount of memory to increment by + * + * Return 0 on success, negative on overflow + */ +extern int ocxl_link_add_lpc_mem(void *link_handle, u64 size); + +/** + * Get the amount of memory required by an OpenCAPI link + * + * link_handle: The OpenCAPI link handle + * + * Return the amount of memory required by the link, this value is undefined if + * ocxl_link_add_lpc_mem failed. + */ +extern u64 ocxl_link_get_lpc_mem_sz(void *link_handle); + +/** + * Map the LPC memory for an OpenCAPI device + * + * Since LPC memory belongs to a link, the whole LPC memory available + * on the link bust be mapped in order to make it accessible to a device. + * + * @link_handle: The OpenCAPI link handle + * @pdev: A device that is on the link + */ +u64 ocxl_link_lpc_map(void *link_handle, struct pci_dev *pdev); + +/** + * Release the LPC memory device for an OpenCAPI device + * + * Releases LPC memory on an OpenCAPI link for a device. If this is the + * last device on the link to release the memory, unmap it from the link. + * + * @link_handle: The OpenCAPI link handle + * @pdev: A device that is on the link + */ +void ocxl_link_lpc_release(void *link_handle, struct pci_dev *pdev); + #endif /* _OCXL_INTERNAL_H_ */ -- 2.21.0