Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp1947376imu; Thu, 17 Jan 2019 06:01:59 -0800 (PST) X-Google-Smtp-Source: ALg8bN5aGuRxijYmmDxoC52r751dH6rvWhl0MJZyTeiPuL8XE1loNb9p3aiXtDXKrsuTu4LnCX0j X-Received: by 2002:a63:d604:: with SMTP id q4mr13412973pgg.175.1547733719196; Thu, 17 Jan 2019 06:01:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1547733719; cv=none; d=google.com; s=arc-20160816; b=XOT0Y3+7PFW5rCSKlnDaJ9b6qjch9qo2LcVXOO/Z5/43A8Qm1p2tWidUf5AKTviGg1 0m9Pis8/2gfjShgybUUd0i604WTSC8EGOyAA4CyMfQ2pfRRUPxXnOrXGQw03FrUI0um2 prsx7GF9QU1rDr9wk1gTTFOnTe1pVtAbG6PeCLz/Fvdj45bwY6EVpbP+q2C24Guwc1PK 3mlOR48fOxfEXY1K1rnMH5KLd4HLp27MWHKwQgEA4MYfyckGfsJvjerqQ34GjbPOs1lr Jth6ZpRh6+is5EdOW/H4JDsSwNSIVjAjEi/fPzilcydQoL/IwavJZrSGzFIlLVVZ7Jlr Zbvw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from; bh=DYwWiRSnHXBdFfJZpYHc7yuMv9IzLHtTCDH0wONKa7w=; b=led3aXEfaYsklHUXyp5mA75M8iijx/7mfQ92yWVDGcYDiaqgV+gJHW1+vw7kxGR9vN qDpB7YpltKl9+cWF9SQH+H2XfKyFuWKqSHgV7cS8Np1A4/I7yGa20gQkpq4Z8L0uDlAk 71hof6mwMp0yzXRQlDIbfVmYIMPrCThl53y0WlLfTqGKGsnd0KmnGiQxCY1WiuyItIom 3LpjDyiYBHAPaUtmTKj+3q+O8h6aSV4xLHlVvB4LoIUyzXc9VxB7sGT1IDtirpge1SXy zR2PayCiUsCd7uZIIpG4NuDjD6khz2mbst/lrZz6lg10qQBVWw/S5pS7oXZ6mxDor8RX CGTQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=vmware.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g5si1653008plt.273.2019.01.17.06.01.43; Thu, 17 Jan 2019 06:01:59 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=vmware.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727346AbfAQMtm (ORCPT + 99 others); Thu, 17 Jan 2019 07:49:42 -0500 Received: from ex13-edg-ou-001.vmware.com ([208.91.0.189]:38348 "EHLO EX13-EDG-OU-001.vmware.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725902AbfAQMtm (ORCPT ); Thu, 17 Jan 2019 07:49:42 -0500 Received: from sc9-mailhost2.vmware.com (10.113.161.72) by EX13-EDG-OU-001.vmware.com (10.113.208.155) with Microsoft SMTP Server id 15.0.1156.6; Thu, 17 Jan 2019 04:49:17 -0800 Received: from akaher-lnx-dev.eng.vmware.com (unknown [10.110.19.203]) by sc9-mailhost2.vmware.com (Postfix) with ESMTP id 67EC6B1341; Thu, 17 Jan 2019 07:49:38 -0500 (EST) From: Ajay Kaher To: , CC: , , , Ajay Kaher , Jork Loeser , Bjorn Helgaas Subject: [PATCH 2/3] PCI: hv: Add vPCI version protocol negotiation Date: Fri, 18 Jan 2019 02:17:17 +0530 Message-ID: <1547758038-5255-3-git-send-email-akaher@vmware.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1547758038-5255-1-git-send-email-akaher@vmware.com> References: <1547758038-5255-1-git-send-email-akaher@vmware.com> MIME-Version: 1.0 Content-Type: text/plain Received-SPF: None (EX13-EDG-OU-001.vmware.com: akaher@vmware.com does not designate permitted sender hosts) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hyper-V vPCI offers different protocol versions. Add the infra for negotiating the one to use. Signed-off-by: Jork Loeser Signed-off-by: Bjorn Helgaas Reviewed-by: K. Y. Srinivasan Acked-by: K. Y. Srinivasan Signed-off-by: Ajay Kaher --- 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 9e44adf..6eed85b 100644 --- a/drivers/pci/host/pci-hyperv.c +++ b/drivers/pci/host/pci-hyperv.c @@ -65,22 +65,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 */ @@ -1789,6 +1804,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 @@ -1805,26 +1821,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); -- 2.7.4