From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (xvm-189-124.dc0.ghst.net [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 6853FA09FF for ; Thu, 7 Jan 2021 06:34:58 +0100 (CET) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 37CB9140E81; Thu, 7 Jan 2021 06:34:58 +0100 (CET) Received: from mga06.intel.com (mga06.intel.com [134.134.136.31]) by mails.dpdk.org (Postfix) with ESMTP id 54AE6140E81; Thu, 7 Jan 2021 06:34:55 +0100 (CET) IronPort-SDR: K24EiWRAAmGxjB2j37C4CfpM3N8eBaCOnJNjcMq7w1AW7J3FEqQremO45LmniWvBLInhswhq1I O32XEsM0w32A== X-IronPort-AV: E=McAfee;i="6000,8403,9856"; a="238924995" X-IronPort-AV: E=Sophos;i="5.79,329,1602572400"; d="scan'208";a="238924995" Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Jan 2021 21:34:54 -0800 IronPort-SDR: cgjwX69Clu+IctguxxOBcknAG4BnHjBCJYiG2QfyEI90/L7WO+BwPBF3jKSRaq96Rr2z7VdpuA FSQzUC2MxDvg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.79,329,1602572400"; d="scan'208";a="395856979" Received: from orsmsx604.amr.corp.intel.com ([10.22.229.17]) by fmsmga004.fm.intel.com with ESMTP; 06 Jan 2021 21:34:53 -0800 Received: from orsmsx611.amr.corp.intel.com (10.22.229.24) by ORSMSX604.amr.corp.intel.com (10.22.229.17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1713.5; Wed, 6 Jan 2021 21:34:53 -0800 Received: from orsmsx602.amr.corp.intel.com (10.22.229.15) by ORSMSX611.amr.corp.intel.com (10.22.229.24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1713.5; Wed, 6 Jan 2021 21:34:53 -0800 Received: from orsedg603.ED.cps.intel.com (10.7.248.4) by orsmsx602.amr.corp.intel.com (10.22.229.15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1713.5 via Frontend Transport; Wed, 6 Jan 2021 21:34:53 -0800 Received: from NAM10-MW2-obe.outbound.protection.outlook.com (104.47.55.108) by edgegateway.intel.com (134.134.137.100) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.1713.5; Wed, 6 Jan 2021 21:34:51 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=UzVTVCXdmlv74cZbC76E1A01cYQmqpGC84bIG4pUfKxdV6sg9Z76rboZ2gC4AQEFfJbf97lFG5KgNerjuwx9XzO7g4b/vNgPif6q9asWKVjeOaXT2O9Kh85pwPT79fxrk0yVt9Kjpz+cu2Bb/LxHzH7tis09BvWJBXU5/VierUdqP6iiCWZh5wmAQ9WZCzrvgT1rqezmD5u3I4JgJO+OqyFOOAujzo4sytSpYneFvwsPKaKzLDWdbHKm98sE2HhhUuWi+xKsZmY1+DYkSDAFu5ikAqxPvqN6cxs5gZeHHf03L8I8vgTcyUDRPYg+xjqliGNDeXbYrLdDHhT9RBNykA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=9vnHROmk33BtfsNn3Hezf0qRsVtkCsslqYLVDcyaA2g=; b=SlJE0IcDnw5yxhyaGgKhgAZfvJj/oATQFNmB248KybqTr+L26k7i5N9l2+hsOFeXn+65pF4nosuboW/rMuSvcFUrsbicHc5GMuFsmkI0iY4jLwrKawNlxXq4MpB3SkbRF+PYU52AoCYW7EvLDqgN2zL0WqNdDknC5PQQd8ePg3c2k0bsHqxTNiZEd2bbAUCehbrRhiFFlX+twQZ7Ev3X8lIe+mH+GBxFGFrI82RdO5ZA4fzZ5AcMkLkIF+6bqqpctCoaU6k7g/qYcBO5wJt0EC0nQjvUNTJ7bVk0SmAtM1YxgzsYYpSHa5Nqag/LvZFPep5bMf1kEOdBw9CIIwsThA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=intel.com; dmarc=pass action=none header.from=intel.com; dkim=pass header.d=intel.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=intel.onmicrosoft.com; s=selector2-intel-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=9vnHROmk33BtfsNn3Hezf0qRsVtkCsslqYLVDcyaA2g=; b=TdeW46JRm531t+l46UF847Zoo4r4Tw1r+cYgY13J2qNF2qUUTRHdZ2mdW66JOLwVczYIF9xmXpsEkxTiecRe3mdLJD+V7xGktlGaHo6aRVG4gr0IVwlRbrA9fj2ZLU6qlPwRw1RfmlxTjrteZ3j+to2O/w/QtmPr4rzb3dENHzs= Received: from BYAPR11MB2901.namprd11.prod.outlook.com (2603:10b6:a03:91::23) by SJ0PR11MB5005.namprd11.prod.outlook.com (2603:10b6:a03:2d3::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3742.6; Thu, 7 Jan 2021 05:34:47 +0000 Received: from BYAPR11MB2901.namprd11.prod.outlook.com ([fe80::4946:fd9f:86f7:43f9]) by BYAPR11MB2901.namprd11.prod.outlook.com ([fe80::4946:fd9f:86f7:43f9%7]) with mapi id 15.20.3721.024; Thu, 7 Jan 2021 05:34:47 +0000 From: "Xu, Rosen" To: "Huang, Wei" , "dev@dpdk.org" , "Zhang, Qi Z" CC: "stable@dpdk.org" , "Zhang, Tianfei" Thread-Topic: [PATCH v7 4/4] examples/ifpga: add example for opae ifpga API Thread-Index: AQHW4zG+wNSoEqMA4UyrxI0plI8v66obptPw Date: Thu, 7 Jan 2021 05:34:47 +0000 Message-ID: References: <1609830569-6445-1-git-send-email-wei.huang@intel.com> <1609830569-6445-5-git-send-email-wei.huang@intel.com> In-Reply-To: <1609830569-6445-5-git-send-email-wei.huang@intel.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: dlp-product: dlpe-windows dlp-version: 11.5.1.3 dlp-reaction: no-action x-titus-metadata-40: eyJDYXRlZ29yeUxhYmVscyI6IiIsIk1ldGFkYXRhIjp7Im5zIjoiaHR0cDpcL1wvd3d3LnRpdHVzLmNvbVwvbnNcL0ludGVsMyIsImlkIjoiZmNhMzlkZmEtYjM3Mi00ZGU1LThjNTYtNWZjYmNiOTU0NzliIiwicHJvcHMiOlt7Im4iOiJDVFBDbGFzc2lmaWNhdGlvbiIsInZhbHMiOlt7InZhbHVlIjoiQ1RQX05UIn1dfV19LCJTdWJqZWN0TGFiZWxzIjpbXSwiVE1DVmVyc2lvbiI6IjE3LjEwLjE4MDQuNDkiLCJUcnVzdGVkTGFiZWxIYXNoIjoieTFJb0l4c1hLRmF0a2VoQWRHMnk5dDVrZVZONlwvK2dqdU9UTkt1VThvNXlkWnRDNXZ5cW13NytuMVUzOU9wcGQifQ== x-ctpclassification: CTP_NT authentication-results: intel.com; dkim=none (message not signed) header.d=none;intel.com; dmarc=none action=none header.from=intel.com; x-originating-ip: [192.198.147.217] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 084f99c8-5110-4ebf-fb6d-08d8b2cdf213 x-ms-traffictypediagnostic: SJ0PR11MB5005: x-ld-processed: 46c98d88-e344-4ed4-8496-4ed7712e255d,ExtAddr x-ms-exchange-transport-forked: True x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:191; x-ms-exchange-senderadcheck: 1 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: qRgT4IkU6KLdae+FT5pqLvDXI6RR5WUDTWq34yWDn6c7CcLvalxX8qqq3KHl5uaSCtGFhX4QIAtW9vHNSakzdiUkhmGVteIWwxHGg9N9eBB/Qw3Td1LN8s65H371WraVlhHfDcXhx7w5jfdE+shLd0bYPx5GPpQ4VjhisPlAdXhTJrCwhc6V4ohlpvsqCbPNQjCJx/pvWONuYkEUK/7Mhhh0xKdes1jn6W7pKSVFrXeihMQh8PYTVWKf9ioOa1HyLNW6XaeM0usw9G85H47pToxmTVkWalia4Akd8BKhapwuJQPW3EtnWeXe56vmRQpG3xbHn06hMjbAAxIxiNPCAwNizqwcKrLaNYba7DxgVXkMG8TnPME+Cb+VBj0k5GszJORjxQ7axk0iy4tvq6MXhg== x-forefront-antispam-report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:BYAPR11MB2901.namprd11.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(346002)(376002)(366004)(396003)(39860400002)(136003)(33656002)(86362001)(2906002)(110136005)(54906003)(5660300002)(478600001)(52536014)(107886003)(4326008)(8676002)(76116006)(64756008)(66476007)(66556008)(66446008)(66946007)(450100002)(6636002)(30864003)(26005)(83380400001)(186003)(8936002)(71200400001)(55016002)(7696005)(53546011)(6506007)(316002)(9686003)(579004)(559001); DIR:OUT; SFP:1102; x-ms-exchange-antispam-messagedata: =?us-ascii?Q?sUYLoQjmBdikZwoRMd1IQiRAd4ETTAhtIhwtPtmvjD1IZD1n1rif5d+8KJPR?= =?us-ascii?Q?A4njSAVg+MH69JrJhUYXUVckQ7WLNdgLPbBoWieum2SHGWKCj8rpd1yTAxum?= =?us-ascii?Q?JKuLdocQZHR9k/BtA1HOlriEWfl+CL2fGhYfoRAkJSIZ1u2eGEzbn0iC8rFA?= =?us-ascii?Q?NYZ6hm+A8eZOkteBP9+x16IHjGK2qvzIO1Ktbo2Pq719NyDp3nHf/W/75Q5s?= =?us-ascii?Q?YQgGNJfeMSOM8qOxs/C9ZgGQfRaMa1rWMJxPsv/fUyTgPn/Gy1yHM0Z1d7wC?= =?us-ascii?Q?OWeenwDSTcgKHdh067hRlsfVHCJrjV/Gzc1h3N7o1NxNlvFV0e3y/W2YsRWB?= =?us-ascii?Q?m4UmH8rIN8EcZ3tefDMVUvTsxL9rdUPxmcEFJFIdLfvHmIPs0XigBAJrFUcH?= =?us-ascii?Q?VZM9DHjml+pisqNZey2rks5rDDn5xdDNKHNAP93O41FIe0hJ1dZpwMVkg+Z+?= =?us-ascii?Q?X8ZMEmCJIhpzod5HQ1qP5woMZvT7vQGljSjOfentsTtVfvjjqFcG5LdIZ7aQ?= =?us-ascii?Q?BK9XP6q374IxOVwYTCq6mnpziqbbAjHDtpN10v4s9WfPl4QHzEiXI2UdoXXo?= =?us-ascii?Q?d5JqYJljCDjELsaxbn2vBioQVVWGuIZYMF0lBhdaW8do4S2sHKDkRfhA8Q9M?= =?us-ascii?Q?SJwtdqjlpaUYISk/bIBHTUMZVpFF7k3pMJcUmFvEmowoWx4DbuzMLQgOXp19?= =?us-ascii?Q?CnKW3oFgD5SplH+CfhuR3JPxz841jwLZv79GteF5CDWpbUytWGlmRq6S2wyr?= =?us-ascii?Q?3xPpLnwK9VJ6cEoSphX8XTcAQ8oCXiViOp0rl/3Mz5FGWukSAKZfBzvlVHDK?= =?us-ascii?Q?eQYniO5qV46tiXQyDteQNXwH4VFIjaknPAowBxeb2eRvQQLchqtprbkCW3xQ?= =?us-ascii?Q?yjZRIYLSTOPwuSaCv2X7z+RBhdhTUyVz6QSC2yyXfaROtJ9h0yF5C8qmoKp+?= =?us-ascii?Q?qnh/QwTuPRxQP/Cs5polUcD2zqtX5sTFkR1nMNI2QwQ=3D?= Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: BYAPR11MB2901.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 084f99c8-5110-4ebf-fb6d-08d8b2cdf213 X-MS-Exchange-CrossTenant-originalarrivaltime: 07 Jan 2021 05:34:47.0761 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 46c98d88-e344-4ed4-8496-4ed7712e255d X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: XyGP3j6CaI+EvO1A/lXhpjv89mGT7E3ZN54VzKOwPMZgRGQqenyyL5jH1lCShVNVNJijW+H2O0+i5qQD55cR/w== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ0PR11MB5005 X-OriginatorOrg: intel.com Subject: Re: [dpdk-stable] [PATCH v7 4/4] examples/ifpga: add example for opae ifpga API X-BeenThere: stable@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: patches for DPDK stable branches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: stable-bounces@dpdk.org Sender: "stable" Hi Wei, Could you add guide in document to let us know how to run it? Thanks, Rosen > -----Original Message----- > From: Huang, Wei > Sent: Tuesday, January 05, 2021 15:09 > To: dev@dpdk.org; Xu, Rosen ; Zhang, Qi Z > > Cc: stable@dpdk.org; Zhang, Tianfei ; Huang, Wei > > Subject: [PATCH v7 4/4] examples/ifpga: add example for opae ifpga API >=20 > An example application shows how to use opae ifpga APIs. > You can test each API by running corresponding command. >=20 > Signed-off-by: Wei Huang > --- > v2: fix coding style issue in commands.c > --- > examples/ifpga/Makefile | 45 ++ > examples/ifpga/commands.c | 1321 > ++++++++++++++++++++++++++++++++++++ > examples/ifpga/commands.h | 16 + > examples/ifpga/main.c | 38 ++ > examples/ifpga/meson.build | 19 + > 5 files changed, 1439 insertions(+) > create mode 100644 examples/ifpga/Makefile create mode 100644 > examples/ifpga/commands.c create mode 100644 > examples/ifpga/commands.h create mode 100644 examples/ifpga/main.c > create mode 100644 examples/ifpga/meson.build >=20 > diff --git a/examples/ifpga/Makefile b/examples/ifpga/Makefile new file > mode 100644 index 000000000..6bfd5c8b4 > --- /dev/null > +++ b/examples/ifpga/Makefile > @@ -0,0 +1,45 @@ > +# SPDX-License-Identifier: BSD-3-Clause # Copyright(c) 2020-2021 Intel > +Corporation > + > +# binary name > +APP =3D ifpga > + > +# all source are stored in SRCS-y > +SRCS-y :=3D main.c commands.c > + > +# Build using pkg-config variables if possible ifneq ($(shell > +pkg-config --exists libdpdk && echo 0),0) $(error "no installation of > +DPDK found") endif > + > +all: static > +.PHONY: shared static > +shared: build/$(APP)-shared > + ln -sf $(APP)-shared build/$(APP) > +static: build/$(APP)-static > + ln -sf $(APP)-static build/$(APP) > + > +PKGCONF ?=3D pkg-config > + > +PC_FILE :=3D $(shell $(PKGCONF) --path libdpdk 2>/dev/null) CFLAGS +=3D = -O3 > +$(shell $(PKGCONF) --cflags libdpdk) -I../../drivers/raw/ifpga > +LDFLAGS_SHARED =3D $(shell $(PKGCONF) --libs libdpdk) -lrte_bus_pci \ > + -lrte_bus_ifpga -lrte_bus_vdev -lrte_raw_ifpga \ > + -lrte_net_i40e -lrte_net_ipn3ke LDFLAGS_STATIC =3D > +$(shell $(PKGCONF) --static --libs libdpdk) > + > +CFLAGS +=3D -DALLOW_EXPERIMENTAL_API > + > +build/$(APP)-shared: $(SRCS-y) Makefile $(PC_FILE) | build > + $(CC) $(CFLAGS) $(SRCS-y) -o $@ $(LDFLAGS) $(LDFLAGS_SHARED) > + > +build/$(APP)-static: $(SRCS-y) Makefile $(PC_FILE) | build > + $(CC) $(CFLAGS) $(SRCS-y) -o $@ $(LDFLAGS) $(LDFLAGS_STATIC) > + > +build: > + @mkdir -p $@ > + > +.PHONY: clean > +clean: > + rm -f build/$(APP) build/$(APP)-static build/$(APP)-shared > + test -d build && rmdir -p build || true > diff --git a/examples/ifpga/commands.c b/examples/ifpga/commands.c new > file mode 100644 index 000000000..eb2fe1ca6 > --- /dev/null > +++ b/examples/ifpga/commands.c > @@ -0,0 +1,1321 @@ > +/* SPDX-License-Identifier: BSD-3-Clause > + * Copyright(c) 2020-2021 Intel Corporation. > + * All rights reserved. > + */ > + > +#include > +#include > +#include > +#include > +#include > +#include > + > +#include > +#include > +#include > +#include > +#include > + > +#include "commands.h" > + > +static int parse_pciaddr(const char *bdf, opae_pci_device *id) { > + size_t len =3D 0; > + unsigned int domain =3D 0; > + unsigned int bus =3D 0; > + unsigned int devid =3D 0; > + unsigned int function =3D 0; > + > + if (!bdf || !id) > + return -EINVAL; > + > + len =3D strlen(bdf); > + if ((len < 5) || (len > 12)) > + return -EINVAL; > + > + len =3D sscanf(bdf, "%x:%x:%x.%d", &domain, &bus, &devid, > &function); > + if (len =3D=3D 4) { > + snprintf(id->bdf, sizeof(id->bdf), "%04x:%02x:%02x.%d", > + domain, bus, devid, function); > + } else { > + len =3D sscanf(bdf, "%x:%x.%d", &bus, &devid, &function); > + if (len =3D=3D 3) { > + snprintf(id->bdf, sizeof(id->bdf), > "%04x:%02x:%02x.%d", > + 0, bus, devid, function); > + } else { > + return -EINVAL; > + } > + } > + return 0; > +} > + > +static void uuid_to_str(opae_uuid *id, uuid_str *str) { > + uint8_t *b =3D NULL; > + char *p =3D NULL; > + int i, j; > + > + if (!id || !str) > + return; > + > + b =3D &id->b[15]; > + p =3D str->s; > + for (i =3D 0; i < 4; i++, b--, p +=3D 2) > + sprintf(p, "%02x", *b); > + sprintf(p++, "-"); > + for (i =3D 0; i < 3; i++) { > + for (j =3D 0; j < 2; j++, b--, p +=3D 2) > + sprintf(p, "%02x", *b); > + sprintf(p++, "-"); > + } > + for (i =3D 0; i < 6; i++, b--, p +=3D 2) > + sprintf(p, "%02x", *b); > +} > + > +/* *** GET API VERSION *** */ > +struct cmd_version_result { > + cmdline_fixed_string_t cmd; > +}; > + > +static void cmd_version_parsed(__rte_unused void *parsed_result, > + struct cmdline *cl, __rte_unused void *data) { > + opae_api_version ver; > + opae_get_api_version(&ver); > + cmdline_printf(cl, "%d.%d.%d\n", ver.major, ver.minor, ver.micro); } > + > +cmdline_parse_token_string_t cmd_version_cmd =3D > + TOKEN_STRING_INITIALIZER(struct cmd_version_result, cmd, > +"get_api_version"); > + > +cmdline_parse_inst_t cmd_get_api_version =3D { > + .f =3D cmd_version_parsed, > + .data =3D NULL, > + .help_str =3D "get OPAE API version", > + .tokens =3D { > + (void *)&cmd_version_cmd, > + NULL, > + }, > +}; > + > +/* *** GET PROC TYPE *** */ > +struct cmd_proc_type_result { > + cmdline_fixed_string_t cmd; > +}; > + > +static void cmd_proc_type_parsed(__rte_unused void *parsed_result, > + struct cmdline *cl, __rte_unused void *data) { > + int type =3D opae_get_proc_type(); > + > + if (type =3D=3D 0) > + cmdline_printf(cl, "Primary\n"); > + else if (type =3D=3D 1) > + cmdline_printf(cl, "Secondary\n"); > + else > + cmdline_printf(cl, "Unknown\n"); > +} > + > +cmdline_parse_token_string_t cmd_proc_type_cmd =3D > + TOKEN_STRING_INITIALIZER(struct cmd_proc_type_result, cmd, > +"get_proc_type"); > + > +cmdline_parse_inst_t cmd_get_proc_type =3D { > + .f =3D cmd_proc_type_parsed, > + .data =3D NULL, > + .help_str =3D "get DPDK process type", > + .tokens =3D { > + (void *)&cmd_proc_type_cmd, > + NULL, > + }, > +}; > + > +/* *** GET IMAGE INFO *** */ > +struct cmd_image_info_result { > + cmdline_fixed_string_t cmd; > + cmdline_fixed_string_t path; > +}; > + > +static void cmd_image_info_parsed(void *parsed_result, > + struct cmdline *cl, __rte_unused void *data) { > + struct cmd_image_info_result *res =3D parsed_result; > + opae_img_info info; > + > + if (opae_get_image_info(res->path, &info) =3D=3D 0) { > + cmdline_printf(cl, "%-16s", "Type:"); > + if (info.type =3D=3D OPAE_IMG_TYPE_BBS) > + cmdline_printf(cl, "FPGA_BBS\n"); > + else if (info.type =3D=3D OPAE_IMG_TYPE_BMC) > + cmdline_printf(cl, "BMC\n"); > + else if (info.type =3D=3D OPAE_IMG_TYPE_GBS) > + cmdline_printf(cl, "FGPA_GBS\n"); > + else > + cmdline_printf(cl, "Unknown\n"); > + cmdline_printf(cl, "%-16s", "Action:"); > + if (info.subtype =3D=3D OPAE_IMG_SUBTYPE_UPDATE) > + cmdline_printf(cl, "UPDATE\n"); > + else if (info.subtype =3D=3D OPAE_IMG_SUBTYPE_CANCELLATION) > + cmdline_printf(cl, "CANCELLATION\n"); > + else if (info.subtype =3D=3D > OPAE_IMG_SUBTYPE_ROOT_KEY_HASH_256) > + cmdline_printf(cl, "ROOT_HASH_256\n"); > + else if (info.subtype =3D=3D > OPAE_IMG_SUBTYPE_ROOT_KEY_HASH_384) > + cmdline_printf(cl, "ROOT_HASH_384\n"); > + else > + cmdline_printf(cl, "Unknown\n"); > + cmdline_printf(cl, "%-16s%u\n", "Total length:", > + info.total_len); > + cmdline_printf(cl, "%-16s%u\n", "Payload offset:", > + info.payload_offset); > + cmdline_printf(cl, "%-16s%u\n", "Payload length:", > + info.payload_len); > + } else { > + cmdline_printf(cl, "Invalid image file\n"); > + } > +} > + > +cmdline_parse_token_string_t cmd_image_info_cmd =3D > + TOKEN_STRING_INITIALIZER(struct cmd_image_info_result, cmd, > + "get_image_info"); > +cmdline_parse_token_string_t cmd_image_info_path =3D > + TOKEN_STRING_INITIALIZER(struct cmd_image_info_result, path, > NULL); > + > +cmdline_parse_inst_t cmd_get_image_info =3D { > + .f =3D cmd_image_info_parsed, > + .data =3D NULL, > + .help_str =3D "get information of image file", > + .tokens =3D { > + (void *)&cmd_image_info_cmd, > + (void *)&cmd_image_info_path, > + NULL, > + }, > +}; > + > +/* *** GET STATUS *** */ > +struct cmd_get_status_result { > + cmdline_fixed_string_t cmd; > + cmdline_fixed_string_t bdf; > +}; > + > +static void cmd_get_status_parsed(void *parsed_result, > + struct cmdline *cl, __rte_unused void *data) { > + struct cmd_get_status_result *res =3D parsed_result; > + opae_pci_device id; > + uint32_t stat, prog; > + > + if (parse_pciaddr(res->bdf, &id) < 0) { > + cmdline_printf(cl, "%s is invalid PCI address\n", res->bdf); > + return; > + } > + > + if (opae_load_rsu_status(&id, &stat, &prog) =3D=3D 0) { > + cmdline_printf(cl, "%-10s", "Status:"); > + if (stat =3D=3D 0) > + cmdline_printf(cl, "IDLE\n"); > + else if (stat =3D=3D 1) > + cmdline_printf(cl, "PREPARE\n"); > + else if (stat =3D=3D 2) > + cmdline_printf(cl, "PROGRAM\n"); > + else if (stat =3D=3D 3) > + cmdline_printf(cl, "COPY\n"); > + else if (stat =3D=3D 4) > + cmdline_printf(cl, "REBOOT\n"); > + else > + cmdline_printf(cl, "unknown\n"); > + cmdline_printf(cl, "%-10s%u%%\n", "Progress:", prog); > + } else { > + cmdline_printf(cl, "Failed\n"); > + } > +} > + > +cmdline_parse_token_string_t cmd_get_status_cmd =3D > + TOKEN_STRING_INITIALIZER(struct cmd_get_status_result, cmd, > +"get_status"); cmdline_parse_token_string_t cmd_get_status_bdf =3D > + TOKEN_STRING_INITIALIZER(struct cmd_get_status_result, bdf, NULL); > + > +cmdline_parse_inst_t cmd_get_status =3D { > + .f =3D cmd_get_status_parsed, > + .data =3D NULL, > + .help_str =3D "get current status & progress of FPGA", > + .tokens =3D { > + (void *)&cmd_get_status_cmd, > + (void *)&cmd_get_status_bdf, > + NULL, > + }, > +}; > + > +/* *** GET PROPERTY *** */ > +struct cmd_property_result { > + cmdline_fixed_string_t cmd; > + cmdline_fixed_string_t bdf; > + int32_t type; > +}; > + > +static void cmd_property_parsed(void *parsed_result, > + struct cmdline *cl, __rte_unused void *data) { > + struct cmd_property_result *res =3D parsed_result; > + opae_pci_device id; > + opae_fpga_property prop; > + uuid_str str; > + uint32_t port =3D 0; > + > + switch (res->type) { > + case 0: > + case 1: > + case 2: > + case 4: > + case 8: > + break; > + default: > + cmdline_printf(cl, "%d is invalid type of property\n", > + res->type); > + return; > + } > + if (parse_pciaddr(res->bdf, &id) < 0) { > + cmdline_printf(cl, "%s is invalid PCI address\n", res->bdf); > + return; > + } > + > + if (opae_get_property(&id, &prop, res->type) =3D=3D 0) { > + if ((res->type =3D=3D 0) || (res->type =3D=3D 1)) { > + cmdline_printf(cl, "%s:\n", "PCI"); > + cmdline_printf(cl, " %-16s : %s\n", > + "PCIe s:b:d.f", prop.pci.pci_addr); > + cmdline_printf(cl, " %-16s : %s\n", > + "kernel driver", prop.pci.drv_name); > + } > + if ((res->type =3D=3D 0) || (res->type =3D=3D 2)) { > + cmdline_printf(cl, "%s:\n", "FME"); > + cmdline_printf(cl, " %-16s : %s\n", > + "platform", prop.fme.platform_name); > + cmdline_printf(cl, " %-16s : %s\n", > + "DCP version", prop.fme.dcp_version); > + cmdline_printf(cl, " %-16s : %s\n", > + "phase", prop.fme.release_name); > + cmdline_printf(cl, " %-16s : %s\n", > + "interface", prop.fme.interface_type); > + cmdline_printf(cl, " %-16s : %s\n", > + "build version", prop.fme.build_version); > + cmdline_printf(cl, " %-16s : %u\n", > + "ports num", prop.fme.num_ports); > + cmdline_printf(cl, " %-16s : %s\n", > + "boot page", prop.fme.boot_page ? "user" : > "factory"); > + uuid_to_str(&prop.fme.pr_id, &str); > + cmdline_printf(cl, " %-16s : %s\n", "pr interface id", > + str.s); > + } > + if ((res->type =3D=3D 0) || (res->type =3D=3D 4)) { > + for (port =3D 0; port < prop.fme.num_ports; port++) { > + cmdline_printf(cl, "%s%d:\n", "PORT", port); > + cmdline_printf(cl, " %-16s : %s\n", > + "access type", > + prop.port[port].type ? "VF" : "PF"); > + uuid_to_str(&prop.port[port].afu_id, &str); > + cmdline_printf(cl, " %-16s : %s\n", > + "accelerator id", str.s); > + } > + } > + if ((res->type =3D=3D 0) || (res->type =3D=3D 8)) { > + cmdline_printf(cl, "%s:\n", "BMC"); > + cmdline_printf(cl, " %-16s : %s\n", > + "MAX10 version", prop.bmc.bmc_version); > + cmdline_printf(cl, " %-16s : %s\n", > + "NIOS FW version", prop.bmc.fw_version); > + } > + } else { > + cmdline_printf(cl, "Failed\n"); > + } > +} > + > +cmdline_parse_token_string_t cmd_property_cmd =3D > + TOKEN_STRING_INITIALIZER(struct cmd_property_result, cmd, > +"get_property"); cmdline_parse_token_string_t cmd_property_bdf =3D > + TOKEN_STRING_INITIALIZER(struct cmd_property_result, bdf, NULL); > +cmdline_parse_token_num_t cmd_property_type =3D > + TOKEN_NUM_INITIALIZER(struct cmd_property_result, type, > RTE_INT32); > + > +cmdline_parse_inst_t cmd_get_property =3D { > + .f =3D cmd_property_parsed, > + .data =3D NULL, > + .help_str =3D "get property of FPGA", > + .tokens =3D { > + (void *)&cmd_property_cmd, > + (void *)&cmd_property_bdf, > + (void *)&cmd_property_type, > + NULL, > + }, > +}; > + > +/* *** GET PHY INFO *** */ > +struct cmd_phy_info_result { > + cmdline_fixed_string_t cmd; > + cmdline_fixed_string_t bdf; > +}; > + > +static void cmd_phy_info_parsed(void *parsed_result, > + struct cmdline *cl, __rte_unused void *data) { > + struct cmd_phy_info_result *res =3D parsed_result; > + opae_pci_device id; > + opae_phy_info info; > + > + if (parse_pciaddr(res->bdf, &id) < 0) { > + cmdline_printf(cl, "%s is invalid PCI address\n", res->bdf); > + return; > + } > + > + if (opae_get_phy_info(&id, &info) =3D=3D 0) { > + cmdline_printf(cl, " %-16s : %u\n", > + "retimers num", info.num_retimers); > + cmdline_printf(cl, " %-16s : %uG\n", > + "link speed", info.link_speed); > + cmdline_printf(cl, " %-16s : %02x\n", > + "link status", info.link_status); > + } else { > + cmdline_printf(cl, "Failed\n"); > + } > +} > + > +cmdline_parse_token_string_t cmd_phy_info_cmd =3D > + TOKEN_STRING_INITIALIZER(struct cmd_phy_info_result, cmd, > +"get_phy_info"); cmdline_parse_token_string_t cmd_phy_info_bdf =3D > + TOKEN_STRING_INITIALIZER(struct cmd_phy_info_result, bdf, NULL); > + > +cmdline_parse_inst_t cmd_phy_info =3D { > + .f =3D cmd_phy_info_parsed, > + .data =3D NULL, > + .help_str =3D "get information of PHY", > + .tokens =3D { > + (void *)&cmd_phy_info_cmd, > + (void *)&cmd_phy_info_bdf, > + NULL, > + }, > +}; > + > +/* *** GET PARENT *** */ > +struct cmd_parent_result { > + cmdline_fixed_string_t cmd; > + cmdline_fixed_string_t bdf; > +}; > + > +static void cmd_parent_parsed(void *parsed_result, > + struct cmdline *cl, __rte_unused void *data) { > + struct cmd_parent_result *res =3D parsed_result; > + opae_pci_device id; > + opae_pci_device parent; > + > + if (parse_pciaddr(res->bdf, &id) < 0) { > + cmdline_printf(cl, "%s is invalid PCI address\n", res->bdf); > + return; > + } > + > + if (opae_get_parent(&id, &parent) > 0) > + cmdline_printf(cl, "%s\n", parent.bdf); > + else > + cmdline_printf(cl, "Failed\n"); > +} > + > +cmdline_parse_token_string_t cmd_parent_cmd =3D > + TOKEN_STRING_INITIALIZER(struct cmd_parent_result, cmd, > "get_parent"); > +cmdline_parse_token_string_t cmd_parent_bdf =3D > + TOKEN_STRING_INITIALIZER(struct cmd_parent_result, bdf, NULL); > + > +cmdline_parse_inst_t cmd_get_parent =3D { > + .f =3D cmd_parent_parsed, > + .data =3D NULL, > + .help_str =3D "get parent PCI device of FPGA", > + .tokens =3D { > + (void *)&cmd_parent_cmd, > + (void *)&cmd_parent_bdf, > + NULL, > + }, > +}; > + > +/* *** GET CHILD *** */ > +struct cmd_child_result { > + cmdline_fixed_string_t cmd; > + cmdline_fixed_string_t bdf; > +}; > + > +static void cmd_child_parsed(void *parsed_result, > + struct cmdline *cl, __rte_unused void *data) { > + struct cmd_child_result *res =3D parsed_result; > + opae_pci_device id; > + pcidev_id child; > + int i, count =3D 0; > + > + if (parse_pciaddr(res->bdf, &id) < 0) { > + cmdline_printf(cl, "%s is invalid PCI address\n", res->bdf); > + return; > + } > + > + count =3D opae_get_child(&id, NULL, 0); > + if (count > 0) { > + child =3D (pcidev_id)malloc(sizeof(opae_pci_device) * count); > + if (child) { > + opae_get_child(&id, child, count); > + for (i =3D 0; i < count; i++) > + cmdline_printf(cl, "%s\n", child[i].bdf); > + free(child); > + } else { > + cmdline_printf(cl, "No memory\n"); > + } > + } else if (count =3D=3D 0) { > + cmdline_printf(cl, "No child\n"); > + } else { > + cmdline_printf(cl, "Failed\n"); > + } > +} > + > +cmdline_parse_token_string_t cmd_child_cmd =3D > + TOKEN_STRING_INITIALIZER(struct cmd_child_result, cmd, > "get_child"); > +cmdline_parse_token_string_t cmd_child_bdf =3D > + TOKEN_STRING_INITIALIZER(struct cmd_child_result, bdf, NULL); > + > +cmdline_parse_inst_t cmd_get_child =3D { > + .f =3D cmd_child_parsed, > + .data =3D NULL, > + .help_str =3D "get child PCI device of FPGA", > + .tokens =3D { > + (void *)&cmd_child_cmd, > + (void *)&cmd_child_bdf, > + NULL, > + }, > +}; > + > +/* *** GET PF1 *** */ > +struct cmd_pf1_result { > + cmdline_fixed_string_t cmd; > + cmdline_fixed_string_t bdf; > +}; > + > +static void cmd_pf1_parsed(void *parsed_result, > + struct cmdline *cl, __rte_unused void *data) { > + struct cmd_pf1_result *res =3D parsed_result; > + opae_pci_device id; > + pcidev_id peer; > + int i, count =3D 0; > + > + if (parse_pciaddr(res->bdf, &id) < 0) { > + cmdline_printf(cl, "%s is invalid PCI address\n", res->bdf); > + return; > + } > + > + count =3D opae_get_pf1(&id, NULL, 0); > + if (count > 0) { > + peer =3D (pcidev_id)malloc(sizeof(opae_pci_device) * count); > + if (peer) { > + opae_get_pf1(&id, peer, count); > + for (i =3D 0; i < count; i++) > + cmdline_printf(cl, "%s\n", peer[i].bdf); > + free(peer); > + } else { > + cmdline_printf(cl, "No memory\n"); > + } > + } else if (count =3D=3D 0) { > + cmdline_printf(cl, "No PF1\n"); > + } else { > + cmdline_printf(cl, "Failed\n"); > + } > +} > + > +cmdline_parse_token_string_t cmd_pf1_cmd =3D > + TOKEN_STRING_INITIALIZER(struct cmd_pf1_result, cmd, "get_pf1"); > +cmdline_parse_token_string_t cmd_pf1_bdf =3D > + TOKEN_STRING_INITIALIZER(struct cmd_pf1_result, bdf, NULL); > + > +cmdline_parse_inst_t cmd_get_pf1 =3D { > + .f =3D cmd_pf1_parsed, > + .data =3D NULL, > + .help_str =3D "get physical function 1 device of FPGA", > + .tokens =3D { > + (void *)&cmd_pf1_cmd, > + (void *)&cmd_pf1_bdf, > + NULL, > + }, > +}; > + > +/* *** SET LOG LEVEL *** */ > +struct cmd_log_level_result { > + cmdline_fixed_string_t cmd; > + int32_t level; > +}; > + > +static void cmd_log_level_parsed(void *parsed_result, > + struct cmdline *cl, __rte_unused void *data) { > + struct cmd_log_level_result *res =3D parsed_result; > + if (opae_set_log_level(res->level) =3D=3D res->level) > + cmdline_printf(cl, "Successful\n"); > + else > + cmdline_printf(cl, "Failed\n"); > +} > + > +cmdline_parse_token_string_t cmd_log_level_cmd =3D > + TOKEN_STRING_INITIALIZER(struct cmd_log_level_result, cmd, > +"set_log_level"); cmdline_parse_token_num_t cmd_log_level_level =3D > + TOKEN_NUM_INITIALIZER(struct cmd_log_level_result, level, > RTE_INT32); > + > +cmdline_parse_inst_t cmd_set_log_level =3D { > + .f =3D cmd_log_level_parsed, > + .data =3D NULL, > + .help_str =3D "set logging level", > + .tokens =3D { > + (void *)&cmd_log_level_cmd, > + (void *)&cmd_log_level_level, > + NULL, > + }, > +}; > + > +/* *** SET LOG FILE *** */ > +struct cmd_log_file_result { > + cmdline_fixed_string_t cmd; > + cmdline_fixed_string_t path; > +}; > + > +static void cmd_log_file_parsed(void *parsed_result, > + struct cmdline *cl, __rte_unused void *data) { > + struct cmd_log_file_result *res =3D parsed_result; > + if (opae_set_log_file(res->path, 1) =3D=3D 0) > + cmdline_printf(cl, "Successful\n"); > + else > + cmdline_printf(cl, "Failed\n"); > +} > + > +cmdline_parse_token_string_t cmd_log_file_cmd =3D > + TOKEN_STRING_INITIALIZER(struct cmd_log_file_result, cmd, > +"set_log_file"); cmdline_parse_token_string_t cmd_log_file_path =3D > + TOKEN_STRING_INITIALIZER(struct cmd_log_file_result, path, NULL); > + > +cmdline_parse_inst_t cmd_set_log_file =3D { > + .f =3D cmd_log_file_parsed, > + .data =3D NULL, > + .help_str =3D "set logging file", > + .tokens =3D { > + (void *)&cmd_log_file_cmd, > + (void *)&cmd_log_file_path, > + NULL, > + }, > +}; > + > +/* *** SET STATUS *** */ > +struct cmd_set_status_result { > + cmdline_fixed_string_t cmd; > + cmdline_fixed_string_t bdf; > + uint32_t stat; > + uint32_t prog; > +}; > + > +static void cmd_set_status_parsed(void *parsed_result, > + struct cmdline *cl, __rte_unused void *data) { > + struct cmd_set_status_result *res =3D parsed_result; > + opae_pci_device id; > + > + if (parse_pciaddr(res->bdf, &id) < 0) { > + cmdline_printf(cl, "%s is invalid PCI address\n", res->bdf); > + return; > + } > + if ((res->stat > 4) || (res->prog > 100)) { > + cmdline_printf(cl, "%u,%u is invalid status\n", res->stat, > + res->prog); > + return; > + } > + > + if (opae_store_rsu_status(&id, res->stat, res->prog) =3D=3D 0) > + cmdline_printf(cl, "Successful\n"); > + else > + cmdline_printf(cl, "Failed\n"); > +} > + > +cmdline_parse_token_string_t cmd_set_status_cmd =3D > + TOKEN_STRING_INITIALIZER(struct cmd_set_status_result, cmd, > +"set_status"); cmdline_parse_token_string_t cmd_set_status_bdf =3D > + TOKEN_STRING_INITIALIZER(struct cmd_set_status_result, bdf, NULL); > +cmdline_parse_token_num_t cmd_set_status_stat =3D > + TOKEN_NUM_INITIALIZER(struct cmd_set_status_result, stat, > RTE_UINT32); > +cmdline_parse_token_num_t cmd_set_status_prog =3D > + TOKEN_NUM_INITIALIZER(struct cmd_set_status_result, prog, > RTE_UINT32); > + > +cmdline_parse_inst_t cmd_set_status =3D { > + .f =3D cmd_set_status_parsed, > + .data =3D NULL, > + .help_str =3D "set current status & progress of FPGA", > + .tokens =3D { > + (void *)&cmd_set_status_cmd, > + (void *)&cmd_set_status_bdf, > + (void *)&cmd_set_status_stat, > + (void *)&cmd_set_status_prog, > + NULL, > + }, > +}; > + > +/* *** ENUMERATE *** */ > +struct cmd_enumerate_result { > + cmdline_fixed_string_t cmd; > + uint32_t vid; > + uint32_t did; > +}; > + > +static void cmd_enumerate_parsed(void *parsed_result, > + struct cmdline *cl, __rte_unused void *data) { > + struct cmd_enumerate_result *res =3D parsed_result; > + opae_pci_id filter; > + opae_pci_device *id; > + int i, count =3D 0; > + > + filter.vendor_id =3D res->vid; > + filter.device_id =3D res->did; > + filter.class_id =3D BIT_SET_32; > + filter.subsystem_vendor_id =3D BIT_SET_16; > + filter.subsystem_device_id =3D BIT_SET_16; > + > + count =3D opae_enumerate(&filter, NULL, 0); > + if (count > 0) { > + id =3D (opae_pci_device *)malloc(sizeof(opae_pci_device) * > count); > + if (id) { > + opae_enumerate(&filter, id, count); > + for (i =3D 0; i < count; i++) > + cmdline_printf(cl, "%s\n", id[i].bdf); > + free(id); > + } else { > + cmdline_printf(cl, "No memory\n"); > + } > + } else if (count =3D=3D 0) { > + cmdline_printf(cl, "Not found\n"); > + } else { > + cmdline_printf(cl, "Failed\n"); > + } > +} > + > +cmdline_parse_token_string_t cmd_enumerate_cmd =3D > + TOKEN_STRING_INITIALIZER(struct cmd_enumerate_result, cmd, > +"enumerate"); cmdline_parse_token_num_t cmd_enumerate_vid =3D > + TOKEN_NUM_INITIALIZER(struct cmd_enumerate_result, vid, > RTE_UINT32); > +cmdline_parse_token_num_t cmd_enumerate_did =3D > + TOKEN_NUM_INITIALIZER(struct cmd_enumerate_result, did, > RTE_UINT32); > + > +cmdline_parse_inst_t cmd_enumerate =3D { > + .f =3D cmd_enumerate_parsed, > + .data =3D NULL, > + .help_str =3D "enumerate specified FPGA", > + .tokens =3D { > + (void *)&cmd_enumerate_cmd, > + (void *)&cmd_enumerate_vid, > + (void *)&cmd_enumerate_did, > + NULL, > + }, > +}; > + > +/* *** BIND *** */ > +struct cmd_bind_result { > + cmdline_fixed_string_t cmd; > + cmdline_fixed_string_t bdf; > + cmdline_fixed_string_t drv; > +}; > + > +static void cmd_bind_parsed(void *parsed_result, > + struct cmdline *cl, __rte_unused void *data) { > + struct cmd_bind_result *res =3D parsed_result; > + opae_pci_device id; > + > + if (parse_pciaddr(res->bdf, &id) < 0) { > + cmdline_printf(cl, "%s is invalid PCI address\n", res->bdf); > + return; > + } > + > + if (opae_bind_driver(&id, res->drv) =3D=3D 0) > + cmdline_printf(cl, "Successful\n"); > + else > + cmdline_printf(cl, "Failed\n"); > +} > + > +cmdline_parse_token_string_t cmd_bind_cmd =3D > + TOKEN_STRING_INITIALIZER(struct cmd_bind_result, cmd, "bind"); > +cmdline_parse_token_string_t cmd_bind_bdf =3D > + TOKEN_STRING_INITIALIZER(struct cmd_bind_result, bdf, NULL); > +cmdline_parse_token_string_t cmd_bind_drv =3D > + TOKEN_STRING_INITIALIZER(struct cmd_bind_result, drv, NULL); > + > +cmdline_parse_inst_t cmd_bind =3D { > + .f =3D cmd_bind_parsed, > + .data =3D NULL, > + .help_str =3D "bind FPGA with kernel driver", > + .tokens =3D { > + (void *)&cmd_bind_cmd, > + (void *)&cmd_bind_bdf, > + (void *)&cmd_bind_drv, > + NULL, > + }, > +}; > + > +/* *** UNBIND *** */ > +struct cmd_unbind_result { > + cmdline_fixed_string_t cmd; > + cmdline_fixed_string_t bdf; > +}; > + > +static void cmd_unbind_parsed(void *parsed_result, > + struct cmdline *cl, __rte_unused void *data) { > + struct cmd_unbind_result *res =3D parsed_result; > + opae_pci_device id; > + > + if (parse_pciaddr(res->bdf, &id) < 0) { > + cmdline_printf(cl, "%s is invalid PCI address\n", res->bdf); > + return; > + } > + > + if (opae_unbind_driver(&id) =3D=3D 0) > + cmdline_printf(cl, "Successful\n"); > + else > + cmdline_printf(cl, "Failed\n"); > +} > + > +cmdline_parse_token_string_t cmd_unbind_cmd =3D > + TOKEN_STRING_INITIALIZER(struct cmd_bind_result, cmd, "unbind"); > +cmdline_parse_token_string_t cmd_unbind_bdf =3D > + TOKEN_STRING_INITIALIZER(struct cmd_bind_result, bdf, NULL); > + > +cmdline_parse_inst_t cmd_unbind =3D { > + .f =3D cmd_unbind_parsed, > + .data =3D NULL, > + .help_str =3D "unbind FPGA from kernel driver", > + .tokens =3D { > + (void *)&cmd_unbind_cmd, > + (void *)&cmd_unbind_bdf, > + NULL, > + }, > +}; > + > +/* *** PROBE *** */ > +struct cmd_probe_result { > + cmdline_fixed_string_t cmd; > + cmdline_fixed_string_t bdf; > +}; > + > +static void cmd_probe_parsed(void *parsed_result, > + struct cmdline *cl, __rte_unused void *data) { > + struct cmd_probe_result *res =3D parsed_result; > + opae_pci_device id; > + > + if (parse_pciaddr(res->bdf, &id) < 0) { > + cmdline_printf(cl, "%s is invalid PCI address\n", res->bdf); > + return; > + } > + > + if (opae_probe_device(&id) =3D=3D 0) > + cmdline_printf(cl, "Successful\n"); > + else > + cmdline_printf(cl, "Failed\n"); > +} > + > +cmdline_parse_token_string_t cmd_probe_cmd =3D > + TOKEN_STRING_INITIALIZER(struct cmd_probe_result, cmd, "probe"); > +cmdline_parse_token_string_t cmd_probe_bdf =3D > + TOKEN_STRING_INITIALIZER(struct cmd_probe_result, bdf, NULL); > + > +cmdline_parse_inst_t cmd_probe =3D { > + .f =3D cmd_probe_parsed, > + .data =3D NULL, > + .help_str =3D "probe FPGA with IFPGA driver", > + .tokens =3D { > + (void *)&cmd_probe_cmd, > + (void *)&cmd_probe_bdf, > + NULL, > + }, > +}; > + > +/* *** REMOVE *** */ > +struct cmd_remove_result { > + cmdline_fixed_string_t cmd; > + cmdline_fixed_string_t bdf; > +}; > + > +static void cmd_remove_parsed(void *parsed_result, > + struct cmdline *cl, __rte_unused void *data) { > + struct cmd_remove_result *res =3D parsed_result; > + opae_pci_device id; > + > + if (parse_pciaddr(res->bdf, &id) < 0) { > + cmdline_printf(cl, "%s is invalid PCI address\n", res->bdf); > + return; > + } > + > + if (opae_remove_device(&id) =3D=3D 0) > + cmdline_printf(cl, "Successful\n"); > + else > + cmdline_printf(cl, "Failed\n"); > +} > + > +cmdline_parse_token_string_t cmd_remove_cmd =3D > + TOKEN_STRING_INITIALIZER(struct cmd_remove_result, cmd, > "remove"); > +cmdline_parse_token_string_t cmd_remove_bdf =3D > + TOKEN_STRING_INITIALIZER(struct cmd_remove_result, bdf, NULL); > + > +cmdline_parse_inst_t cmd_remove =3D { > + .f =3D cmd_remove_parsed, > + .data =3D NULL, > + .help_str =3D "remove FPGA from IFPGA driver", > + .tokens =3D { > + (void *)&cmd_remove_cmd, > + (void *)&cmd_remove_bdf, > + NULL, > + }, > +}; > + > +/* *** FLASH *** */ > +struct cmd_flash_result { > + cmdline_fixed_string_t cmd; > + cmdline_fixed_string_t bdf; > + cmdline_fixed_string_t path; > +}; > + > +static void cmd_flash_parsed(void *parsed_result, > + struct cmdline *cl, __rte_unused void *data) { > + struct cmd_flash_result *res =3D parsed_result; > + opae_pci_device id; > + uint64_t stat =3D 0; > + > + if (parse_pciaddr(res->bdf, &id) < 0) { > + cmdline_printf(cl, "%s is invalid PCI address\n", res->bdf); > + return; > + } > + > + if (opae_update_flash(&id, res->path, &stat)) > + cmdline_printf(cl, "Error: 0x%lx\n", stat); } > + > +cmdline_parse_token_string_t cmd_flash_cmd =3D > + TOKEN_STRING_INITIALIZER(struct cmd_flash_result, cmd, "flash"); > +cmdline_parse_token_string_t cmd_flash_bdf =3D > + TOKEN_STRING_INITIALIZER(struct cmd_flash_result, bdf, NULL); > +cmdline_parse_token_string_t cmd_flash_path =3D > + TOKEN_STRING_INITIALIZER(struct cmd_flash_result, path, NULL); > + > +cmdline_parse_inst_t cmd_flash =3D { > + .f =3D cmd_flash_parsed, > + .data =3D NULL, > + .help_str =3D "update flash of FPGA", > + .tokens =3D { > + (void *)&cmd_flash_cmd, > + (void *)&cmd_flash_bdf, > + (void *)&cmd_flash_path, > + NULL, > + }, > +}; > + > +/* *** PR *** */ > +struct cmd_pr_result { > + cmdline_fixed_string_t cmd; > + cmdline_fixed_string_t bdf; > + int32_t port; > + cmdline_fixed_string_t path; > +}; > + > +static void cmd_pr_parsed(void *parsed_result, > + struct cmdline *cl, __rte_unused void *data) { > + struct cmd_pr_result *res =3D parsed_result; > + opae_pci_device id; > + > + if (parse_pciaddr(res->bdf, &id) < 0) { > + cmdline_printf(cl, "%s is invalid PCI address\n", res->bdf); > + return; > + } > + > + if (opae_partial_reconfigure(&id, res->port, res->path) =3D=3D 0) > + cmdline_printf(cl, "Successful\n"); > + else > + cmdline_printf(cl, "Failed\n"); > +} > + > +cmdline_parse_token_string_t cmd_pr_cmd =3D > + TOKEN_STRING_INITIALIZER(struct cmd_pr_result, cmd, "pr"); > +cmdline_parse_token_string_t cmd_pr_bdf =3D > + TOKEN_STRING_INITIALIZER(struct cmd_pr_result, bdf, NULL); > +cmdline_parse_token_num_t cmd_pr_port =3D > + TOKEN_NUM_INITIALIZER(struct cmd_pr_result, port, RTE_INT32); > +cmdline_parse_token_string_t cmd_pr_path =3D > + TOKEN_STRING_INITIALIZER(struct cmd_pr_result, path, NULL); > + > +cmdline_parse_inst_t cmd_pr =3D { > + .f =3D cmd_pr_parsed, > + .data =3D NULL, > + .help_str =3D "partial reconfigure FPGA", > + .tokens =3D { > + (void *)&cmd_pr_cmd, > + (void *)&cmd_pr_bdf, > + (void *)&cmd_pr_port, > + (void *)&cmd_pr_path, > + NULL, > + }, > +}; > + > +/* *** REBOOT *** */ > +struct cmd_reboot_result { > + cmdline_fixed_string_t cmd; > + cmdline_fixed_string_t bdf; > + cmdline_fixed_string_t type; > + int32_t page; > +}; > + > +static void cmd_reboot_parsed(void *parsed_result, > + struct cmdline *cl, __rte_unused void *data) { > + struct cmd_reboot_result *res =3D parsed_result; > + opae_pci_device id; > + int type =3D 0; > + > + if (parse_pciaddr(res->bdf, &id) < 0) { > + cmdline_printf(cl, "%s is invalid PCI address\n", res->bdf); > + return; > + } > + > + if (!strcmp(res->type, "fpga")) { > + type =3D 0; > + } else if (!strcmp(res->type, "bmc")) { > + type =3D 1; > + } else { > + cmdline_printf(cl, "%s is invalid reboot type\n", res->type); > + return; > + } > + > + if (opae_reboot_device(&id, type, res->page) =3D=3D 0) > + cmdline_printf(cl, "Successful\n"); > + else > + cmdline_printf(cl, "Failed\n"); > +} > + > +cmdline_parse_token_string_t cmd_reboot_cmd =3D > + TOKEN_STRING_INITIALIZER(struct cmd_reboot_result, cmd, > "reboot"); > +cmdline_parse_token_string_t cmd_reboot_bdf =3D > + TOKEN_STRING_INITIALIZER(struct cmd_reboot_result, bdf, NULL); > +cmdline_parse_token_string_t cmd_reboot_type =3D > + TOKEN_STRING_INITIALIZER(struct cmd_reboot_result, type, NULL); > +cmdline_parse_token_num_t cmd_reboot_page =3D > + TOKEN_NUM_INITIALIZER(struct cmd_reboot_result, page, > RTE_INT32); > + > +cmdline_parse_inst_t cmd_reboot =3D { > + .f =3D cmd_reboot_parsed, > + .data =3D NULL, > + .help_str =3D "reboot FPGA or MAX10", > + .tokens =3D { > + (void *)&cmd_reboot_cmd, > + (void *)&cmd_reboot_bdf, > + (void *)&cmd_reboot_type, > + (void *)&cmd_reboot_page, > + NULL, > + }, > +}; > + > +/* *** CANCEL *** */ > +struct cmd_cancel_result { > + cmdline_fixed_string_t cmd; > + cmdline_fixed_string_t bdf; > +}; > + > +static void cmd_cancel_parsed(void *parsed_result, > + struct cmdline *cl, __rte_unused void *data) { > + struct cmd_cancel_result *res =3D parsed_result; > + opae_pci_device id; > + > + if (parse_pciaddr(res->bdf, &id) < 0) { > + cmdline_printf(cl, "%s is invalid PCI address\n", res->bdf); > + return; > + } > + > + if (opae_cancel_flash_update(&id, 0) =3D=3D 0) > + cmdline_printf(cl, "Successful\n"); > + else > + cmdline_printf(cl, "Failed\n"); > +} > + > +cmdline_parse_token_string_t cmd_cancel_cmd =3D > + TOKEN_STRING_INITIALIZER(struct cmd_cancel_result, cmd, "cancel"); > +cmdline_parse_token_string_t cmd_cancel_bdf =3D > + TOKEN_STRING_INITIALIZER(struct cmd_cancel_result, bdf, NULL); > + > +cmdline_parse_inst_t cmd_cancel =3D { > + .f =3D cmd_cancel_parsed, > + .data =3D NULL, > + .help_str =3D "cancel flash update", > + .tokens =3D { > + (void *)&cmd_cancel_cmd, > + (void *)&cmd_cancel_bdf, > + NULL, > + }, > +}; > + > +/* *** CHECK *** */ > +struct cmd_check_result { > + cmdline_fixed_string_t cmd; > +}; > + > +static void cmd_check_parsed(__rte_unused void *parsed_result, > + __rte_unused struct cmdline *cl, __rte_unused void *data) { > + opae_check_pcidev_list(); > +} > + > +cmdline_parse_token_string_t cmd_check_cmd =3D > + TOKEN_STRING_INITIALIZER(struct cmd_check_result, cmd, "check"); > + > +cmdline_parse_inst_t cmd_check =3D { > + .f =3D cmd_check_parsed, > + .data =3D NULL, > + .help_str =3D "display list of PCI devices", > + .tokens =3D { > + (void *)&cmd_check_cmd, > + NULL, > + }, > +}; > + > +/* *** PCI READ *** */ > +struct cmd_pci_read_result { > + cmdline_fixed_string_t cmd; > + cmdline_fixed_string_t bdf; > + uint32_t offset; > +}; > + > +static void cmd_pci_read_parsed(void *parsed_result, > + struct cmdline *cl, __rte_unused void *data) { > + struct cmd_pci_read_result *res =3D parsed_result; > + opae_pci_device id; > + uint32_t offset =3D 0; > + uint32_t value =3D 0; > + > + if (parse_pciaddr(res->bdf, &id) < 0) { > + cmdline_printf(cl, "%s is invalid PCI address\n", res->bdf); > + return; > + } > + > + if (res->offset & 0x3) { > + offset =3D res->offset & ~3; > + cmdline_printf(cl, "align offset to 0x%x\n", offset); > + } else { > + offset =3D res->offset; > + } > + > + if (opae_read_pci_cfg(&id, offset, &value) =3D=3D 0) > + cmdline_printf(cl, "0x%08x\n", value); > + else > + cmdline_printf(cl, "Failed\n"); > +} > + > +cmdline_parse_token_string_t cmd_pci_read_cmd =3D > + TOKEN_STRING_INITIALIZER(struct cmd_pci_read_result, cmd, > "pci_read"); > +cmdline_parse_token_string_t cmd_pci_read_bdf =3D > + TOKEN_STRING_INITIALIZER(struct cmd_pci_read_result, bdf, NULL); > +cmdline_parse_token_num_t cmd_pci_read_offset =3D > + TOKEN_NUM_INITIALIZER(struct cmd_pci_read_result, offset, > RTE_UINT32); > + > +cmdline_parse_inst_t cmd_pci_read =3D { > + .f =3D cmd_pci_read_parsed, > + .data =3D NULL, > + .help_str =3D "read PCI configuration space", > + .tokens =3D { > + (void *)&cmd_pci_read_cmd, > + (void *)&cmd_pci_read_bdf, > + (void *)&cmd_pci_read_offset, > + NULL, > + }, > +}; > + > +/* *** PCI WRITE *** */ > +struct cmd_pci_write_result { > + cmdline_fixed_string_t cmd; > + cmdline_fixed_string_t bdf; > + uint32_t offset; > + uint32_t value; > +}; > + > +static void cmd_pci_write_parsed(void *parsed_result, > + struct cmdline *cl, __rte_unused void *data) { > + struct cmd_pci_write_result *res =3D parsed_result; > + opae_pci_device id; > + uint32_t offset =3D 0; > + > + if (parse_pciaddr(res->bdf, &id) < 0) { > + cmdline_printf(cl, "%s is invalid PCI address\n", res->bdf); > + return; > + } > + > + if (res->offset & 0x3) { > + offset =3D res->offset & ~3; > + cmdline_printf(cl, "align offset to 0x%x\n", offset); > + } else { > + offset =3D res->offset; > + } > + > + if (opae_write_pci_cfg(&id, offset, res->value) =3D=3D 0) > + cmdline_printf(cl, "Successful\n"); > + else > + cmdline_printf(cl, "Failed\n"); > +} > + > +cmdline_parse_token_string_t cmd_pci_write_cmd =3D > + TOKEN_STRING_INITIALIZER(struct cmd_pci_write_result, cmd, > +"pci_write"); cmdline_parse_token_string_t cmd_pci_write_bdf =3D > + TOKEN_STRING_INITIALIZER(struct cmd_pci_write_result, bdf, NULL); > +cmdline_parse_token_num_t cmd_pci_write_offset =3D > + TOKEN_NUM_INITIALIZER(struct cmd_pci_write_result, offset, > +RTE_UINT32); cmdline_parse_token_num_t cmd_pci_write_value =3D > + TOKEN_NUM_INITIALIZER(struct cmd_pci_write_result, value, > RTE_UINT32); > + > +cmdline_parse_inst_t cmd_pci_write =3D { > + .f =3D cmd_pci_write_parsed, > + .data =3D NULL, > + .help_str =3D "write PCI configuration space", > + .tokens =3D { > + (void *)&cmd_pci_write_cmd, > + (void *)&cmd_pci_write_bdf, > + (void *)&cmd_pci_write_offset, > + (void *)&cmd_pci_write_value, > + NULL, > + }, > +}; > + > +/* *** QUIT *** */ > +struct cmd_quit_result { > + cmdline_fixed_string_t quit; > +}; > + > +static void cmd_quit_parsed(__rte_unused void *parsed_result, > + struct cmdline *cl, __rte_unused void *data) { > + cmdline_quit(cl); > +} > + > +cmdline_parse_token_string_t cmd_quit_quit =3D > + TOKEN_STRING_INITIALIZER(struct cmd_quit_result, quit, "quit"); > + > +cmdline_parse_inst_t cmd_quit =3D { > + .f =3D cmd_quit_parsed, > + .data =3D NULL, > + .help_str =3D "exit DPDK application", > + .tokens =3D { > + (void *)&cmd_quit_quit, > + NULL, > + }, > +}; > + > +/* *** HELP *** */ > +struct cmd_help_result { > + cmdline_fixed_string_t help; > +}; > + > +static void cmd_help_parsed(__rte_unused void *parsed_result, > + struct cmdline *cl, __rte_unused void *data) { > + cmdline_printf(cl, > + " get_api_version \t\t" > + "get OPAE API version\n" > + " get_proc_type \t\t" > + "get DPDK process type\n" > + " get_image_info \t\t" > + "get information of image file\n" > + " get_status \t\t" > + "get current status & progress of FPGA\n" > + " get_property <0|1|2|4|8>\t\t" > + "get property of FPGA\n" > + " get_phy_info \t\t" > + "get information of PHY\n" > + " get_parent \t\t" > + "get parent PCI device of FPGA\n" > + " get_child \t\t" > + "get child PCI device of FPGA\n" > + " get_pf1 \t\t" > + "get physical function 1 device of FPGA\n" > + " set_log_level <0-4> \t\t" > + "set logging level\n" > + " set_log_file \t\t" > + "set logging file\n" > + " set_status <0-4> <0-100>\t\t" > + "set current status & progress of FPGA\n" > + " enumerate \t\t" > + "enumerate specified FPGA\n" > + " bind \t\t" > + "bind FPGA with kernel driver\n" > + " unbind \t\t" > + "unbind FPGA from kernel driver\n" > + " probe \t\t" > + "probe FPGA with IFPGA driver\n" > + " remove \t\t" > + "remove FPGA from IFPGA driver\n" > + " flash \t\t" > + "update flash of FPGA\n" > + " pr \t\t" > + "partial reconfigure FPGA\n" > + " reboot <0-1> \t\t" > + "reboot FPGA or MAX10\n" > + " cancel \t\t" > + "cancel flash update\n" > + " check \t\t" > + "display list of PCI devices\n" > + " pci_read <0-1024> \t\t" > + "read PCI configuration space\n" > + " pci_write <0-1024> \t\t" > + "write PCI configuration space\n" > + " quit \t\t" > + "exit DPDK application\n" > + " help \t\t" > + "show commands list\n"); > +} > + > +cmdline_parse_token_string_t cmd_help_help =3D > + TOKEN_STRING_INITIALIZER(struct cmd_help_result, help, "help"); > + > +cmdline_parse_inst_t cmd_help =3D { > + .f =3D cmd_help_parsed, > + .data =3D NULL, > + .help_str =3D "show commands list", > + .tokens =3D { > + (void *)&cmd_help_help, > + NULL, > + }, > +}; > + > +/****** CONTEXT (list of commands) */ > +cmdline_parse_ctx_t main_ctx[] =3D { > + (cmdline_parse_inst_t *)&cmd_get_image_info, > + (cmdline_parse_inst_t *)&cmd_get_api_version, > + (cmdline_parse_inst_t *)&cmd_get_proc_type, > + (cmdline_parse_inst_t *)&cmd_get_status, > + (cmdline_parse_inst_t *)&cmd_get_property, > + (cmdline_parse_inst_t *)&cmd_phy_info, > + (cmdline_parse_inst_t *)&cmd_get_parent, > + (cmdline_parse_inst_t *)&cmd_get_child, > + (cmdline_parse_inst_t *)&cmd_get_pf1, > + (cmdline_parse_inst_t *)&cmd_set_log_level, > + (cmdline_parse_inst_t *)&cmd_set_log_file, > + (cmdline_parse_inst_t *)&cmd_set_status, > + (cmdline_parse_inst_t *)&cmd_enumerate, > + (cmdline_parse_inst_t *)&cmd_bind, > + (cmdline_parse_inst_t *)&cmd_unbind, > + (cmdline_parse_inst_t *)&cmd_probe, > + (cmdline_parse_inst_t *)&cmd_remove, > + (cmdline_parse_inst_t *)&cmd_flash, > + (cmdline_parse_inst_t *)&cmd_pr, > + (cmdline_parse_inst_t *)&cmd_reboot, > + (cmdline_parse_inst_t *)&cmd_cancel, > + (cmdline_parse_inst_t *)&cmd_check, > + (cmdline_parse_inst_t *)&cmd_pci_read, > + (cmdline_parse_inst_t *)&cmd_pci_write, > + (cmdline_parse_inst_t *)&cmd_quit, > + (cmdline_parse_inst_t *)&cmd_help, > + NULL, > +}; > diff --git a/examples/ifpga/commands.h b/examples/ifpga/commands.h new > file mode 100644 index 000000000..76c4c5025 > --- /dev/null > +++ b/examples/ifpga/commands.h > @@ -0,0 +1,16 @@ > +/* SPDX-License-Identifier: BSD-3-Clause > + * Copyright(c) 2020-2021 Intel Corporation */ > + > +#ifndef _COMMANDS_H_ > +#define _COMMANDS_H_ > + > +#include "ifpga_opae_api.h" > + > +extern cmdline_parse_ctx_t main_ctx[]; > + > +typedef struct { > + char s[38]; > +} uuid_str; > + > +#endif /* _COMMANDS_H_ */ > diff --git a/examples/ifpga/main.c b/examples/ifpga/main.c new file mode > 100644 index 000000000..e9380d581 > --- /dev/null > +++ b/examples/ifpga/main.c > @@ -0,0 +1,38 @@ > +/* SPDX-License-Identifier: BSD-3-Clause > + * Copyright(c) 2020-2021 Intel Corporation */ > + > +#include > +#include > +#include > +#include > +#include > + > +#include > +#include > +#include > +#include > + > +#include > +#include > +#include > + > +#include "commands.h" > + > + > +int main(int argc, char **argv) > +{ > + struct cmdline *cl; > + int ret; > + > + ret =3D opae_init_eal(argc, argv); > + if (ret < 0) > + rte_panic("Cannot init EAL\n"); > + cl =3D cmdline_stdin_new(main_ctx, "opae> "); > + if (cl =3D=3D NULL) > + rte_panic("Cannot create cmdline instance\n"); > + cmdline_interact(cl); > + opae_cleanup_eal(); > + cmdline_stdin_exit(cl); > + return 0; > +} > diff --git a/examples/ifpga/meson.build b/examples/ifpga/meson.build new > file mode 100644 index 000000000..9077a7bb2 > --- /dev/null > +++ b/examples/ifpga/meson.build > @@ -0,0 +1,19 @@ > +# SPDX-License-Identifier: BSD-3-Clause # Copyright(c) 2020-2021 Intel > +Corporation > + > +# meson file, for building this example as part of a main DPDK build. > +# > +# To build this example as a standalone application with an > +already-installed # DPDK instance, use 'make' > + > +# require the raw_ifpga library > +build =3D dpdk_conf.has('RTE_RAW_IFPGA') > +if not build > + subdir_done() > +endif > + > +deps +=3D 'raw_ifpga' > +allow_experimental_apis =3D true > +sources =3D files( > + 'main.c', 'commands.c' > +) > -- > 2.29.2