From patchwork Wed May 24 20:41:27 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jork Loeser X-Patchwork-Id: 9746909 X-Patchwork-Delegate: bhelgaas@google.com Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id E8DAE60210 for ; Wed, 24 May 2017 20:44:35 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DB79E28977 for ; Wed, 24 May 2017 20:44:35 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D04B92898F; Wed, 24 May 2017 20:44:35 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6C87928977 for ; Wed, 24 May 2017 20:44:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1033427AbdEXUod (ORCPT ); Wed, 24 May 2017 16:44:33 -0400 Received: from a2nlsmtp01-03.prod.iad2.secureserver.net ([198.71.225.37]:38154 "EHLO a2nlsmtp01-03.prod.iad2.secureserver.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1035735AbdEXUmd (ORCPT ); Wed, 24 May 2017 16:42:33 -0400 Received: from linuxonhyperv.com ([107.180.71.197]) by : HOSTING RELAY : with SMTP id Dd64dNDvv2aSjDd64duGeL; Wed, 24 May 2017 13:41:32 -0700 x-originating-ip: 107.180.71.197 Received: from jloeser by linuxonhyperv.com with local (Exim 4.89) (envelope-from ) id 1dDd64-0003Rl-Qr; Wed, 24 May 2017 13:41:32 -0700 From: Jork Loeser To: jloeser@microsoft.com, helgaas@kernel.org, linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org, devel@linuxdriverproject.org, olaf@aepfle.de, apw@canonical.com, vkuznets@redhat.com, jasowang@redhat.com, leann.ogasawara@canonical.com, marcelo.cerri@canonical.com, sthemmin@microsoft.com Subject: [PATCH-v2 4/5] Hyper-V vPCI: Add vPCI version protocol negotiation Date: Wed, 24 May 2017 13:41:27 -0700 Message-Id: <1495658488-13199-5-git-send-email-jloeser@linuxonhyperv.com> X-Mailer: git-send-email 1.7.1 In-Reply-To: <1495658488-13199-1-git-send-email-jloeser@linuxonhyperv.com> References: <1495658488-13199-1-git-send-email-jloeser@linuxonhyperv.com> Reply-To: Jork Loeser X-CMAE-Envelope: MS4wfEYS7gcT5Qgk6ZpWEgUhUoVpw7fLujhDWSJW2YcrxjEoiRKJQbNOYrXPCE2ZeBRExIe0cqlONSgf6we3eN1Il0tY38IBtqGareRbotlR+7LKU8Ve7GTA 4YV820FTkPjor0ZALeMf/D3rnjyEz3JAms7F82l7sQSCUa6uHPiVQP+Bv02qhJc7QESi7MsrO9+CrxiA5TQkrJlYcTIq5pPTXOgoJSaz7wy0R3WDJFWihyAB 4DDd+m9prYDfYC4T1mQzMPtmWhD7ZvENBnj+/dlBj7U+TyxY7rAQ0J/JbF9GlHxzQZGqGFZKFi6FrHbIP1UTBvmVgaeL4/n62DlhifVovjaysWCCFc/udf8M 7n5oR40UTbot7Bm45z9sYYhuslRStUBge4CUf3Iciozw9Wi7xAXGhbDBHwDgnEpANKTc6hn8fCI3mmntlO6XCYwox1LnWT0KlUpAYr8fnL0DJIEWyhiG2Y4C 5f/J1wAvQG9+3Hw69uHu6gS3WOznAG77Gs2lrSoVkCuuEL9WxeMheeHX2KFX6yCTuVSvjFHJOrCzldj8GzFv30u2+dEJM9eYEvTkDQ== Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Jork Loeser Hyper-V vPCI offers different protocol versions. This patch creates the the infra for negotiating the one to use. Signed-off-by: Jork Loeser --- drivers/pci/host/pci-hyperv.c | 72 +++++++++++++++++++++++++++++++------------ 1 file changed, 53 insertions(+), 19 deletions(-) diff --git a/drivers/pci/host/pci-hyperv.c b/drivers/pci/host/pci-hyperv.c index ee70b1f..2d69b00 100644 --- a/drivers/pci/host/pci-hyperv.c +++ b/drivers/pci/host/pci-hyperv.c @@ -64,22 +64,37 @@ * major version. */ -#define PCI_MAKE_VERSION(major, minor) ((u32)(((major) << 16) | (major))) +#define PCI_MAKE_VERSION(major, minor) ((u32)(((major) << 16) | (minor))) #define PCI_MAJOR_VERSION(version) ((u32)(version) >> 16) #define PCI_MINOR_VERSION(version) ((u32)(version) & 0xff) -enum { - PCI_PROTOCOL_VERSION_1_1 = PCI_MAKE_VERSION(1, 1), - PCI_PROTOCOL_VERSION_CURRENT = PCI_PROTOCOL_VERSION_1_1 +enum pci_protocol_version_t { + PCI_PROTOCOL_VERSION_1_1 = PCI_MAKE_VERSION(1, 1), /* Win10 */ }; #define CPU_AFFINITY_ALL -1ULL + +/* + * Supported protocol versions in the order of probing - highest go + * first. + */ +static enum pci_protocol_version_t pci_protocol_versions[] = { + PCI_PROTOCOL_VERSION_1_1, +}; + +/* + * Protocol version negotiated by hv_pci_protocol_negotiation(). + */ +static enum pci_protocol_version_t pci_protocol_version; + #define PCI_CONFIG_MMIO_LENGTH 0x2000 #define CFG_PAGE_OFFSET 0x1000 #define CFG_PAGE_SIZE (PCI_CONFIG_MMIO_LENGTH - CFG_PAGE_OFFSET) #define MAX_SUPPORTED_MSI_MESSAGES 0x400 +#define STATUS_REVISION_MISMATCH 0xC0000059 + /* * Message Types */ @@ -1849,6 +1864,7 @@ static int hv_pci_protocol_negotiation(struct hv_device *hdev) struct hv_pci_compl comp_pkt; struct pci_packet *pkt; int ret; + int i; /* * Initiate the handshake with the host and negotiate @@ -1865,26 +1881,44 @@ static int hv_pci_protocol_negotiation(struct hv_device *hdev) pkt->compl_ctxt = &comp_pkt; version_req = (struct pci_version_request *)&pkt->message; version_req->message_type.type = PCI_QUERY_PROTOCOL_VERSION; - version_req->protocol_version = PCI_PROTOCOL_VERSION_CURRENT; - ret = vmbus_sendpacket(hdev->channel, version_req, - sizeof(struct pci_version_request), - (unsigned long)pkt, VM_PKT_DATA_INBAND, - VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED); - if (ret) - goto exit; + for (i = 0; i < ARRAY_SIZE(pci_protocol_versions); i++) { + version_req->protocol_version = pci_protocol_versions[i]; + ret = vmbus_sendpacket(hdev->channel, version_req, + sizeof(struct pci_version_request), + (unsigned long)pkt, VM_PKT_DATA_INBAND, + VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED); + if (ret) { + dev_err(&hdev->device, + "PCI Pass-through VSP failed sending version reqquest: %#x", + ret); + goto exit; + } - wait_for_completion(&comp_pkt.host_event); + wait_for_completion(&comp_pkt.host_event); - if (comp_pkt.completion_status < 0) { - dev_err(&hdev->device, - "PCI Pass-through VSP failed version request %x\n", - comp_pkt.completion_status); - ret = -EPROTO; - goto exit; + if (comp_pkt.completion_status >= 0) { + pci_protocol_version = pci_protocol_versions[i]; + dev_info(&hdev->device, + "PCI VMBus probing: Using version %#x\n", + pci_protocol_version); + goto exit; + } + + if (comp_pkt.completion_status != STATUS_REVISION_MISMATCH) { + dev_err(&hdev->device, + "PCI Pass-through VSP failed version request: %#x", + comp_pkt.completion_status); + ret = -EPROTO; + goto exit; + } + + reinit_completion(&comp_pkt.host_event); } - ret = 0; + dev_err(&hdev->device, + "PCI pass-through VSP failed to find supported version"); + ret = -EPROTO; exit: kfree(pkt);