From patchwork Thu Oct 20 21:26:07 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Gerlach X-Patchwork-Id: 6408 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4242:0:0:0:0:0 with SMTP id s2csp331269wrr; Thu, 20 Oct 2022 14:27:52 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5qDiGLfkd9HaSdEA01ziRIK3fZx5DrwrPK6yGvB5Nqu6ohMGxyoJ60BQxh1r3/n9uq5E5x X-Received: by 2002:a05:6402:22ed:b0:458:bcd1:69cf with SMTP id dn13-20020a05640222ed00b00458bcd169cfmr14274507edb.260.1666301272714; Thu, 20 Oct 2022 14:27:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666301272; cv=none; d=google.com; s=arc-20160816; b=tCVeq1jmffY8dPOx98IK7bl69UlSLS+IHeB3v3JumqbYVoi1V4/UKj3JgRCqNdBFkn qDVezm4ZdZv5pZvHCzMnOnPR345xf0IZl0wwQprIFZihx1Riec8cCdrhZ+zjyBH4ULyj I8GUar4Dp/mOgMWlByaOkMq3YVGj+dXhCA1YF23uJDlLZwL8+EdXgxqy1c2KXF9Cr+ui dGxnqaoJc4dX8rnaFulheQ1ZY5u2RJ0IE3YC4DLdzCF/UjuvVIfLxBfDw20yPp2fWceO 19/+XyCIa5kpWPpv1SvHsr4vwOiWLmaUvpn4uFpZrKlYm/LbKZfWP4pbpsRDrcpJftA5 Xy4Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=huri9rrcz2rcBxJLCMVfdz6h2hmy3wPSBMgoE22S0JU=; b=SmnN4M3HMNDLEcJ965W9vdzpEQeuRcUbOxU+3n3WwKFVb15By2pkatRa2o2fZ7DMpN fLeYd03D/hfWYaF0E2rO743hiRaiebXHuTlVPUo1/YSfiiZZ71DvQE/QuHqS7zOzjv66 GVSzjS54hyajsGtOdrYZJcPRlVVvqB26wi6xfg+AxM1ohnz5udzmKGypbBEaeayNulnt t26ri8SI35TESWbsY24DzpIIuqxpc/4XGPNAYLf2naTsPod3Xf91HhpuJ4ps78qy1JRn DJHy1xIb1iSxD+FJgUE/ES3s+399a9Y1821bT+/+eFyCrP3kB+KJVzqLuK8i5bKlBn3t 5uXA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=Q8CX7EOj; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id bx13-20020a0564020b4d00b0046107f951f9si1581027edb.237.2022.10.20.14.27.28; Thu, 20 Oct 2022 14:27:52 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=Q8CX7EOj; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229862AbiJTV0F (ORCPT + 99 others); Thu, 20 Oct 2022 17:26:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38582 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229606AbiJTVZ6 (ORCPT ); Thu, 20 Oct 2022 17:25:58 -0400 Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 43B6718058A; Thu, 20 Oct 2022 14:25:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1666301157; x=1697837157; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=G4RA3fXWPYCO6YJlAhmqw1zonueFqiUc6ye2HSURtV8=; b=Q8CX7EOj0wKtpifLQcaU/nGuiXLDM6luqvpIgPJmS8z/fvDSfW30e7vq C2Tw6HB3vZBLgoa+xrJfkpNoSb/uIfHFpQfuSkwbm5jT7GX3xuXo8ugaI CpZRDpqoBjwjq9L9LXy0DhNUobfOlMmfmLWt3iAlvHGBume2f102TbEPl 9/E9zgDb410Snlyp0PAkZHTYsh/jgDjgD2iG9GBV1Tf9XEr/nZE3JasJJ MKllmluvdcJ/8FoI1v7sfPpQly+xJtbW/TnMAPCyIZc+HwXk+tUpB15Vc tIZeYNySR+Rmh7PEIxdxuCuVs8FjTtEyfjDbe5X1oEcpIKXXyac9TNKIw Q==; X-IronPort-AV: E=McAfee;i="6500,9779,10506"; a="333412432" X-IronPort-AV: E=Sophos;i="5.95,199,1661842800"; d="scan'208";a="333412432" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 Oct 2022 14:25:56 -0700 X-IronPort-AV: E=McAfee;i="6500,9779,10506"; a="693260670" X-IronPort-AV: E=Sophos;i="5.95,199,1661842800"; d="scan'208";a="693260670" Received: from rhweight-wrk1.ra.intel.com ([137.102.106.139]) by fmsmga008-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 Oct 2022 14:25:55 -0700 From: matthew.gerlach@linux.intel.com To: hao.wu@intel.com, yilun.xu@intel.com, russell.h.weight@intel.com, basheer.ahmed.muddebihal@intel.com, trix@redhat.com, mdf@kernel.org, linux-fpga@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, tianfei.zhang@intel.com, corbet@lwn.net, gregkh@linuxfoundation.org, linux-serial@vger.kernel.org, jirislaby@kernel.org, geert+renesas@glider.be, andriy.shevchenko@linux.intel.com, niklas.soderlund+renesas@ragnatech.se, macro@orcam.me.uk, johan@kernel.org, lukas@wunner.de, ilpo.jarvinen@linux.intel.com, marpagan@redhat.com Cc: Matthew Gerlach Subject: [PATCH v4 1/4] Documentation: fpga: dfl: Add documentation for DFHv1 Date: Thu, 20 Oct 2022 14:26:07 -0700 Message-Id: <20221020212610.697729-2-matthew.gerlach@linux.intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221020212610.697729-1-matthew.gerlach@linux.intel.com> References: <20221020212610.697729-1-matthew.gerlach@linux.intel.com> MIME-Version: 1.0 X-Spam-Status: No, score=-7.2 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE, URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747243523488427006?= X-GMAIL-MSGID: =?utf-8?q?1747243523488427006?= From: Matthew Gerlach Add documentation describing the extensions provided by Version 1 of the Device Feature Header (DFHv1). Signed-off-by: Matthew Gerlach --- v4: Remove marketing speak and separate v0 and v1 descriptions. Fix errors reported by "make htmldocs". v3: no change v2: s/GUILD/GUID/ add picture --- Documentation/fpga/dfl.rst | 96 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 96 insertions(+) diff --git a/Documentation/fpga/dfl.rst b/Documentation/fpga/dfl.rst index 15b670926084..12365be435a8 100644 --- a/Documentation/fpga/dfl.rst +++ b/Documentation/fpga/dfl.rst @@ -561,6 +561,102 @@ new DFL feature via UIO direct access, its feature id should be added to the driver's id_table. +Device Feature Header - Version 0 +=========================================== +The format of Version 0 of a Device Feature Header (DFH) is shown below:: + + +-----------------------------------------------------------------------+ + |63 Type 60|59 DFH VER 52|51 Rsvd 41|40 EOL|39 Next 16|15 VER 12|11 ID 0| 0x00 + +-----------------------------------------------------------------------+ + |63 GUID_L 0| 0x08 + +-----------------------------------------------------------------------+ + |63 GUID_H 0| 0x10 + +-----------------------------------------------------------------------+ + +Offset 0x00 +Type - The type of DFH (e.g. FME, AFU, or private feature). +DFH VER - The version of the DFH. +Rsvd - Currently unused. +EOL - Set if this DFH is the end of the Device Feature List (DFL). +Next - The offset of the next DFH in the DFL from the start of the DFH. +If EOL is set, Next refers to size of mmio for last feature in the list. +ID - If Type field is 'private feature', then ID of the private feature. + +Offset 0x08 +GUID_L - Least significant 64 bits of a 128 bit Globally Unique Identifier +if Type is FME or AFU. + +Offset 0x10 +GUID_H - Most significant 64 bits of a 128 bit Globally Unique Identifier +if Type is FME or AFU. + + +Device Feature Header - Version 1 +=========================================== +The format of Version 1 of a Device Feature Header (DFH) is shown below:: + + +-----------------------------------------------------------------------+ + |63 Type 60|59 DFH VER 52|51 Rsvd 41|40 EOL|39 Next 16|15 VER 12|11 ID 0| 0x00 + +-----------------------------------------------------------------------+ + |63 GUID_L 0| 0x08 + +-----------------------------------------------------------------------+ + |63 GUID_H 0| 0x10 + +-----------------------------------------------------------------------+ + |63 Address/Offset 1| Rel 0| 0x18 + +-----------------------------------------------------------------------+ + |63 Reg Size 32|Params 31|30 Group 16|15 Instance 0| 0x20 + +-----------------------------------------------------------------------+ + |63 Next 34|RSV33|EOP32|31 Param Version 16|15 Param ID 0| 0x28 + +-----------------------------------------------------------------------+ + |63 Parameter Data 0| 0x30 + +-----------------------------------------------------------------------+ + + ... + + +-----------------------------------------------------------------------+ + |63 Next parameter offset 32|31 Param Version 16|15 Param ID 0| + +-----------------------------------------------------------------------+ + |63 Parameter Data 0| + +-----------------------------------------------------------------------+ + +Offset 0x00 +Type - The type of DFH (e.g. FME, AFU, or private feature). +DFH VER - The version of the DFH. +Rsvd - Currently unused. +EOL - Set if this DFH is the end of the Device Feature List (DFL). +Next - The offset of the next DFH in the DFL from the start of the DFH. +If EOL is set, Next refers to size of mmio for last feature in the list. +ID - If Type field is 'private feature', then ID of the private feature. + +Offset 0x08 +GUID_L - Least significant 64 bits of a 128 bit Globally Unique Identifier. + +Offset 0x10 +GUID_H - Most significant 64 bits of a 128 bit Globally Unique Identifier +if Type is FME or AFU. + +Offset 0x18 +Address/Offset - If Rel bit is set, then high 63 bits of a 16 bit aligned +absolute address for the location of the feature's registers. +If Rel bit is clear, then the feature's registers start at the +offset from the start of the DFH. + +Offset 0x20 +Reg Size - Size of feature's register set. +Params - Set if DFH has one or more parameter blocks. +Group - Id of group if feature is part of a group. +Instance - Id of instance of feature within a group. + +Offset 0x28 if feature has parameters +Next - High 30 bits of a 32 bit aligned offset to the next parameter block. +If EOP set, size of last parameter. +Param Version - Version of Param ID. +Param ID - ID of parameter. + +Offset 0x30 +Parameter Data - Parameter data whose size and format is defined by version +and ID of the parameter. + Open discussion =============== FME driver exports one ioctl (DFL_FPGA_FME_PORT_PR) for partial reconfiguration From patchwork Thu Oct 20 21:26:08 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Gerlach X-Patchwork-Id: 6413 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4242:0:0:0:0:0 with SMTP id s2csp331726wrr; Thu, 20 Oct 2022 14:29:48 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6lKyqIcjkWZdQ6odj/KmNQ0BFouPVgU5zwUjU9SlC3U45G7S/p8RMpY1SljFtAjMtnxeki X-Received: by 2002:a17:907:969e:b0:791:9ba2:497f with SMTP id hd30-20020a170907969e00b007919ba2497fmr12791845ejc.8.1666301388551; Thu, 20 Oct 2022 14:29:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666301388; cv=none; d=google.com; s=arc-20160816; b=uzhdxHckpqpHkHbhJdiAuT4HAciBi8R9JAen9L1fJ8Xaruy2RY7IHHXRKic7KpEFlR jy+ynX6Y6FO/c1i2sbXomvwYAzx3hdVpuEcNKyW6+psxbKTE0QP0mzqAIXJqSF9stXmI goXCtgwl+672W+LkZv43HOJu6w0XUawnOZznrC752bA3uSbKdyQQEI0pxpBF3ocDlzry pESZuNvy0AwGPfRiMa93OpMIsjgJV5qI+Kylnh+c6RnikrZAlAmjxEr2Q70VXzdz5KF+ qgIYfQWr5yo6Qm7vLgTdWsC2ZCUhlEZuHvJ5BiC+KbmBCnp1sTesSerdJ1Y5JkRUc6Zm n9Fw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=k1SYlFF99Fa1NASTXLdai3DtcJAPpMdMYHqXx+ijgE0=; b=LRAy6a9YzvchNwA0i2KiujQgTj6EbNzPqXgO9o3pJup15+SOWjpCNbCcrhe27UJHLG J/RdMoH3ZXsMxA6+roEt7yDYarFOdo6ADFy/w56qWACNU43oFt4STaUOAEIyZHrM2knl jCagqziOWaPJ43UQTsVyrGBTPZuaCnovRrI1+cbnW7MieEXT4B3suD5AYrl9vZ9jd7sL 9tdjfy2zhqSVNIkeUDQh9NSgoR3DKDOHZRJKuY1/yiOZ19E/ejT7bI9osvctytc9w8rN ZNRi55JSjs22Jv24QC8/YrMI/S3XFQsyHge3CiV60YteP5k7n8GocB1+9JFtsDCW1SkG jxbA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=kSmsRe05; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b19-20020a056402351300b00459e1ce80a7si9378464edd.241.2022.10.20.14.29.24; Thu, 20 Oct 2022 14:29:48 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=kSmsRe05; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229819AbiJTV0O (ORCPT + 99 others); Thu, 20 Oct 2022 17:26:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38584 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229629AbiJTVZ6 (ORCPT ); Thu, 20 Oct 2022 17:25:58 -0400 Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5E0BA180597; Thu, 20 Oct 2022 14:25:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1666301157; x=1697837157; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=RX2JNyvAov8v89XYF6H5UlH6Cd9vaxEM+damP0WRpBM=; b=kSmsRe053I1hTu7EHDjVe5xbu6eKTOg9hpeIAzWvWmNeoM6bPBqXgWz3 1r3MhyTyr24c/TIQJHekuq53JbQP3ohEXmrbOZp3rq7qxQYZDbNE1W0yP bYiHT86xsbeSryJ2RJMIEautxd2H5PZHuGiWXo2LyN53zhIXamj0vw44+ NKv7Cy6CQGaQhU4k6RLsZyQaBPYC9aVNC8eG5oTgzuzsMEjwO+pHCGs3s 3h0DwUs6BjOnt0bsh0wVrRyPsmBH/55UHDrCXrqFj2N2oOHU9jLCvIAk2 k38gdJpSCYG+DE/lwsHPkvPLO5aLfl6JTIkQ6jyLpfrusmOHht+fGum6r g==; X-IronPort-AV: E=McAfee;i="6500,9779,10506"; a="333412435" X-IronPort-AV: E=Sophos;i="5.95,199,1661842800"; d="scan'208";a="333412435" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 Oct 2022 14:25:56 -0700 X-IronPort-AV: E=McAfee;i="6500,9779,10506"; a="693260674" X-IronPort-AV: E=Sophos;i="5.95,199,1661842800"; d="scan'208";a="693260674" Received: from rhweight-wrk1.ra.intel.com ([137.102.106.139]) by fmsmga008-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 Oct 2022 14:25:56 -0700 From: matthew.gerlach@linux.intel.com To: hao.wu@intel.com, yilun.xu@intel.com, russell.h.weight@intel.com, basheer.ahmed.muddebihal@intel.com, trix@redhat.com, mdf@kernel.org, linux-fpga@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, tianfei.zhang@intel.com, corbet@lwn.net, gregkh@linuxfoundation.org, linux-serial@vger.kernel.org, jirislaby@kernel.org, geert+renesas@glider.be, andriy.shevchenko@linux.intel.com, niklas.soderlund+renesas@ragnatech.se, macro@orcam.me.uk, johan@kernel.org, lukas@wunner.de, ilpo.jarvinen@linux.intel.com, marpagan@redhat.com Cc: Basheer Ahmed Muddebihal , Matthew Gerlach Subject: [PATCH v4 2/4] fpga: dfl: Add DFHv1 Register Definitions Date: Thu, 20 Oct 2022 14:26:08 -0700 Message-Id: <20221020212610.697729-3-matthew.gerlach@linux.intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221020212610.697729-1-matthew.gerlach@linux.intel.com> References: <20221020212610.697729-1-matthew.gerlach@linux.intel.com> MIME-Version: 1.0 X-Spam-Status: No, score=-7.2 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE, URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747243644665454388?= X-GMAIL-MSGID: =?utf-8?q?1747243644665454388?= From: Basheer Ahmed Muddebihal This patch adds the definitions for DFHv1 header and related register bitfields. Signed-off-by: Basheer Ahmed Muddebihal Signed-off-by: Matthew Gerlach --- v4: s/MSIX/MSI_X/g move kerneldoc to implementation don't change copyright date v3: keep DFHv1 definitions "hidden" in drivers/fpga/dfl.h v2: clean up whitespace and one line comments remove extra space in commit use uniform number of digits in constants don't change copyright date because of removed content dfl.h s/MSIX/MSI_X/g move kerneldoc --- drivers/fpga/dfl.h | 33 +++++++++++++++++++++++++++++++++ include/linux/dfl.h | 11 +++++++++++ 2 files changed, 44 insertions(+) diff --git a/drivers/fpga/dfl.h b/drivers/fpga/dfl.h index 06cfcd5e84bb..45e6e1359a67 100644 --- a/drivers/fpga/dfl.h +++ b/drivers/fpga/dfl.h @@ -74,11 +74,44 @@ #define DFH_REVISION GENMASK_ULL(15, 12) /* Feature revision */ #define DFH_NEXT_HDR_OFST GENMASK_ULL(39, 16) /* Offset to next DFH */ #define DFH_EOL BIT_ULL(40) /* End of list */ +#define DFH_VERSION GENMASK_ULL(59, 52) /* DFH version */ #define DFH_TYPE GENMASK_ULL(63, 60) /* Feature type */ #define DFH_TYPE_AFU 1 #define DFH_TYPE_PRIVATE 3 #define DFH_TYPE_FIU 4 +/* + * DFHv1 Register Offset definitons + * In DHFv1, DFH + GUID + CSR_START + CSR_SIZE_GROUP + PARAM_HDR + PARAM_DATA + * as common header registers + */ +#define DFHv1_CSR_ADDR 0x18 /* CSR Register start address */ +#define DFHv1_CSR_SIZE_GRP 0x20 /* Size of Reg Block and Group/tag */ +#define DFHv1_PARAM_HDR 0x28 /* Optional First Param header */ + +/* + * CSR Rel Bit, 1'b0 = relative (offset from feature DFH start), + * 1'b1 = absolute (ARM or other non-PCIe use) + */ +#define DFHv1_CSR_ADDR_REL BIT_ULL(0) + +/* CSR Header Register Bit Definitions */ +#define DFHv1_CSR_ADDR_MASK GENMASK_ULL(63, 1) /* 63:1 of CSR address */ + +/* CSR SIZE Goup Register Bit Definitions */ +#define DFHv1_CSR_SIZE_GRP_INSTANCE_ID GENMASK_ULL(15, 0) /* Enumeration instantiated IP */ +#define DFHv1_CSR_SIZE_GRP_GROUPING_ID GENMASK_ULL(30, 16) /* Group Features/interfaces */ +#define DFHv1_CSR_SIZE_GRP_HAS_PARAMS BIT_ULL(31) /* Presence of Parameters */ +#define DFHv1_CSR_SIZE_GRP_SIZE GENMASK_ULL(63, 32) /* Size of CSR Block in bytes */ + +/* PARAM Header Register Bit Definitions */ +#define DFHv1_PARAM_HDR_ID GENMASK_ULL(15, 0) /* Id of this Param */ +#define DFHv1_PARAM_HDR_VERSION GENMASK_ULL(31, 16) /* Version Param */ +#define DFHv1_PARAM_HDR_NEXT_OFFSET GENMASK_ULL(63, 32) /* Offset of next Param */ +#define DFHv1_PARAM_HDR_NEXT_EOL BIT_ULL(0) +#define DFHv1_PARAM_HDR_NEXT_MASK GENMASK_ULL(1, 0) +#define DFHv1_PARAM_DATA 0x08 /* Offset of Param data from Param header */ + /* Next AFU Register Bitfield */ #define NEXT_AFU_NEXT_DFH_OFST GENMASK_ULL(23, 0) /* Offset to next AFU */ diff --git a/include/linux/dfl.h b/include/linux/dfl.h index 431636a0dc78..fea9e16d35b6 100644 --- a/include/linux/dfl.h +++ b/include/linux/dfl.h @@ -11,6 +11,17 @@ #include #include +#define DFHv1_PARAM_ID_MSI_X 0x1 +#define DFHv1_PARAM_MSI_X_STARTV 0x0 +#define DFHv1_PARAM_MSI_X_NUMV 0x4 + +#define DFHv1_PARAM_ID_CLK_FRQ 0x2 +#define DFHv1_PARAM_ID_FIFO_LEN 0x3 + +#define DFHv1_PARAM_ID_REG_LAYOUT 0x4 +#define DFHv1_PARAM_ID_REG_WIDTH GENMASK_ULL(63, 32) +#define DFHv1_PARAM_ID_REG_SHIFT GENMASK_ULL(31, 0) + /** * enum dfl_id_type - define the DFL FIU types */ From patchwork Thu Oct 20 21:26:09 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Gerlach X-Patchwork-Id: 6409 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4242:0:0:0:0:0 with SMTP id s2csp331358wrr; Thu, 20 Oct 2022 14:28:14 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6+ifIEGjv4BXMNPzYUIuZaEANbXMdPwxP1cv6TX7WWxOxkEQIK5z5q+zOBF8T1H2mMLJwz X-Received: by 2002:a50:ec15:0:b0:458:a612:f751 with SMTP id g21-20020a50ec15000000b00458a612f751mr13940616edr.111.1666301294363; Thu, 20 Oct 2022 14:28:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666301294; cv=none; d=google.com; s=arc-20160816; b=i1zZcas7cI9o4hdZZNTGWJ2vA8OHyBGQCAq3tj1MWlbAMpsFJkkSV4fglr4mjKndlf h8t8WnP3/ub9OiNf9M/Bc2TkYQ0WYo9dPpXqBJytuwATVThI19slZpuUWubi4tcSpoSe qfxXxZHFlOaE1d22jqD6jANu8L+CjrJoMNdjHAziVORckg4nVp1ltM/w/FjOcWNoRwCm wEC41X6QKg64zZuYWAVIXolciFmmhMGpDZyT7weEx5HVonoowmNRcO2hvzoFThisxRfJ Y5+yq9hvFwjUvYO7HzSbjjzlJGWUHqPkTZeSTyDxL7c393h8L55DIr6XhoV77uOiv2xl YkrA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=hOb6KxAJchSIsrG/gwP/RN7HYVJ0zcfatMauXIRbGm0=; b=XDl0iN2GTFTbT7+AzDSxHAmKHr1XIEKwDOQlJIPHpbcfADEFrJxi6IrTvxcHGlx0G1 LMJYXAMJht283PJElV/DY68GId8hps8PGhH2jahbd/p6Ae5LFnMYm8gscE0J3zi+lmH7 yANAK51sGOPAGGT7e/3OcWaOJmx+668qw6TCGHdAMBfUTkDC4hxggHCdsqtYckjLyqvw tKnI85to6stMDY2oaV51g4USc8hcsloNvdRpQ+weoWIW0JG4bCkNBrUE8e6eQzBzOMY5 oHgqe1B6j+W7RcVwjRLfr1P9KcY8qXH6h59L8dgSJV31CjqywrkM9rSqISRD84zoZ1Lc uIsg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=NrHF2OFn; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id y22-20020a056402359600b00458b42ff418si18099999edc.221.2022.10.20.14.27.50; Thu, 20 Oct 2022 14:28:14 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=NrHF2OFn; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229839AbiJTV0W (ORCPT + 99 others); Thu, 20 Oct 2022 17:26:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38712 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229670AbiJTV0A (ORCPT ); Thu, 20 Oct 2022 17:26:00 -0400 Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 241C91805AF; Thu, 20 Oct 2022 14:25:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1666301158; x=1697837158; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=hVOlHIIKc4ukbpxE1RipCHsPTHMEEm1lY+xI+vrmXag=; b=NrHF2OFnADOUB5e4juBW2Gk/onDnmKWCwKfhpOHzMSy9zOjlkWVcHjLU rnTRpaVZTeLMeZyLoQX+vIWz+imPVKHQRcFTnNzQrvkvNVdP3uSJi8EyX joALzLXx86zEsg7elj2ijAICwmcWEdlIchX0/Gk1yVs0q9UxVFfPp0YwS wNIURj9Xqc8bEggZ4IvVSDqJ8lyswMqaX2ExtABxn9EIlvXwC3a6SDOxn zekJ9NLepy3Qqg796O9UXddUD0dmoBZOy2oWNCPpU+EUhEyBms/CcBPXA mKbvBIP1EByqq51IHNFEK4KxqCNsqd74xQKZKXg9DCLc/mlWpUbeRjNQQ Q==; X-IronPort-AV: E=McAfee;i="6500,9779,10506"; a="333412439" X-IronPort-AV: E=Sophos;i="5.95,199,1661842800"; d="scan'208";a="333412439" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 Oct 2022 14:25:57 -0700 X-IronPort-AV: E=McAfee;i="6500,9779,10506"; a="693260681" X-IronPort-AV: E=Sophos;i="5.95,199,1661842800"; d="scan'208";a="693260681" Received: from rhweight-wrk1.ra.intel.com ([137.102.106.139]) by fmsmga008-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 Oct 2022 14:25:56 -0700 From: matthew.gerlach@linux.intel.com To: hao.wu@intel.com, yilun.xu@intel.com, russell.h.weight@intel.com, basheer.ahmed.muddebihal@intel.com, trix@redhat.com, mdf@kernel.org, linux-fpga@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, tianfei.zhang@intel.com, corbet@lwn.net, gregkh@linuxfoundation.org, linux-serial@vger.kernel.org, jirislaby@kernel.org, geert+renesas@glider.be, andriy.shevchenko@linux.intel.com, niklas.soderlund+renesas@ragnatech.se, macro@orcam.me.uk, johan@kernel.org, lukas@wunner.de, ilpo.jarvinen@linux.intel.com, marpagan@redhat.com Cc: Matthew Gerlach Subject: [PATCH v4 3/4] fpga: dfl: add basic support DFHv1 Date: Thu, 20 Oct 2022 14:26:09 -0700 Message-Id: <20221020212610.697729-4-matthew.gerlach@linux.intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221020212610.697729-1-matthew.gerlach@linux.intel.com> References: <20221020212610.697729-1-matthew.gerlach@linux.intel.com> MIME-Version: 1.0 X-Spam-Status: No, score=-7.2 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE, URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747243546025609604?= X-GMAIL-MSGID: =?utf-8?q?1747243546025609604?= From: Matthew Gerlach Add generic support for MSI-X interrupts for DFL devices. The location of a feature's registers is explicitly described in DFHv1 and can be relative to the base of the DFHv1 or an absolute address. Parse the location and pass the information to DFL driver. Signed-off-by: Matthew Gerlach --- v4: s/MSIX/MSI_X move kernel doc to implementation use structure assignment fix decode of absolute address clean up comment in parse_feature_irqs remove use of csr_res v3: remove unneeded blank line use clearer variable name pass finfo into parse_feature_irqs() refactor code for better indentation use switch statement for irq parsing squash in code parsing register location v2: fix kernel doc clarify use of DFH_VERSION field --- drivers/fpga/dfl.c | 234 ++++++++++++++++++++++++++++++++++---------- drivers/fpga/dfl.h | 5 + include/linux/dfl.h | 4 + 3 files changed, 194 insertions(+), 49 deletions(-) diff --git a/drivers/fpga/dfl.c b/drivers/fpga/dfl.c index b9aae85ba930..37f995e66436 100644 --- a/drivers/fpga/dfl.c +++ b/drivers/fpga/dfl.c @@ -342,6 +342,8 @@ static void release_dfl_dev(struct device *dev) if (ddev->mmio_res.parent) release_resource(&ddev->mmio_res); + kfree(ddev->params); + ida_free(&dfl_device_ida, ddev->id); kfree(ddev->irqs); kfree(ddev); @@ -380,7 +382,16 @@ dfl_dev_add(struct dfl_feature_platform_data *pdata, ddev->type = feature_dev_id_type(pdev); ddev->feature_id = feature->id; ddev->revision = feature->revision; + ddev->dfh_version = feature->dfh_version; ddev->cdev = pdata->dfl_cdev; + if (feature->param_size) { + ddev->params = kmemdup(feature->params, feature->param_size, GFP_KERNEL); + if (!ddev->params) { + ret = -ENOMEM; + goto put_dev; + } + ddev->param_size = feature->param_size; + } /* add mmio resource */ parent_res = &pdev->resource[feature->resource_index]; @@ -708,20 +719,27 @@ struct build_feature_devs_info { * struct dfl_feature_info - sub feature info collected during feature dev build * * @fid: id of this sub feature. + * @revision: revision of this sub feature + * @dfh_version: version of Device Feature Header (DFH) * @mmio_res: mmio resource of this sub feature. * @ioaddr: mapped base address of mmio resource. * @node: node in sub_features linked list. * @irq_base: start of irq index in this sub feature. * @nr_irqs: number of irqs of this sub feature. + * @param_size: size DFH parameters. + * @params: DFH parameter data. */ struct dfl_feature_info { u16 fid; u8 revision; + u8 dfh_version; struct resource mmio_res; void __iomem *ioaddr; struct list_head node; unsigned int irq_base; unsigned int nr_irqs; + unsigned int param_size; + u64 params[]; }; static void dfl_fpga_cdev_add_port_dev(struct dfl_fpga_cdev *cdev, @@ -797,7 +815,17 @@ static int build_info_commit_dev(struct build_feature_devs_info *binfo) feature->dev = fdev; feature->id = finfo->fid; feature->revision = finfo->revision; + feature->dfh_version = finfo->dfh_version; + if (finfo->param_size) { + feature->params = devm_kmemdup(binfo->dev, + finfo->params, finfo->param_size, + GFP_KERNEL); + if (!feature->params) + return -ENOMEM; + + feature->param_size = finfo->param_size; + } /* * the FIU header feature has some fundamental functions (sriov * set, port enable/disable) needed for the dfl bus device and @@ -934,56 +962,108 @@ static u16 feature_id(u64 value) return 0; } +static void *find_param(void *base, resource_size_t max, int param) +{ + int off = 0; + u64 v, next; + + while (off < max) { + v = *(u64 *)(base + off); + if (param == FIELD_GET(DFHv1_PARAM_HDR_ID, v)) + return base + off + DFHv1_PARAM_DATA; + + next = FIELD_GET(DFHv1_PARAM_HDR_NEXT_OFFSET, v); + off += next & ~DFHv1_PARAM_HDR_NEXT_MASK; + if (next & DFHv1_PARAM_HDR_NEXT_EOL) + break; + + } + + return NULL; +} + +/** + * dfh_find_param() - find data for the given parameter id + * @dfl_dev: dfl device + * @param: id of dfl parameter + * + * Return: pointer to parameter data on success, NULL otherwise. + */ +void *dfh_find_param(struct dfl_device *dfl_dev, int param) +{ + return find_param(dfl_dev->params, dfl_dev->param_size, param); +} +EXPORT_SYMBOL_GPL(dfh_find_param); + static int parse_feature_irqs(struct build_feature_devs_info *binfo, - resource_size_t ofst, u16 fid, - unsigned int *irq_base, unsigned int *nr_irqs) + resource_size_t ofst, struct dfl_feature_info *finfo) { void __iomem *base = binfo->ioaddr + ofst; unsigned int i, ibase, inr = 0; + void *params = finfo->params; enum dfl_id_type type; + u16 fid = finfo->fid; int virq; + u32 *p; u64 v; - type = feature_dev_id_type(binfo->feature_dev); + switch (finfo->dfh_version) { + case 0: + /* + * DFHv0 only provides mmio resource information for each feature + * in the DFL header. There is no generic interrupt information. + * Instead, features with interrupt functionality provide + * the information in feature specific registers. + */ + type = feature_dev_id_type(binfo->feature_dev); + if (type == PORT_ID) { + switch (fid) { + case PORT_FEATURE_ID_UINT: + v = readq(base + PORT_UINT_CAP); + ibase = FIELD_GET(PORT_UINT_CAP_FST_VECT, v); + inr = FIELD_GET(PORT_UINT_CAP_INT_NUM, v); + break; + case PORT_FEATURE_ID_ERROR: + v = readq(base + PORT_ERROR_CAP); + ibase = FIELD_GET(PORT_ERROR_CAP_INT_VECT, v); + inr = FIELD_GET(PORT_ERROR_CAP_SUPP_INT, v); + break; + } + } else if (type == FME_ID) { + switch (fid) { + case FME_FEATURE_ID_GLOBAL_ERR: + v = readq(base + FME_ERROR_CAP); + ibase = FIELD_GET(FME_ERROR_CAP_INT_VECT, v); + inr = FIELD_GET(FME_ERROR_CAP_SUPP_INT, v); + break; + } + } + break; - /* - * Ideally DFL framework should only read info from DFL header, but - * current version DFL only provides mmio resources information for - * each feature in DFL Header, no field for interrupt resources. - * Interrupt resource information is provided by specific mmio - * registers of each private feature which supports interrupt. So in - * order to parse and assign irq resources, DFL framework has to look - * into specific capability registers of these private features. - * - * Once future DFL version supports generic interrupt resource - * information in common DFL headers, the generic interrupt parsing - * code will be added. But in order to be compatible to old version - * DFL, the driver may still fall back to these quirks. - */ - if (type == PORT_ID) { - switch (fid) { - case PORT_FEATURE_ID_UINT: - v = readq(base + PORT_UINT_CAP); - ibase = FIELD_GET(PORT_UINT_CAP_FST_VECT, v); - inr = FIELD_GET(PORT_UINT_CAP_INT_NUM, v); + case 1: + /* + * DFHv1 provides interrupt resource information in DFHv1 + * parameter blocks. + */ + if (!finfo->param_size) break; - case PORT_FEATURE_ID_ERROR: - v = readq(base + PORT_ERROR_CAP); - ibase = FIELD_GET(PORT_ERROR_CAP_INT_VECT, v); - inr = FIELD_GET(PORT_ERROR_CAP_SUPP_INT, v); + + p = find_param(params, finfo->param_size, DFHv1_PARAM_ID_MSI_X); + if (!p) break; - } - } else if (type == FME_ID) { - if (fid == FME_FEATURE_ID_GLOBAL_ERR) { - v = readq(base + FME_ERROR_CAP); - ibase = FIELD_GET(FME_ERROR_CAP_INT_VECT, v); - inr = FIELD_GET(FME_ERROR_CAP_SUPP_INT, v); - } + + ibase = *p++; + inr = *p; + break; + + default: + dev_warn(binfo->dev, "unexpected DFH version %d\n", finfo->dfh_version); + break; } if (!inr) { - *irq_base = 0; - *nr_irqs = 0; + finfo->irq_base = 0; + finfo->nr_irqs = 0; return 0; } @@ -1006,12 +1086,37 @@ static int parse_feature_irqs(struct build_feature_devs_info *binfo, } } - *irq_base = ibase; - *nr_irqs = inr; + finfo->irq_base = ibase; + finfo->nr_irqs = inr; return 0; } +static int dfh_get_psize(void __iomem *dfh_base, resource_size_t max) +{ + int size = 0; + u64 v, next; + + if (!FIELD_GET(DFHv1_CSR_SIZE_GRP_HAS_PARAMS, + readq(dfh_base + DFHv1_CSR_SIZE_GRP))) + return 0; + + while (size + DFHv1_PARAM_HDR < max) { + v = readq(dfh_base + DFHv1_PARAM_HDR + size); + + next = FIELD_GET(DFHv1_PARAM_HDR_NEXT_OFFSET, v); + if (!(next & ~DFHv1_PARAM_HDR_NEXT_MASK)) + return -EINVAL; + + size += next & ~DFHv1_PARAM_HDR_NEXT_MASK; + + if (next & DFHv1_PARAM_HDR_NEXT_EOL) + return size; + } + + return -ENOENT; +} + /* * when create sub feature instances, for private features, it doesn't need * to provide resource size and feature id as they could be read from DFH @@ -1023,39 +1128,70 @@ static int create_feature_instance(struct build_feature_devs_info *binfo, resource_size_t ofst, resource_size_t size, u16 fid) { - unsigned int irq_base, nr_irqs; struct dfl_feature_info *finfo; + int dfh_psize = 0; u8 revision = 0; + u8 dfh_ver = 0; int ret; u64 v; if (fid != FEATURE_ID_AFU) { v = readq(binfo->ioaddr + ofst); revision = FIELD_GET(DFH_REVISION, v); - + dfh_ver = FIELD_GET(DFH_VERSION, v); /* read feature size and id if inputs are invalid */ size = size ? size : feature_size(v); fid = fid ? fid : feature_id(v); + if (dfh_ver == 1) { + dfh_psize = dfh_get_psize(binfo->ioaddr + ofst, size); + if (dfh_psize < 0) { + dev_err(binfo->dev, + "failed to read size of DFHv1 parameters %d\n", + dfh_psize); + return dfh_psize; + } + dev_dbg(binfo->dev, "dfhv1_psize %d\n", dfh_psize); + } } if (binfo->len - ofst < size) return -EINVAL; - ret = parse_feature_irqs(binfo, ofst, fid, &irq_base, &nr_irqs); - if (ret) - return ret; - - finfo = kzalloc(sizeof(*finfo), GFP_KERNEL); + finfo = kzalloc(sizeof(*finfo) + dfh_psize, GFP_KERNEL); if (!finfo) return -ENOMEM; + if (dfh_psize > 0) { + memcpy_fromio(finfo->params, + binfo->ioaddr + ofst + DFHv1_PARAM_HDR, dfh_psize); + finfo->param_size = dfh_psize; + } + finfo->fid = fid; finfo->revision = revision; - finfo->mmio_res.start = binfo->start + ofst; - finfo->mmio_res.end = finfo->mmio_res.start + size - 1; + finfo->dfh_version = dfh_ver; finfo->mmio_res.flags = IORESOURCE_MEM; - finfo->irq_base = irq_base; - finfo->nr_irqs = nr_irqs; + if (dfh_ver == 1) { + v = readq(binfo->ioaddr + ofst + DFHv1_CSR_ADDR); + if (v & DFHv1_CSR_ADDR_REL) + finfo->mmio_res.start = v & ~DFHv1_CSR_ADDR_REL; + else + finfo->mmio_res.start = binfo->start + ofst + + FIELD_GET(DFHv1_CSR_ADDR_MASK, v); + + v = readq(binfo->ioaddr + ofst + DFHv1_CSR_SIZE_GRP); + finfo->mmio_res.end = finfo->mmio_res.start + + FIELD_GET(DFHv1_CSR_SIZE_GRP_SIZE, v) - 1; + } else { + finfo->mmio_res.start = binfo->start + ofst; + finfo->mmio_res.end = finfo->mmio_res.start + size - 1; + } + + ret = parse_feature_irqs(binfo, ofst, finfo); + if (ret) { + kfree(finfo); + return ret; + } list_add_tail(&finfo->node, &binfo->sub_features); binfo->feature_num++; diff --git a/drivers/fpga/dfl.h b/drivers/fpga/dfl.h index 45e6e1359a67..1ea7f40c1af6 100644 --- a/drivers/fpga/dfl.h +++ b/drivers/fpga/dfl.h @@ -273,11 +273,14 @@ struct dfl_feature_irq_ctx { * @ops: ops of this sub feature. * @ddev: ptr to the dfl device of this sub feature. * @priv: priv data of this feature. + * @param_size: size of dfh parameters + * @params: point to memory copy of dfh parameters */ struct dfl_feature { struct platform_device *dev; u16 id; u8 revision; + u8 dfh_version; int resource_index; void __iomem *ioaddr; struct dfl_feature_irq_ctx *irq_ctx; @@ -285,6 +288,8 @@ struct dfl_feature { const struct dfl_feature_ops *ops; struct dfl_device *ddev; void *priv; + unsigned int param_size; + void *params; }; #define FEATURE_DEV_ID_UNUSED (-1) diff --git a/include/linux/dfl.h b/include/linux/dfl.h index fea9e16d35b6..d00787e870b7 100644 --- a/include/linux/dfl.h +++ b/include/linux/dfl.h @@ -50,9 +50,12 @@ struct dfl_device { u16 type; u16 feature_id; u8 revision; + u8 dfh_version; struct resource mmio_res; int *irqs; unsigned int num_irqs; + unsigned int param_size; + void *params; struct dfl_fpga_cdev *cdev; const struct dfl_device_id *id_entry; }; @@ -95,4 +98,5 @@ void dfl_driver_unregister(struct dfl_driver *dfl_drv); module_driver(__dfl_driver, dfl_driver_register, \ dfl_driver_unregister) +void *dfh_find_param(struct dfl_device *dfl_dev, int param); #endif /* __LINUX_DFL_H */ From patchwork Thu Oct 20 21:26:10 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Gerlach X-Patchwork-Id: 6410 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4242:0:0:0:0:0 with SMTP id s2csp331477wrr; Thu, 20 Oct 2022 14:28:41 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6ayYJp+ioOdQDUA2ot2+qksjYud4P+DEP0FjrYOqpiTmUdHkzHRKT2j2tDpeu7P3ZuIjOc X-Received: by 2002:a17:907:7635:b0:78d:c5e9:3e57 with SMTP id jy21-20020a170907763500b0078dc5e93e57mr12828950ejc.204.1666301321647; Thu, 20 Oct 2022 14:28:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666301321; cv=none; d=google.com; s=arc-20160816; b=a4ptpyS2L3Kuz/0BUz2jQkXFfYBeAFLbgi+hmNyBQjK/ZDwCsFYWoq0tbjcqvL08Na KwQAyvK5ETP+RtvFFF3ZmzLEm59npnBE5buleccleSLEXnCP8bYSucIgPQlZIHCT9UeS yd6OgYqsq4pFeR+Zxt372kM8ALB3g03LxFXuJibZ5fBUM7xmlXoaFSrHKkqd/sZLr0e8 cX8i3rlDGYD1cAGFseO4qDnBcVJXjMCbSQUA3Idaz6wp/S233GPKNeIq86EI3v9UzHiL wta8X8301RruqP+RNW2L09ScW9ND65XVQeURQoJ5hd9Afv0+nHKoO65hdUc8LaRZ0Qqu hOyA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=RoakfwIjzENLOc3t5fWqKVOfgsiLn4B4NWUOkDUk+So=; b=Mv+ea6hJS/YD6uWDGKxkTwf/STpKmPGUZ7maybjk3LID7d/Rvy9Uv1oP4Vkb6TkKff Ow4fWGeHSjVZ6RT7MMkGJEPpsirlbRdPTn/c9pUogFjfUlG+LChXy7lvqZ6mIl4NdD87 etpP31VGfaqyNvV+JkZo708suVKBlDTO1NkhtsqWp3lzCXzrVX3hig9HHW8nqBtqONLF csuz9nCKdGyCXKMof8Pkgh5+HID0M8sopfQD0yRQ/3fozcv8mx/RAJ1aW1UB3UInmdVq 6msCLxbfHPzrPpT3hnpVVszHrQjyWYVv6oFWnIj9tiTYH4dx8dudFoj2yr6nmN55Yv1V X9sQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=S6zYlvpJ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id hb10-20020a170907160a00b00782e85ae302si17242810ejc.574.2022.10.20.14.28.17; Thu, 20 Oct 2022 14:28:41 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=S6zYlvpJ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229597AbiJTV0h (ORCPT + 99 others); Thu, 20 Oct 2022 17:26:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38714 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229779AbiJTV0A (ORCPT ); Thu, 20 Oct 2022 17:26:00 -0400 Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 071F217E232; Thu, 20 Oct 2022 14:25:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1666301159; x=1697837159; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=vZCpdvJHfbvZBCLZsEQYW68bNUKI0Koalfz10BUIW0o=; b=S6zYlvpJMgzxSXnGML8JEOoRPB6tnv146qaZb19TajNwECfNQeyyg6yw ugEMrv53lXL5o9a/boqYZZ2kye49G9x6eCWCJ9OMiJAtcxOxhbb7DPxoA KOrSK1Rl5IN5BdGJXlWwG8eYXBpGItGewKsQS4wwsqUBi17SCGkWTDx7l 7eKLMTERwvfhma6J7yGGIe7V2aOqnvAJN2yefBiG5gYOcjsnnTcRHVjw7 kDKpxB64Ckpm+C0GlZydknYkOE34N65IfHgABeQ7MbFZiEYJWhyUva0Ra TAjCXL2XzqlUwGqwF2Tw7MtI2qjDZDIrgVFna14B8DohFDvQns5w/Ob1O Q==; X-IronPort-AV: E=McAfee;i="6500,9779,10506"; a="333412443" X-IronPort-AV: E=Sophos;i="5.95,199,1661842800"; d="scan'208";a="333412443" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 Oct 2022 14:25:57 -0700 X-IronPort-AV: E=McAfee;i="6500,9779,10506"; a="693260685" X-IronPort-AV: E=Sophos;i="5.95,199,1661842800"; d="scan'208";a="693260685" Received: from rhweight-wrk1.ra.intel.com ([137.102.106.139]) by fmsmga008-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 Oct 2022 14:25:57 -0700 From: matthew.gerlach@linux.intel.com To: hao.wu@intel.com, yilun.xu@intel.com, russell.h.weight@intel.com, basheer.ahmed.muddebihal@intel.com, trix@redhat.com, mdf@kernel.org, linux-fpga@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, tianfei.zhang@intel.com, corbet@lwn.net, gregkh@linuxfoundation.org, linux-serial@vger.kernel.org, jirislaby@kernel.org, geert+renesas@glider.be, andriy.shevchenko@linux.intel.com, niklas.soderlund+renesas@ragnatech.se, macro@orcam.me.uk, johan@kernel.org, lukas@wunner.de, ilpo.jarvinen@linux.intel.com, marpagan@redhat.com Cc: Matthew Gerlach Subject: [PATCH v4 4/4] tty: serial: 8250: add DFL bus driver for Altera 16550. Date: Thu, 20 Oct 2022 14:26:10 -0700 Message-Id: <20221020212610.697729-5-matthew.gerlach@linux.intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221020212610.697729-1-matthew.gerlach@linux.intel.com> References: <20221020212610.697729-1-matthew.gerlach@linux.intel.com> MIME-Version: 1.0 X-Spam-Status: No, score=-7.2 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE, URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747243574376329713?= X-GMAIL-MSGID: =?utf-8?q?1747243574376329713?= From: Matthew Gerlach Add a Device Feature List (DFL) bus driver for the Altera 16550 implementation of UART. Signed-off-by: Matthew Gerlach --- v4: use dev_err_probe() everywhere that is appropriate clean up noise change error messages to use the word, unsupported tried again to sort Makefile and KConfig better reorder probe function for easier error handling use new dfh_find_param API v3: use passed in location of registers use cleaned up functions for parsing parameters v2: clean up error messages alphabetize header files fix 'missing prototype' error by making function static tried to sort Makefile and Kconfig better --- drivers/tty/serial/8250/8250_dfl.c | 149 +++++++++++++++++++++++++++++ drivers/tty/serial/8250/Kconfig | 12 +++ drivers/tty/serial/8250/Makefile | 1 + 3 files changed, 162 insertions(+) create mode 100644 drivers/tty/serial/8250/8250_dfl.c diff --git a/drivers/tty/serial/8250/8250_dfl.c b/drivers/tty/serial/8250/8250_dfl.c new file mode 100644 index 000000000000..f02f0ba2a565 --- /dev/null +++ b/drivers/tty/serial/8250/8250_dfl.c @@ -0,0 +1,149 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Driver for FPGA UART + * + * Copyright (C) 2022 Intel Corporation, Inc. + * + * Authors: + * Ananda Ravuri + * Matthew Gerlach + */ + +#include +#include +#include +#include +#include +#include +#include + +struct dfl_uart { + int line; +}; + +static int dfl_uart_get_params(struct dfl_device *dfl_dev, struct uart_8250_port *uart) +{ + struct device *dev = &dfl_dev->dev; + u64 v, fifo_len, reg_width; + u64 *p; + + p = dfh_find_param(dfl_dev, DFHv1_PARAM_ID_CLK_FRQ); + if (!p) + return dev_err_probe(dev, -EINVAL, "missing CLK_FRQ param\n"); + + uart->port.uartclk = *p; + dev_dbg(dev, "UART_CLK_ID %u Hz\n", uart->port.uartclk); + + p = dfh_find_param(dfl_dev, DFHv1_PARAM_ID_FIFO_LEN); + if (!p) + return dev_err_probe(dev, -EINVAL, "missing FIFO_LEN param\n"); + + fifo_len = *p; + dev_dbg(dev, "UART_FIFO_ID fifo_len %llu\n", fifo_len); + + switch (fifo_len) { + case 32: + uart->port.type = PORT_ALTR_16550_F32; + break; + + case 64: + uart->port.type = PORT_ALTR_16550_F64; + break; + + case 128: + uart->port.type = PORT_ALTR_16550_F128; + break; + + default: + return dev_err_probe(dev, -EINVAL, "unsupported fifo_len %llu\n", fifo_len); + } + + p = dfh_find_param(dfl_dev, DFHv1_PARAM_ID_REG_LAYOUT); + if (!p) + return dev_err_probe(dev, -EINVAL, "missing REG_LAYOUT param\n"); + + v = *p; + uart->port.regshift = FIELD_GET(DFHv1_PARAM_ID_REG_SHIFT, v); + reg_width = FIELD_GET(DFHv1_PARAM_ID_REG_WIDTH, v); + + dev_dbg(dev, "UART_LAYOUT_ID width %lld shift %d\n", reg_width, uart->port.regshift); + + switch (reg_width) { + case 4: + uart->port.iotype = UPIO_MEM32; + break; + + case 2: + uart->port.iotype = UPIO_MEM16; + break; + + default: + return dev_err_probe(dev, -EINVAL, "unsupported reg_width %lld\n", reg_width); + } + + return 0; +} + +static int dfl_uart_probe(struct dfl_device *dfl_dev) +{ + struct device *dev = &dfl_dev->dev; + struct uart_8250_port uart; + struct dfl_uart *dfluart; + int ret; + + memset(&uart, 0, sizeof(uart)); + uart.port.flags = UPF_IOREMAP; + uart.port.mapbase = dfl_dev->mmio_res.start; + uart.port.mapsize = resource_size(&dfl_dev->mmio_res); + + ret = dfl_uart_get_params(dfl_dev, &uart); + + if (ret < 0) + return dev_err_probe(dev, ret, "failed uart feature walk\n"); + + dev_dbg(dev, "nr_irqs %d %p\n", dfl_dev->num_irqs, dfl_dev->irqs); + + if (dfl_dev->num_irqs == 1) + uart.port.irq = dfl_dev->irqs[0]; + + dfluart = devm_kzalloc(dev, sizeof(*dfluart), GFP_KERNEL); + if (!dfluart) + return -ENOMEM; + + dfluart->line = serial8250_register_8250_port(&uart); + if (dfluart->line < 0) + return dev_err_probe(dev, dfluart->line, "unable to register 8250 port.\n"); + + dev_set_drvdata(dev, dfluart); + + return 0; +} + +static void dfl_uart_remove(struct dfl_device *dfl_dev) +{ + struct dfl_uart *dfluart = dev_get_drvdata(&dfl_dev->dev); + + serial8250_unregister_port(dfluart->line); +} + +#define FME_FEATURE_ID_UART 0x24 + +static const struct dfl_device_id dfl_uart_ids[] = { + { FME_ID, FME_FEATURE_ID_UART }, + { } +}; +MODULE_DEVICE_TABLE(dfl, dfl_uart_ids); + +static struct dfl_driver dfl_uart_driver = { + .drv = { + .name = "dfl-uart", + }, + .id_table = dfl_uart_ids, + .probe = dfl_uart_probe, + .remove = dfl_uart_remove, +}; +module_dfl_driver(dfl_uart_driver); + +MODULE_DESCRIPTION("DFL Intel UART driver"); +MODULE_AUTHOR("Intel Corporation"); +MODULE_LICENSE("GPL"); diff --git a/drivers/tty/serial/8250/Kconfig b/drivers/tty/serial/8250/Kconfig index d0b49e15fbf5..4efc8ee51c18 100644 --- a/drivers/tty/serial/8250/Kconfig +++ b/drivers/tty/serial/8250/Kconfig @@ -370,6 +370,18 @@ config SERIAL_8250_FSL erratum for Freescale 16550 UARTs in the 8250 driver. It also enables support for ACPI enumeration. +config SERIAL_8250_DFL + tristate "DFL bus driver for Altera 16550 UART" + depends on SERIAL_8250 && FPGA_DFL + help + This option enables support for a Device Feature List (DFL) bus + driver for the Altera 16650 UART. One or more Altera 16650 UARTs + can be instantiated in a FPGA and then be discovered during + enumeration of the DFL bus. + + To compile this driver as a module, chose M here: the + module will be called 8250_dfl. + config SERIAL_8250_DW tristate "Support for Synopsys DesignWare 8250 quirks" depends on SERIAL_8250 diff --git a/drivers/tty/serial/8250/Makefile b/drivers/tty/serial/8250/Makefile index bee908f99ea0..65bc6ad4dd01 100644 --- a/drivers/tty/serial/8250/Makefile +++ b/drivers/tty/serial/8250/Makefile @@ -28,6 +28,7 @@ obj-$(CONFIG_SERIAL_8250_EXAR_ST16C554) += 8250_exar_st16c554.o obj-$(CONFIG_SERIAL_8250_HUB6) += 8250_hub6.o obj-$(CONFIG_SERIAL_8250_FSL) += 8250_fsl.o obj-$(CONFIG_SERIAL_8250_MEN_MCB) += 8250_men_mcb.o +obj-$(CONFIG_SERIAL_8250_DFL) += 8250_dfl.o obj-$(CONFIG_SERIAL_8250_DW) += 8250_dw.o obj-$(CONFIG_SERIAL_8250_EM) += 8250_em.o obj-$(CONFIG_SERIAL_8250_IOC3) += 8250_ioc3.o