Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp537373pxb; Sat, 6 Mar 2021 07:56:23 -0800 (PST) X-Google-Smtp-Source: ABdhPJxJ/6MMRXVbIDt9zquoNX8YpP5vlKeLHDCssy80/KiCkcl1Ks54mKwjkPcp/6O8Ge0jlub/ X-Received: by 2002:a50:fe89:: with SMTP id d9mr14545308edt.57.1615046183622; Sat, 06 Mar 2021 07:56:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1615046183; cv=none; d=google.com; s=arc-20160816; b=1BtoixNzQHDorBmkG74CL++g/PcpYQXsJbySrYSqjioUS3APukjUa4BIkrSsLEAQTh n+yxxG86r3omzaER6XKP67OVnAOgtCGt5ZGIFrdxfFqYpYB3epRN3L89JDGvl/hnxnQX TGyx3Kxno/p2G1Cncf82AkFpDOziassYPgLWpxa0kpOacLrDBKQV3nWLx8Er2nu18sBC q1dirhCdWXH3xkINyFH1peXr3UjNuXWnhKC6SF9b4vZZdIC9uK0LHos+E0HGeBDeuL2W tmFlLP70TUhs7BKXCs24U6Ng7CZ5y5nOrmXq/ZJ0+uOxgSYPTjihlSye4KCz5Xqkzjtp c0Tg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-language:content-transfer-encoding :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject:dkim-signature; bh=YLgTC5xuRtEJoWFeLL0Al3QRdT5Bosciz4GMHZ864Iw=; b=PCVrTGchsgyYc/mr6o7xWOQO776yznjcMMipvKzP/uS0PLB68hFQbhparKYF9cYrgs zoo92hPMM7d+/D07oMH6a0CJuzmLxIIbxyby5Fhtm35NCuoaJ+oAoJadBlvr9Z1HL++6 mNPJw8kt3ZgnO5c9UruxCVYOj+qbPsJ9Wk6YmrRMceQk9tk/r6RLbdRU2OOdsa4sB8Dd 6f71VKZJl0U+FqiwySz0B5tz/Jg0oyzMSwC2PwoCVsgxtgUMu9RWSGFqYEyeF31JzaWR EDZilxl/6lDCTkes5R2eHn9U/W7wv1ZJzE/am2tyFWAnq/t1yicAFPBLz1k3moISihI0 SoUA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=OUM3UOd7; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id dc3si3705688edb.57.2021.03.06.07.56.00; Sat, 06 Mar 2021 07:56:23 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=OUM3UOd7; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230417AbhCFPy5 (ORCPT + 99 others); Sat, 6 Mar 2021 10:54:57 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:58409 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230213AbhCFPyz (ORCPT ); Sat, 6 Mar 2021 10:54:55 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1615046094; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=YLgTC5xuRtEJoWFeLL0Al3QRdT5Bosciz4GMHZ864Iw=; b=OUM3UOd7bMqgZCjzd/uiRJ3QdbL4bhVu9i+/Phe2hhGX05ATdU0ItbPUQ+RGySssoPnwG9 cZ1ZC1SN9IjzzwpzhL6h8IK40fDh5ETu25/s/HinxBnXCW1wuArim/jtU5Zw1hy8P49uYQ QU0fYmz5LyPmAsZo5Vd3WOqAAOwHagA= Received: from mail-qt1-f197.google.com (mail-qt1-f197.google.com [209.85.160.197]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-534-2jU-gskmMeiU-WV-1SOHIQ-1; Sat, 06 Mar 2021 10:54:52 -0500 X-MC-Unique: 2jU-gskmMeiU-WV-1SOHIQ-1 Received: by mail-qt1-f197.google.com with SMTP id 16so4464423qtw.1 for ; Sat, 06 Mar 2021 07:54:52 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding :content-language; bh=YLgTC5xuRtEJoWFeLL0Al3QRdT5Bosciz4GMHZ864Iw=; b=VM1qMRJBn3cPU8IPvGnNhtkscGqzjK2m6B+1WoF+3JrgSd9PvVGG812c03EFeiMmjR U9PBMstizzkhQ6483SQ0hx1YcJ5kM8t4RY8OC+xu+oHoUa1gidhFABbnZD0C4MOiCj9P Bvmlr90n1ah3/GjuKxOgSDPXp6RvYIsnylHojkd/bqSIy3XlvByaB7asQp7VeuoiJW1K MRfEwPYd4cUXUUNCrUdzugzY8e8MxYOqf8z7ScZ58xAsVFGE8mTY4PEoNR6XoR6Nff+r XEcAn/AaGVz5h9mMFl5L3Cq0zvDLq5YjfGOaXbId2pWN6/8S15KMdZkTP7Cc7g0Xe1ZF xVlg== X-Gm-Message-State: AOAM530RM87akFLxXTkMZhpNQjWo6/3vQE9Xd4232cE3dX3tPf51MBNM enyuTvonY+8nDVm2bcOC9L3a7QxlqEmXwbZRMZehbyj5t8Oh81C4V+R1JTprtmeKEjXXRsBqqP3 nOdYQLSw475tTYMHxkI2V3UYA X-Received: by 2002:a37:4986:: with SMTP id w128mr13417974qka.313.1615046092134; Sat, 06 Mar 2021 07:54:52 -0800 (PST) X-Received: by 2002:a37:4986:: with SMTP id w128mr13417959qka.313.1615046091884; Sat, 06 Mar 2021 07:54:51 -0800 (PST) Received: from trix.remote.csb (075-142-250-213.res.spectrum.com. [75.142.250.213]) by smtp.gmail.com with ESMTPSA id z11sm4182354qkg.52.2021.03.06.07.54.50 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 06 Mar 2021 07:54:51 -0800 (PST) Subject: Re: [PATCH V3 XRT Alveo 17/18] fpga: xrt: partition isolation platform driver To: Lizhi Hou , linux-kernel@vger.kernel.org Cc: Lizhi Hou , linux-fpga@vger.kernel.org, maxz@xilinx.com, sonal.santan@xilinx.com, michal.simek@xilinx.com, stefanos@xilinx.com, devicetree@vger.kernel.org, mdf@kernel.org, robh@kernel.org, Max Zhen References: <20210218064019.29189-1-lizhih@xilinx.com> <20210218064019.29189-18-lizhih@xilinx.com> From: Tom Rix Message-ID: <74def489-0a25-f90a-a00c-9d79dcbaf25a@redhat.com> Date: Sat, 6 Mar 2021 07:54:49 -0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.7.0 MIME-Version: 1.0 In-Reply-To: <20210218064019.29189-18-lizhih@xilinx.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Content-Language: en-US Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2/17/21 10:40 PM, Lizhi Hou wrote: > Add partition isolation platform driver. partition isolation is > a hardware function discovered by walking firmware metadata. > A platform device node will be created for it. Partition isolation > function isolate the different fpga regions > > Signed-off-by: Sonal Santan > Signed-off-by: Max Zhen > Signed-off-by: Lizhi Hou > --- > drivers/fpga/xrt/include/xleaf/axigate.h | 25 ++ > drivers/fpga/xrt/lib/xleaf/axigate.c | 298 +++++++++++++++++++++++ > 2 files changed, 323 insertions(+) > create mode 100644 drivers/fpga/xrt/include/xleaf/axigate.h > create mode 100644 drivers/fpga/xrt/lib/xleaf/axigate.c > > diff --git a/drivers/fpga/xrt/include/xleaf/axigate.h b/drivers/fpga/xrt/include/xleaf/axigate.h > new file mode 100644 > index 000000000000..2cef71e13b30 > --- /dev/null > +++ b/drivers/fpga/xrt/include/xleaf/axigate.h > @@ -0,0 +1,25 @@ > +/* SPDX-License-Identifier: GPL-2.0 */ > +/* > + * Header file for XRT Axigate Leaf Driver > + * > + * Copyright (C) 2020-2021 Xilinx, Inc. > + * > + * Authors: > + * Lizhi Hou > + */ > + > +#ifndef _XRT_AXIGATE_H_ > +#define _XRT_AXIGATE_H_ > + > +#include "xleaf.h" > +#include "metadata.h" > + > +/* > + * AXIGATE driver IOCTL calls. > + */ > +enum xrt_axigate_ioctl_cmd { > + XRT_AXIGATE_FREEZE = XRT_XLEAF_CUSTOM_BASE, /* See comments in xleaf.h */ > + XRT_AXIGATE_FREE, These are substrings, could change suffix to make it harder for developer to mix up. > +}; > + > +#endif /* _XRT_AXIGATE_H_ */ > diff --git a/drivers/fpga/xrt/lib/xleaf/axigate.c b/drivers/fpga/xrt/lib/xleaf/axigate.c > new file mode 100644 > index 000000000000..382969f9925f > --- /dev/null > +++ b/drivers/fpga/xrt/lib/xleaf/axigate.c > @@ -0,0 +1,298 @@ > +// SPDX-License-Identifier: GPL-2.0 > +/* > + * Xilinx Alveo FPGA AXI Gate Driver > + * > + * Copyright (C) 2020-2021 Xilinx, Inc. > + * > + * Authors: > + * Lizhi Hou > + */ > + > +#include > +#include > +#include > +#include > +#include > +#include "metadata.h" > +#include "xleaf.h" > +#include "xleaf/axigate.h" > + > +#define XRT_AXIGATE "xrt_axigate" > + > +struct axigate_regs { > + u32 iag_wr; > + u32 iag_rvsd; > + u32 iag_rd; > +} __packed; similar to other patches, prefix of element is not needed. > + > +struct xrt_axigate { > + struct platform_device *pdev; > + void *base; > + struct mutex gate_lock; /* gate dev lock */ > + > + void *evt_hdl; > + const char *ep_name; > + > + bool gate_freezed; > +}; > + > +/* the ep names are in the order of hardware layers */ > +static const char * const xrt_axigate_epnames[] = { > + XRT_MD_NODE_GATE_PLP, > + XRT_MD_NODE_GATE_ULP, what are plp, ulp ? it is helpful to comment or expand acronyms > + NULL > +}; > + > +#define reg_rd(g, r) \ > + ioread32((void *)(g)->base + offsetof(struct axigate_regs, r)) > +#define reg_wr(g, v, r) \ > + iowrite32(v, (void *)(g)->base + offsetof(struct axigate_regs, r)) > + > +static inline void freeze_gate(struct xrt_axigate *gate) > +{ > + reg_wr(gate, 0, iag_wr); The values written here and below are magic, the need to have #defines > + ndelay(500); > + reg_rd(gate, iag_rd); > +} > + > +static inline void free_gate(struct xrt_axigate *gate) > +{ > + reg_wr(gate, 0x2, iag_wr); > + ndelay(500); > + (void)reg_rd(gate, iag_rd); > + reg_wr(gate, 0x3, iag_wr); > + ndelay(500); > + reg_rd(gate, iag_rd); > +} > + > +static int xrt_axigate_epname_idx(struct platform_device *pdev) > +{ > + int i; > + int ret; int i, ret; > + struct resource *res; > + > + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); > + if (!res) { > + xrt_err(pdev, "Empty Resource!"); > + return -EINVAL; > + } > + > + for (i = 0; xrt_axigate_epnames[i]; i++) { null guarded array is useful with the size isn't know, in this case it is, so covert loop to using ARRAY_SIZE > + ret = strncmp(xrt_axigate_epnames[i], res->name, > + strlen(xrt_axigate_epnames[i]) + 1); needs a strlen check in case res->name is just a substring > + if (!ret) > + break; > + } > + > + ret = (xrt_axigate_epnames[i]) ? i : -EINVAL; > + return ret; > +} > + > +static void xrt_axigate_freeze(struct platform_device *pdev) > +{ > + struct xrt_axigate *gate; > + u32 freeze = 0; > + > + gate = platform_get_drvdata(pdev); > + > + mutex_lock(&gate->gate_lock); > + freeze = reg_rd(gate, iag_rd); > + if (freeze) { /* gate is opened */ > + xleaf_broadcast_event(pdev, XRT_EVENT_PRE_GATE_CLOSE, false); > + freeze_gate(gate); > + } > + > + gate->gate_freezed = true; Looks like freeze could be 0, so is setting gate_freeze = true correct all the time ? > + mutex_unlock(&gate->gate_lock); > + > + xrt_info(pdev, "freeze gate %s", gate->ep_name); > +} > + > +static void xrt_axigate_free(struct platform_device *pdev) > +{ > + struct xrt_axigate *gate; > + u32 freeze; > + > + gate = platform_get_drvdata(pdev); > + > + mutex_lock(&gate->gate_lock); > + freeze = reg_rd(gate, iag_rd); > + if (!freeze) { /* gate is closed */ > + free_gate(gate); > + xleaf_broadcast_event(pdev, XRT_EVENT_POST_GATE_OPEN, true); > + /* xrt_axigate_free() could be called in event cb, thus > + * we can not wait for the completes > + */ > + } > + > + gate->gate_freezed = false; freezed is not a word, the element name should be 'gate_frozen' > + mutex_unlock(&gate->gate_lock); > + > + xrt_info(pdev, "free gate %s", gate->ep_name); > +} > + > +static void xrt_axigate_event_cb(struct platform_device *pdev, void *arg) > +{ > + struct platform_device *leaf; > + struct xrt_event *evt = (struct xrt_event *)arg; > + enum xrt_events e = evt->xe_evt; > + enum xrt_subdev_id id = evt->xe_subdev.xevt_subdev_id; > + int instance = evt->xe_subdev.xevt_subdev_instance; > + struct xrt_axigate *gate = platform_get_drvdata(pdev); > + struct resource *res; > + > + switch (e) { > + case XRT_EVENT_POST_CREATION: > + break; > + default: > + return; > + } convert switch() to if () > + > + if (id != XRT_SUBDEV_AXIGATE) > + return; > + > + leaf = xleaf_get_leaf_by_id(pdev, id, instance); > + if (!leaf) > + return; > + > + res = platform_get_resource(leaf, IORESOURCE_MEM, 0); > + if (!res || !strncmp(res->name, gate->ep_name, strlen(res->name) + 1)) { > + (void)xleaf_put_leaf(pdev, leaf); > + return; > + } > + > + /* > + * higher level axigate instance created, > + * make sure the gate is openned. This covers 1RP flow which is openned -> is opened what is 1RP ? Tom > + * has plp gate as well. > + */ > + if (xrt_axigate_epname_idx(leaf) > xrt_axigate_epname_idx(pdev)) > + xrt_axigate_free(pdev); > + else > + xleaf_ioctl(leaf, XRT_AXIGATE_FREE, NULL); > + > + (void)xleaf_put_leaf(pdev, leaf); > +} > + > +static int > +xrt_axigate_leaf_ioctl(struct platform_device *pdev, u32 cmd, void *arg) > +{ > + switch (cmd) { > + case XRT_XLEAF_EVENT: > + xrt_axigate_event_cb(pdev, arg); > + break; > + case XRT_AXIGATE_FREEZE: > + xrt_axigate_freeze(pdev); > + break; > + case XRT_AXIGATE_FREE: > + xrt_axigate_free(pdev); > + break; > + default: > + xrt_err(pdev, "unsupported cmd %d", cmd); > + return -EINVAL; > + } > + > + return 0; > +} > + > +static int xrt_axigate_remove(struct platform_device *pdev) > +{ > + struct xrt_axigate *gate; > + > + gate = platform_get_drvdata(pdev); > + > + if (gate->base) > + iounmap(gate->base); > + > + platform_set_drvdata(pdev, NULL); > + devm_kfree(&pdev->dev, gate); > + > + return 0; > +} > + > +static int xrt_axigate_probe(struct platform_device *pdev) > +{ > + struct xrt_axigate *gate; > + struct resource *res; > + int ret; > + > + gate = devm_kzalloc(&pdev->dev, sizeof(*gate), GFP_KERNEL); > + if (!gate) > + return -ENOMEM; > + > + gate->pdev = pdev; > + platform_set_drvdata(pdev, gate); > + > + xrt_info(pdev, "probing..."); > + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); > + if (!res) { > + xrt_err(pdev, "Empty resource 0"); > + ret = -EINVAL; > + goto failed; > + } > + > + gate->base = ioremap(res->start, res->end - res->start + 1); > + if (!gate->base) { > + xrt_err(pdev, "map base iomem failed"); > + ret = -EFAULT; > + goto failed; > + } > + > + gate->ep_name = res->name; > + > + mutex_init(&gate->gate_lock); > + > + return 0; > + > +failed: > + xrt_axigate_remove(pdev); > + return ret; > +} > + > +static struct xrt_subdev_endpoints xrt_axigate_endpoints[] = { > + { > + .xse_names = (struct xrt_subdev_ep_names[]) { > + { .ep_name = "ep_pr_isolate_ulp_00" }, > + { NULL }, > + }, > + .xse_min_ep = 1, > + }, > + { > + .xse_names = (struct xrt_subdev_ep_names[]) { > + { .ep_name = "ep_pr_isolate_plp_00" }, > + { NULL }, > + }, > + .xse_min_ep = 1, > + }, > + { 0 }, > +}; > + > +static struct xrt_subdev_drvdata xrt_axigate_data = { > + .xsd_dev_ops = { > + .xsd_ioctl = xrt_axigate_leaf_ioctl, > + }, > +}; > + > +static const struct platform_device_id xrt_axigate_table[] = { > + { XRT_AXIGATE, (kernel_ulong_t)&xrt_axigate_data }, > + { }, > +}; > + > +static struct platform_driver xrt_axigate_driver = { > + .driver = { > + .name = XRT_AXIGATE, > + }, > + .probe = xrt_axigate_probe, > + .remove = xrt_axigate_remove, > + .id_table = xrt_axigate_table, > +}; > + > +void axigate_leaf_init_fini(bool init) > +{ > + if (init) { > + xleaf_register_driver(XRT_SUBDEV_AXIGATE, > + &xrt_axigate_driver, xrt_axigate_endpoints); > + } else { > + xleaf_unregister_driver(XRT_SUBDEV_AXIGATE); > + } > +}