Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp41191pxf; Wed, 17 Mar 2021 14:48:55 -0700 (PDT) X-Google-Smtp-Source: ABdhPJygYny4bQpXx+jXE5Ji7lfSPJW3Y9qX8uEtUBBdMq2/nCzY5KpggpU92AvHB26plRCy+Fbt X-Received: by 2002:a05:6402:104c:: with SMTP id e12mr43376781edu.108.1616017735729; Wed, 17 Mar 2021 14:48:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1616017735; cv=none; d=google.com; s=arc-20160816; b=yol0tKf73lFZLkgntkr7m3qjOxvQbWh1TCd3q3jMmdSs0PL+1ceOoysExqvzTQM1vJ 2+IGFtmjkFGQJjG7ylT8xJWgNxu82141SF1lKaxOrBDKTM2zmplSqaAlhhqi8jYfJiRO AdOkOpzEjFzsOwb+UvIwZYogNEJBKlo5jhqtYj2c08ehrDF/JSNa5khioZm6bI6TjAXo M2nu4E8ktieNxpYOLjGL1BLQEiNsU4mqOFJhhjcO7JXREfKaXSZDzbfl/4GpbX8DNAck AJcr+kyXxPrgQ8w6VEggp2F0RmIpAaV2gGsKhmY+so0f0y4oTpH7PMZxm5vSixEg6Rsi hqOg== 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=fvmTNKdyQD8s3a5BWMkDpJz/hGcnvlu2wRkq0iMW4OU=; b=kadQT8kB1t05H1soXlhUuz59xB0SptaO+YE7b4etgxt329VT2crFv1S/jK7kx1bkiE evBCQax7GSmslA60ucdctxJ5DWG+KW/vMEvgtRnz0gHJJxhWL7hnkcPHtp7XEPFNP2kS ggQakkqg1W9HLeWPlrU26CpzbhNt79sB0JyLna/rfVYxtvWzFPWUNLh+87PSdgM4DwWL UkFIYXn1le483hqpyHRvXfCTLbEnshYXAAFVmf1sOqmyk9VkIJhN7P6Ujj21ZAMcyqPT GaZsXcoaa1bG20v8z/JWL12Y6NZGdW2oK4myfR2s5Dk/QpM2PPr6HX5kIHpWsKvbI03N cclg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=eg+heNQ2; 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 k12si35832ejq.734.2021.03.17.14.48.32; Wed, 17 Mar 2021 14:48:55 -0700 (PDT) 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=eg+heNQ2; 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 S230500AbhCQVQz (ORCPT + 99 others); Wed, 17 Mar 2021 17:16:55 -0400 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:36829 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230272AbhCQVQy (ORCPT ); Wed, 17 Mar 2021 17:16:54 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1616015813; 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=fvmTNKdyQD8s3a5BWMkDpJz/hGcnvlu2wRkq0iMW4OU=; b=eg+heNQ2rCMyOZJM91L9zfenms1ctgl1YKABHTq8YXx0Q6sQF+YDw61zIhCattLB03CumN V2Q2RdyNuSJzhl0765ZbFItMMOExtuB7/a6jlYwA3hE9wikz4VdnKjyny2/i/TMaW/uHpT nwMORKUJBz8yGEDmSogsB1LqVUhWNoE= Received: from mail-qk1-f199.google.com (mail-qk1-f199.google.com [209.85.222.199]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-358-Oq8dP7YkN52WtYJEcAO-AA-1; Wed, 17 Mar 2021 17:16:43 -0400 X-MC-Unique: Oq8dP7YkN52WtYJEcAO-AA-1 Received: by mail-qk1-f199.google.com with SMTP id 130so30290081qkm.0 for ; Wed, 17 Mar 2021 14:16:43 -0700 (PDT) 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=fvmTNKdyQD8s3a5BWMkDpJz/hGcnvlu2wRkq0iMW4OU=; b=LD4H+Nt1Mx9S69VJaKRbJ8waGF5Kk5NFrfLnDMKWVceyTs2Bkj5r4wLsTHs71LL7I0 TtEhk9HfzzJ6/MGueae0bSCrNC8pXmvJLlnhSzDzCTIYNQxSFLPLTVVISgZPmFgZDn7O iJ4Pqt+UH41lVp/kI75kzPLEHfURDNMw4goJyNki6gm1WnmGri+m+dwxpgBmDy+ZLuua 4pDIgp6SpMbN+U9ROhHDtqTHriJFJJMZudieV/n/C3PpqOAGcO5yPJt9RMkt6v/Gulli kIcZgP1LzRT5OUY9Ww1fFb6ALFVwncCE1XmyDsDTmDC1cU2f9qSQU99/5CVrURZcGLwB 7riA== X-Gm-Message-State: AOAM533oyVbxy6RaTxOXWFlCK8dzDf5giLR9ThkpPOdCGaQegz/GKxn8 nM6pIJF5a4HJ5w75+0/3S+mEqfwY/kevJVS3q3NZTUzA9BM/eilnDqh5cFsgaafM9lICRJCSkQu +1s1VZtdZfjCcUGgbPAIW8lIG X-Received: by 2002:a37:a48a:: with SMTP id n132mr1185081qke.359.1616015802572; Wed, 17 Mar 2021 14:16:42 -0700 (PDT) X-Received: by 2002:a37:a48a:: with SMTP id n132mr1185064qke.359.1616015802310; Wed, 17 Mar 2021 14:16:42 -0700 (PDT) Received: from trix.remote.csb (075-142-250-213.res.spectrum.com. [75.142.250.213]) by smtp.gmail.com with ESMTPSA id p186sm174867qka.66.2021.03.17.14.16.40 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 17 Mar 2021 14:16:42 -0700 (PDT) Subject: Re: [PATCH V3 XRT Alveo 13/18] fpga: xrt: devctl platform driver To: Lizhi Hou , linux-kernel@vger.kernel.org Cc: 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-14-lizhih@xilinx.com> <20b2a60e-1ed1-c466-ce0b-26179338390e@xilinx.com> From: Tom Rix Message-ID: <1c0b59ac-400a-aac6-9886-6b6e7c685a9c@redhat.com> Date: Wed, 17 Mar 2021 14:16:39 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.8.0 MIME-Version: 1.0 In-Reply-To: <20b2a60e-1ed1-c466-ce0b-26179338390e@xilinx.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Content-Language: en-US Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 3/16/21 4:54 PM, Lizhi Hou wrote: > > > On 03/04/2021 05:39 AM, Tom Rix wrote: >> CAUTION: This message has originated from an External Source. Please use proper judgment and caution when opening attachments, clicking links, or responding to this email. >> >> >> On 2/17/21 10:40 PM, Lizhi Hou wrote: >>> Add devctl driver. devctl is a type of hardware function which only has >>> few registers to read or write. They are discovered by walking firmware >>> metadata. A platform device node will be created for them. >>> >>> Signed-off-by: Sonal Santan >>> Signed-off-by: Max Zhen >>> Signed-off-by: Lizhi Hou >>> --- >>>   drivers/fpga/xrt/include/xleaf/devctl.h |  43 +++++ >>>   drivers/fpga/xrt/lib/xleaf/devctl.c     | 206 ++++++++++++++++++++++++ >>>   2 files changed, 249 insertions(+) >>>   create mode 100644 drivers/fpga/xrt/include/xleaf/devctl.h >>>   create mode 100644 drivers/fpga/xrt/lib/xleaf/devctl.c >>> >>> diff --git a/drivers/fpga/xrt/include/xleaf/devctl.h b/drivers/fpga/xrt/include/xleaf/devctl.h >>> new file mode 100644 >>> index 000000000000..96a40e066f83 >>> --- /dev/null >>> +++ b/drivers/fpga/xrt/include/xleaf/devctl.h >>> @@ -0,0 +1,43 @@ >>> +/* SPDX-License-Identifier: GPL-2.0 */ >>> +/* >>> + * Header file for XRT DEVCTL Leaf Driver >>> + * >>> + * Copyright (C) 2020-2021 Xilinx, Inc. >>> + * >>> + * Authors: >>> + *   Lizhi Hou >>> + */ >>> + >>> +#ifndef _XRT_DEVCTL_H_ >>> +#define _XRT_DEVCTL_H_ >>> + >>> +#include "xleaf.h" >>> + >>> +/* >>> + * DEVCTL driver IOCTL calls. >>> + */ >>> +enum xrt_devctl_ioctl_cmd { >>> +     XRT_DEVCTL_READ = XRT_XLEAF_CUSTOM_BASE, /* See comments in xleaf.h */ >>> +     XRT_DEVCTL_WRITE, >>> +}; >>> + >>> +enum xrt_devctl_id { >>> +     XRT_DEVCTL_ROM_UUID, >> Assumes 0, should make this explicit and initialize to 0 > Sure. >>> +     XRT_DEVCTL_DDR_CALIB, >>> +     XRT_DEVCTL_GOLDEN_VER, >>> +     XRT_DEVCTL_MAX >>> +}; >>> + >>> +struct xrt_devctl_ioctl_rw { >>> +     u32     xgir_id; >>> +     void    *xgir_buf; >>> +     u32     xgir_len; >>> +     u32     xgir_offset; >> similar to other patches, the xgir_ prefix is not needed >>> +}; >>> + >>> +struct xrt_devctl_ioctl_intf_uuid { >>> +     u32     xgir_uuid_num; >>> +     uuid_t  *xgir_uuids; >>> +}; >>> + >>> +#endif       /* _XRT_DEVCTL_H_ */ >>> diff --git a/drivers/fpga/xrt/lib/xleaf/devctl.c b/drivers/fpga/xrt/lib/xleaf/devctl.c >>> new file mode 100644 >>> index 000000000000..caf8c6569f0f >>> --- /dev/null >>> +++ b/drivers/fpga/xrt/lib/xleaf/devctl.c >>> @@ -0,0 +1,206 @@ >>> +// SPDX-License-Identifier: GPL-2.0 >>> +/* >>> + * Xilinx Alveo FPGA devctl Driver >>> + * >>> + * Copyright (C) 2020-2021 Xilinx, Inc. >>> + * >>> + * Authors: >>> + *      Lizhi Hou >>> + */ >>> + >>> +#include >>> +#include >>> +#include >>> +#include >>> +#include >>> +#include "metadata.h" >>> +#include "xleaf.h" >>> +#include "xleaf/devctl.h" >>> + >>> +#define XRT_DEVCTL "xrt_devctl" >>> + >>> +struct xrt_name_id { >>> +     char *ep_name; >>> +     int id; >>> +}; >>> + >>> +static struct xrt_name_id name_id[XRT_DEVCTL_MAX] = { >>> +     { XRT_MD_NODE_BLP_ROM, XRT_DEVCTL_ROM_UUID }, >>> +     { XRT_MD_NODE_GOLDEN_VER, XRT_DEVCTL_GOLDEN_VER }, >> DDR_CALIB is unused ? > Not sure if I understand the question correctly. ddr_calib will have more things need to handle other than just read/write. I do not understand either, ignore this comment. If it is important, I will bring it up in a later revision's review and do a better job of explaining the issue. Tom >>> +}; >>> + >>> +struct xrt_devctl { >>> +     struct platform_device  *pdev; >>> +     void            __iomem *base_addrs[XRT_DEVCTL_MAX]; >>> +     ulong                   sizes[XRT_DEVCTL_MAX]; >>> +}; >> similar to other patches, why not use regmap ? > Will change to regmap. >>> + >>> +static int xrt_devctl_name2id(struct xrt_devctl *devctl, const char *name) >>> +{ >>> +     int     i; >>> + >>> +     for (i = 0; i < XRT_DEVCTL_MAX && name_id[i].ep_name; i++) { >>> +             if (!strncmp(name_id[i].ep_name, name, strlen(name_id[i].ep_name) + 1)) >>> +                     return name_id[i].id; >>> +     } >>> + >>> +     return -EINVAL; >>> +} >>> + >>> +static int >>> +xrt_devctl_leaf_ioctl(struct platform_device *pdev, u32 cmd, void *arg) >>> +{ >>> +     struct xrt_devctl       *devctl; >>> +     int                     ret = 0; >>> + >>> +     devctl = platform_get_drvdata(pdev); >>> + >>> +     switch (cmd) { >>> +     case XRT_XLEAF_EVENT: >>> +             /* Does not handle any event. */ >>> +             break; >>> +     case XRT_DEVCTL_READ: { >>> +             struct xrt_devctl_ioctl_rw      *rw_arg = arg; >>> +             u32                             *p_src, *p_dst, i; >>> + >>> +             if (rw_arg->xgir_len & 0x3) { >>> +                     xrt_err(pdev, "invalid len %d", rw_arg->xgir_len); >>> +                     return -EINVAL; >>> +             } >>> + >>> +             if (rw_arg->xgir_id >= XRT_DEVCTL_MAX) { >>> +                     xrt_err(pdev, "invalid id %d", rw_arg->xgir_id); >>> +                     return -EINVAL; >>> +             } >> needs a < 0 check ? > change xgir_id to u32. >>> + >>> +             p_src = devctl->base_addrs[rw_arg->xgir_id]; >>> +             if (!p_src) { >>> +                     xrt_err(pdev, "io not found, id %d", >>> +                             rw_arg->xgir_id); >>> +                     return -EINVAL; >>> +             } >>> +             if (rw_arg->xgir_offset + rw_arg->xgir_len > >>> +                 devctl->sizes[rw_arg->xgir_id]) { >>> +                     xrt_err(pdev, "invalid argument, off %d, len %d", >>> +                             rw_arg->xgir_offset, rw_arg->xgir_len); >>> +                     return -EINVAL; >>> +             } >>> +             p_dst = rw_arg->xgir_buf; >>> +             for (i = 0; i < rw_arg->xgir_len / sizeof(u32); i++) { >>> +                     u32 val = ioread32(p_src + rw_arg->xgir_offset + i); >>> + >>> +                     memcpy(p_dst + i, &val, sizeof(u32)); >>> +             } >>> +             break; >>> +     } >> The _WRITE msg is not handled Then why have it ? > Will remove write msg from this patch set and add it back in future patches. > > Thanks, > Lizhi >> >> Tom >> >>> +     default: >>> +             xrt_err(pdev, "unsupported cmd %d", cmd); >>> +             return -EINVAL; >>> +     } >>> + >>> +     return ret; >>> +} >>> + >>> +static int xrt_devctl_remove(struct platform_device *pdev) >>> +{ >>> +     struct xrt_devctl       *devctl; >>> +     int                     i; >>> + >>> +     devctl = platform_get_drvdata(pdev); >>> + >>> +     for (i = 0; i < XRT_DEVCTL_MAX; i++) { >>> +             if (devctl->base_addrs[i]) >>> +                     iounmap(devctl->base_addrs[i]); >>> +     } >>> + >>> +     platform_set_drvdata(pdev, NULL); >>> +     devm_kfree(&pdev->dev, devctl); >>> + >>> +     return 0; >>> +} >>> + >>> +static int xrt_devctl_probe(struct platform_device *pdev) >>> +{ >>> +     struct xrt_devctl       *devctl; >>> +     int                     i, id, ret = 0; >>> +     struct resource         *res; >>> + >>> +     devctl = devm_kzalloc(&pdev->dev, sizeof(*devctl), GFP_KERNEL); >>> +     if (!devctl) >>> +             return -ENOMEM; >>> + >>> +     devctl->pdev = pdev; >>> +     platform_set_drvdata(pdev, devctl); >>> + >>> +     xrt_info(pdev, "probing..."); >>> +     for (i = 0, res = platform_get_resource(pdev, IORESOURCE_MEM, 0); >>> +         res; >>> +         res = platform_get_resource(pdev, IORESOURCE_MEM, ++i)) { >>> +             id = xrt_devctl_name2id(devctl, res->name); >>> +             if (id < 0) { >>> +                     xrt_err(pdev, "ep %s not found", res->name); >>> +                     continue; >>> +             } >>> +             devctl->base_addrs[id] = ioremap(res->start, res->end - res->start + 1); >>> +             if (!devctl->base_addrs[id]) { >>> +                     xrt_err(pdev, "map base failed %pR", res); >>> +                     ret = -EIO; >>> +                     goto failed; >>> +             } >>> +             devctl->sizes[id] = res->end - res->start + 1; >>> +     } >>> + >>> +failed: >>> +     if (ret) >>> +             xrt_devctl_remove(pdev); >>> + >>> +     return ret; >>> +} >>> + >>> +static struct xrt_subdev_endpoints xrt_devctl_endpoints[] = { >>> +     { >>> +             .xse_names = (struct xrt_subdev_ep_names[]) { >>> +                     /* add name if ep is in same partition */ >>> +                     { .ep_name = XRT_MD_NODE_BLP_ROM }, >>> +                     { NULL }, >>> +             }, >>> +             .xse_min_ep = 1, >>> +     }, >>> +     { >>> +             .xse_names = (struct xrt_subdev_ep_names[]) { >>> +                     { .ep_name = XRT_MD_NODE_GOLDEN_VER }, >>> +                     { NULL }, >>> +             }, >>> +             .xse_min_ep = 1, >>> +     }, >>> +     /* adding ep bundle generates devctl device instance */ >>> +     { 0 }, >>> +}; >>> + >>> +static struct xrt_subdev_drvdata xrt_devctl_data = { >>> +     .xsd_dev_ops = { >>> +             .xsd_ioctl = xrt_devctl_leaf_ioctl, >>> +     }, >>> +}; >>> + >>> +static const struct platform_device_id xrt_devctl_table[] = { >>> +     { XRT_DEVCTL, (kernel_ulong_t)&xrt_devctl_data }, >>> +     { }, >>> +}; >>> + >>> +static struct platform_driver xrt_devctl_driver = { >>> +     .driver = { >>> +             .name = XRT_DEVCTL, >>> +     }, >>> +     .probe = xrt_devctl_probe, >>> +     .remove = xrt_devctl_remove, >>> +     .id_table = xrt_devctl_table, >>> +}; >>> + >>> +void devctl_leaf_init_fini(bool init) >>> +{ >>> +     if (init) >>> +             xleaf_register_driver(XRT_SUBDEV_DEVCTL, &xrt_devctl_driver, xrt_devctl_endpoints); >>> +     else >>> +             xleaf_unregister_driver(XRT_SUBDEV_DEVCTL); >>> +} >