From patchwork Wed Oct 7 21:16:36 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kelsey Skunberg X-Patchwork-Id: 1378288 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.ubuntu.com (client-ip=91.189.94.19; helo=huckleberry.canonical.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=canonical.com Received: from huckleberry.canonical.com (huckleberry.canonical.com [91.189.94.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4C66bd2ylHz9sTs; Thu, 8 Oct 2020 08:17:01 +1100 (AEDT) Received: from localhost ([127.0.0.1] helo=huckleberry.canonical.com) by huckleberry.canonical.com with esmtp (Exim 4.86_2) (envelope-from ) id 1kQGnx-0000kN-9d; Wed, 07 Oct 2020 21:16:57 +0000 Received: from youngberry.canonical.com ([91.189.89.112]) by huckleberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1kQGnn-0000h2-Mi for kernel-team@lists.ubuntu.com; Wed, 07 Oct 2020 21:16:47 +0000 Received: from mail-oo1-f71.google.com ([209.85.161.71]) by youngberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1kQGnn-00016r-B3 for kernel-team@lists.ubuntu.com; Wed, 07 Oct 2020 21:16:47 +0000 Received: by mail-oo1-f71.google.com with SMTP id p42so1550033ooi.9 for ; Wed, 07 Oct 2020 14:16:47 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=DUVm7dIPoipbzVvKHWd8pLzU1yLHNudvHoXKKMXMw0o=; b=R7NH953jRVP2t5Q6pfnR+JcifEKGRzgPYJclGwhiDuujMR7KjLP+6glfFDRFtPpdWK FHOzMZSVpDlbN/v9+AOiv7IhTkHZFMfhQGWU8edhGpWERNrzt8qjngsMH4fS6MJXZ0Ec YFv4tNpiJ9Dgxc/tjvExy0kr42hK2NBh0c9NmT+FxL1ElilCoz1CF447bjfjsa1XO6WX QsUaF2gHHVNI8IYa9gaYGGSce4KAoCFHuGR8Pj1j8bep5NuFcWcrDzNtdBSZWQP9sjMX VEG+3C5V8odPJ3hxTR9HVjd6t9P3S2Gg6xj7+fGJiilNVe28090n0/p1DVGUS2OV61pz qHnw== X-Gm-Message-State: AOAM531uIxH90Q990fvv2/NL53y8pM4jesUjWjXz2dvxqFOMIKZeEhXE iu54+BwVMJGumq2fKq0jPWXLju/TmV+h9JifRYfXwCrZBzdM0dVKCsbgfW12SlcdCnijGNjtdHa Q5KIA3zA5x1rC0G7nXAeupTqtxm5cHyhJunpdj+1dIA== X-Received: by 2002:aca:ec4d:: with SMTP id k74mr2803423oih.96.1602105405838; Wed, 07 Oct 2020 14:16:45 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzdexDlqbrORzpTRt5bI+Ly6PYv9f4T0pg0tkXIVTISOhCwLVu/+FkmKqXOQomIEZOcGcgAbA== X-Received: by 2002:aca:ec4d:: with SMTP id k74mr2803414oih.96.1602105405609; Wed, 07 Oct 2020 14:16:45 -0700 (PDT) Received: from localhost.localdomain ([38.80.149.171]) by smtp.gmail.com with ESMTPSA id v17sm2891236oic.4.2020.10.07.14.16.44 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Oct 2020 14:16:45 -0700 (PDT) From: Kelsey Skunberg To: kernel-team@lists.ubuntu.com Subject: [bionic/linux-azure-4.15][PATCH 1/3] PCI: hv: Reorganize the code in preparation of hibernation Date: Wed, 7 Oct 2020 15:16:36 -0600 Message-Id: <20201007211640.60573-2-kelsey.skunberg@canonical.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201007211640.60573-1-kelsey.skunberg@canonical.com> References: <20201007211640.60573-1-kelsey.skunberg@canonical.com> MIME-Version: 1.0 X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" From: Dexuan Cui BugLink: https://bugs.launchpad.net/bugs/1883261 There is no functional change. This is just preparatory for a later patch which adds the hibernation support for the pci-hyperv driver. Signed-off-by: Dexuan Cui Signed-off-by: Lorenzo Pieralisi Reviewed-by: Michael Kelley (backported from commit a8e37506e79a7a08d0ee217f389fa1710e7a2ea4) [KelseyS: Changes made in drivers/pci/host/ instead of drivers/pci/controller. Context changes in hv_pcu_bus_exit()] Signed-off-by: Kelsey Skunberg --- drivers/pci/host/pci-hyperv.c | 46 +++++++++++++++++++++++------------ 1 file changed, 30 insertions(+), 16 deletions(-) diff --git a/drivers/pci/host/pci-hyperv.c b/drivers/pci/host/pci-hyperv.c index f5cb6b5f5515..1c822eb10c7a 100644 --- a/drivers/pci/host/pci-hyperv.c +++ b/drivers/pci/host/pci-hyperv.c @@ -2270,7 +2270,9 @@ static void hv_pci_onchannelcallback(void *context) * failing if the host doesn't support the necessary protocol * level. */ -static int hv_pci_protocol_negotiation(struct hv_device *hdev) +static int hv_pci_protocol_negotiation(struct hv_device *hdev, + enum pci_protocol_version_t version[], + int num_version) { struct pci_version_request *version_req; struct hv_pci_compl comp_pkt; @@ -2294,8 +2296,8 @@ static int hv_pci_protocol_negotiation(struct hv_device *hdev) version_req = (struct pci_version_request *)&pkt->message; version_req->message_type.type = PCI_QUERY_PROTOCOL_VERSION; - for (i = 0; i < ARRAY_SIZE(pci_protocol_versions); i++) { - version_req->protocol_version = pci_protocol_versions[i]; + for (i = 0; i < num_version; i++) { + version_req->protocol_version = version[i]; ret = vmbus_sendpacket(hdev->channel, version_req, sizeof(struct pci_version_request), (unsigned long)pkt, VM_PKT_DATA_INBAND, @@ -2311,7 +2313,7 @@ static int hv_pci_protocol_negotiation(struct hv_device *hdev) } if (comp_pkt.completion_status >= 0) { - pci_protocol_version = pci_protocol_versions[i]; + pci_protocol_version = version[i]; dev_info(&hdev->device, "PCI VMBus probing: Using version %#x\n", pci_protocol_version); @@ -2820,7 +2822,8 @@ static int hv_pci_probe(struct hv_device *hdev, hv_set_drvdata(hdev, hbus); - ret = hv_pci_protocol_negotiation(hdev); + ret = hv_pci_protocol_negotiation(hdev, pci_protocol_versions, + ARRAY_SIZE(pci_protocol_versions)); if (ret) goto close; @@ -2894,7 +2897,7 @@ static int hv_pci_probe(struct hv_device *hdev, return ret; } -static void hv_pci_bus_exit(struct hv_device *hdev) +static int hv_pci_bus_exit(struct hv_device *hdev, bool hibernating) { struct hv_pcibus_device *hbus = hv_get_drvdata(hdev); struct { @@ -2910,17 +2913,21 @@ static void hv_pci_bus_exit(struct hv_device *hdev) * access the per-channel ringbuffer any longer. */ if (hdev->channel->rescind) - return; + return 0; - /* Delete any children which might still exist. */ - dr = kzalloc(sizeof(*dr), GFP_KERNEL); - if (dr && hv_pci_start_relations_work(hbus, dr)) - kfree(dr); + if (!hibernating) { + /* Delete any children which might still exist. */ + dr = kzalloc(sizeof(*dr), GFP_KERNEL); + if (dr && hv_pci_start_relations_work(hbus, dr)) + kfree(dr); + } ret = hv_send_resources_released(hdev); - if (ret) + if (ret) { dev_err(&hdev->device, "Couldn't send resources released packet(s)\n"); + return ret; + } memset(&pkt.teardown_packet, 0, sizeof(pkt.teardown_packet)); init_completion(&comp_pkt.host_event); @@ -2933,8 +2940,14 @@ static void hv_pci_bus_exit(struct hv_device *hdev) (unsigned long)&pkt.teardown_packet, VM_PKT_DATA_INBAND, VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED); - if (!ret) - wait_for_completion_timeout(&comp_pkt.host_event, 10 * HZ); + if (ret) + return ret; + + if (wait_for_completion_timeout(&comp_pkt.host_event, 10 * HZ) == 0) + return -ETIMEDOUT; + + return 0; + } /** @@ -2946,6 +2959,7 @@ static void hv_pci_bus_exit(struct hv_device *hdev) static int hv_pci_remove(struct hv_device *hdev) { struct hv_pcibus_device *hbus; + int ret; hbus = hv_get_drvdata(hdev); if (hbus->state == hv_pcibus_installed) { @@ -2958,7 +2972,7 @@ static int hv_pci_remove(struct hv_device *hdev) hbus->state = hv_pcibus_removed; } - hv_pci_bus_exit(hdev); + ret = hv_pci_bus_exit(hdev, false); vmbus_close(hdev->channel); @@ -2975,7 +2989,7 @@ static int hv_pci_remove(struct hv_device *hdev) hv_put_dom_num(hbus->sysdata.domain); free_page((unsigned long)hbus); - return 0; + return ret; } static const struct hv_vmbus_device_id hv_pci_id_table[] = {