Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * PCI Backend Operations - respond to PCI requests from Frontend
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  *   Author: Ryan Wilson <hap9@epoch.ncsc.mil>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) #define dev_fmt pr_fmt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include <linux/moduleparam.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <linux/wait.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <linux/bitops.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <xen/events.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <linux/sched.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include "pciback.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) static irqreturn_t xen_pcibk_guest_interrupt(int irq, void *dev_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) /* Ensure a device is has the fake IRQ handler "turned on/off" and is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21)  * ready to be exported. This MUST be run after xen_pcibk_reset_device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22)  * which does the actual PCI device enable/disable.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) static void xen_pcibk_control_isr(struct pci_dev *dev, int reset)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) 	struct xen_pcibk_dev_data *dev_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 	int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 	int enable = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 	dev_data = pci_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 	if (!dev_data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 	/* We don't deal with bridges */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 	if (dev->hdr_type != PCI_HEADER_TYPE_NORMAL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 	if (reset) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 		dev_data->enable_intx = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 		dev_data->ack_intr = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 	enable =  dev_data->enable_intx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 	/* Asked to disable, but ISR isn't runnig */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 	if (!enable && !dev_data->isr_on)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 	/* Squirrel away the IRQs in the dev_data. We need this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 	 * b/c when device transitions to MSI, the dev->irq is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 	 * overwritten with the MSI vector.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 	if (enable)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 		dev_data->irq = dev->irq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 	 * SR-IOV devices in all use MSI-X and have no legacy
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 	 * interrupts, so inhibit creating a fake IRQ handler for them.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 	if (dev_data->irq == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 	dev_dbg(&dev->dev, "%s: #%d %s %s%s %s-> %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 		dev_data->irq_name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 		dev_data->irq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 		pci_is_enabled(dev) ? "on" : "off",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 		dev->msi_enabled ? "MSI" : "",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 		dev->msix_enabled ? "MSI/X" : "",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 		dev_data->isr_on ? "enable" : "disable",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 		enable ? "enable" : "disable");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 	if (enable) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 		 * The MSI or MSI-X should not have an IRQ handler. Otherwise
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 		 * if the guest terminates we BUG_ON in free_msi_irqs.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 		if (dev->msi_enabled || dev->msix_enabled)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 			goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 		rc = request_irq(dev_data->irq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 				xen_pcibk_guest_interrupt, IRQF_SHARED,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 				dev_data->irq_name, dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 		if (rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 			dev_err(&dev->dev, "%s: failed to install fake IRQ " \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 				"handler for IRQ %d! (rc:%d)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 				dev_data->irq_name, dev_data->irq, rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 			goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 		free_irq(dev_data->irq, dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 		dev_data->irq = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 	dev_data->isr_on = enable;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 	dev_data->ack_intr = enable;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 	dev_dbg(&dev->dev, "%s: #%d %s %s%s %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 		dev_data->irq_name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 		dev_data->irq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 		pci_is_enabled(dev) ? "on" : "off",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 		dev->msi_enabled ? "MSI" : "",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 		dev->msix_enabled ? "MSI/X" : "",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 		enable ? (dev_data->isr_on ? "enabled" : "failed to enable") :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 			(dev_data->isr_on ? "failed to disable" : "disabled"));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) /* Ensure a device is "turned off" and ready to be exported.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106)  * (Also see xen_pcibk_config_reset to ensure virtual configuration space is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107)  * ready to be re-exported)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) void xen_pcibk_reset_device(struct pci_dev *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 	u16 cmd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 	xen_pcibk_control_isr(dev, 1 /* reset device */);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 	/* Disable devices (but not bridges) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 	if (dev->hdr_type == PCI_HEADER_TYPE_NORMAL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) #ifdef CONFIG_PCI_MSI
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 		/* The guest could have been abruptly killed without
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 		 * disabling MSI/MSI-X interrupts.*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 		if (dev->msix_enabled)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 			pci_disable_msix(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 		if (dev->msi_enabled)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 			pci_disable_msi(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 		if (pci_is_enabled(dev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 			pci_disable_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 		dev->is_busmaster = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 		pci_read_config_word(dev, PCI_COMMAND, &cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 		if (cmd & (PCI_COMMAND_INVALIDATE)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 			cmd &= ~(PCI_COMMAND_INVALIDATE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 			pci_write_config_word(dev, PCI_COMMAND, cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 			dev->is_busmaster = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) #ifdef CONFIG_PCI_MSI
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) static
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) int xen_pcibk_enable_msi(struct xen_pcibk_device *pdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 			 struct pci_dev *dev, struct xen_pci_op *op)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 	struct xen_pcibk_dev_data *dev_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 	int status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 	if (dev->msi_enabled)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 		status = -EALREADY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 	else if (dev->msix_enabled)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 		status = -ENXIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 		status = pci_enable_msi(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 	if (status) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 		dev_warn_ratelimited(&dev->dev, "error enabling MSI for guest %u: err %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 				     pdev->xdev->otherend_id, status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 		op->value = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 		return XEN_PCI_ERR_op_failed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 	/* The value the guest needs is actually the IDT vector, not the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 	 * the local domain's IRQ number. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 	op->value = dev->irq ? xen_pirq_from_irq(dev->irq) : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 	dev_dbg(&dev->dev, "MSI: %d\n", op->value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 	dev_data = pci_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 	if (dev_data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 		dev_data->ack_intr = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) static
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) int xen_pcibk_disable_msi(struct xen_pcibk_device *pdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 			  struct pci_dev *dev, struct xen_pci_op *op)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 	if (dev->msi_enabled) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 		struct xen_pcibk_dev_data *dev_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 		pci_disable_msi(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 		dev_data = pci_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 		if (dev_data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 			dev_data->ack_intr = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 	op->value = dev->irq ? xen_pirq_from_irq(dev->irq) : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 	dev_dbg(&dev->dev, "MSI: %d\n", op->value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) static
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) int xen_pcibk_enable_msix(struct xen_pcibk_device *pdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 			  struct pci_dev *dev, struct xen_pci_op *op)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 	struct xen_pcibk_dev_data *dev_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 	int i, result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 	struct msix_entry *entries;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 	u16 cmd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 	dev_dbg(&dev->dev, "enable MSI-X\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 	if (op->value > SH_INFO_MAX_VEC)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 	if (dev->msix_enabled)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 		return -EALREADY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 	 * PCI_COMMAND_MEMORY must be enabled, otherwise we may not be able
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 	 * to access the BARs where the MSI-X entries reside.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 	 * But VF devices are unique in which the PF needs to be checked.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 	pci_read_config_word(pci_physfn(dev), PCI_COMMAND, &cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 	if (dev->msi_enabled || !(cmd & PCI_COMMAND_MEMORY))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 		return -ENXIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 	entries = kmalloc_array(op->value, sizeof(*entries), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 	if (entries == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 	for (i = 0; i < op->value; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 		entries[i].entry = op->msix_entries[i].entry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 		entries[i].vector = op->msix_entries[i].vector;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 	result = pci_enable_msix_exact(dev, entries, op->value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 	if (result == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 		for (i = 0; i < op->value; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 			op->msix_entries[i].entry = entries[i].entry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 			if (entries[i].vector) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 				op->msix_entries[i].vector =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 					xen_pirq_from_irq(entries[i].vector);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 				dev_dbg(&dev->dev, "MSI-X[%d]: %d\n", i,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 					op->msix_entries[i].vector);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 	} else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 		dev_warn_ratelimited(&dev->dev, "error enabling MSI-X for guest %u: err %d!\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 				     pdev->xdev->otherend_id, result);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 	kfree(entries);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 	op->value = result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 	dev_data = pci_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 	if (dev_data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 		dev_data->ack_intr = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 	return result > 0 ? 0 : result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) static
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) int xen_pcibk_disable_msix(struct xen_pcibk_device *pdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 			   struct pci_dev *dev, struct xen_pci_op *op)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 	if (dev->msix_enabled) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 		struct xen_pcibk_dev_data *dev_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 		pci_disable_msix(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 		dev_data = pci_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 		if (dev_data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 			dev_data->ack_intr = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 	 * SR-IOV devices (which don't have any legacy IRQ) have
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 	 * an undefined IRQ value of zero.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 	op->value = dev->irq ? xen_pirq_from_irq(dev->irq) : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 	dev_dbg(&dev->dev, "MSI-X: %d\n", op->value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) static inline bool xen_pcibk_test_op_pending(struct xen_pcibk_device *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 	return test_bit(_XEN_PCIF_active,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 			(unsigned long *)&pdev->sh_info->flags) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 	       !test_and_set_bit(_PDEVF_op_active, &pdev->flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) * Now the same evtchn is used for both pcifront conf_read_write request
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) * as well as pcie aer front end ack. We use a new work_queue to schedule
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) * xen_pcibk conf_read_write service for avoiding confict with aer_core
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) * do_recovery job which also use the system default work_queue
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) static void xen_pcibk_test_and_schedule_op(struct xen_pcibk_device *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 	bool eoi = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 	/* Check that frontend is requesting an operation and that we are not
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 	 * already processing a request */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 	if (xen_pcibk_test_op_pending(pdev)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 		schedule_work(&pdev->op_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 		eoi = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 	/*_XEN_PCIB_active should have been cleared by pcifront. And also make
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 	sure xen_pcibk is waiting for ack by checking _PCIB_op_pending*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 	if (!test_bit(_XEN_PCIB_active, (unsigned long *)&pdev->sh_info->flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 	    && test_bit(_PCIB_op_pending, &pdev->flags)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) 		wake_up(&xen_pcibk_aer_wait_queue);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 		eoi = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) 	/* EOI if there was nothing to do. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 	if (eoi)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) 		xen_pcibk_lateeoi(pdev, XEN_EOI_FLAG_SPURIOUS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) /* Performing the configuration space reads/writes must not be done in atomic
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317)  * context because some of the pci_* functions can sleep (mostly due to ACPI
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318)  * use of semaphores). This function is intended to be called from a work
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319)  * queue in process context taking a struct xen_pcibk_device as a parameter */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) static void xen_pcibk_do_one_op(struct xen_pcibk_device *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) 	struct pci_dev *dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) 	struct xen_pcibk_dev_data *dev_data = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) 	struct xen_pci_op *op = &pdev->op;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) 	int test_intx = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) #ifdef CONFIG_PCI_MSI
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) 	unsigned int nr = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) 	*op = pdev->sh_info->op;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) 	barrier();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) 	dev = xen_pcibk_get_pci_dev(pdev, op->domain, op->bus, op->devfn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) 	if (dev == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) 		op->err = XEN_PCI_ERR_dev_not_found;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) 	else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) 		dev_data = pci_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) 		if (dev_data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) 			test_intx = dev_data->enable_intx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) 		switch (op->cmd) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) 		case XEN_PCI_OP_conf_read:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) 			op->err = xen_pcibk_config_read(dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) 				  op->offset, op->size, &op->value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) 		case XEN_PCI_OP_conf_write:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) 			op->err = xen_pcibk_config_write(dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) 				  op->offset, op->size,	op->value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) #ifdef CONFIG_PCI_MSI
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) 		case XEN_PCI_OP_enable_msi:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) 			op->err = xen_pcibk_enable_msi(pdev, dev, op);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) 		case XEN_PCI_OP_disable_msi:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) 			op->err = xen_pcibk_disable_msi(pdev, dev, op);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) 		case XEN_PCI_OP_enable_msix:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) 			nr = op->value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) 			op->err = xen_pcibk_enable_msix(pdev, dev, op);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) 		case XEN_PCI_OP_disable_msix:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) 			op->err = xen_pcibk_disable_msix(pdev, dev, op);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) 		default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) 			op->err = XEN_PCI_ERR_not_implemented;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) 	if (!op->err && dev && dev_data) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) 		/* Transition detected */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) 		if ((dev_data->enable_intx != test_intx))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) 			xen_pcibk_control_isr(dev, 0 /* no reset */);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) 	pdev->sh_info->op.err = op->err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) 	pdev->sh_info->op.value = op->value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) #ifdef CONFIG_PCI_MSI
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) 	if (op->cmd == XEN_PCI_OP_enable_msix && op->err == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) 		unsigned int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) 		for (i = 0; i < nr; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) 			pdev->sh_info->op.msix_entries[i].vector =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) 				op->msix_entries[i].vector;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) 	/* Tell the driver domain that we're done. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) 	wmb();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) 	clear_bit(_XEN_PCIF_active, (unsigned long *)&pdev->sh_info->flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) 	notify_remote_via_irq(pdev->evtchn_irq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) 	/* Mark that we're done. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) 	smp_mb__before_atomic(); /* /after/ clearing PCIF_active */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) 	clear_bit(_PDEVF_op_active, &pdev->flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) 	smp_mb__after_atomic(); /* /before/ final check for work */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) void xen_pcibk_do_op(struct work_struct *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) 	struct xen_pcibk_device *pdev =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) 		container_of(data, struct xen_pcibk_device, op_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) 	do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) 		xen_pcibk_do_one_op(pdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) 	} while (xen_pcibk_test_op_pending(pdev));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) 	xen_pcibk_lateeoi(pdev, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) irqreturn_t xen_pcibk_handle_event(int irq, void *dev_id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) 	struct xen_pcibk_device *pdev = dev_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) 	bool eoi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) 	/* IRQs might come in before pdev->evtchn_irq is written. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) 	if (unlikely(pdev->evtchn_irq != irq))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) 		pdev->evtchn_irq = irq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) 	eoi = test_and_set_bit(_EOI_pending, &pdev->flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) 	WARN(eoi, "IRQ while EOI pending\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) 	xen_pcibk_test_and_schedule_op(pdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) 	return IRQ_HANDLED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) static irqreturn_t xen_pcibk_guest_interrupt(int irq, void *dev_id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) 	struct pci_dev *dev = (struct pci_dev *)dev_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) 	struct xen_pcibk_dev_data *dev_data = pci_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) 	if (dev_data->isr_on && dev_data->ack_intr) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) 		dev_data->handled++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) 		if ((dev_data->handled % 1000) == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) 			if (xen_test_irq_shared(irq)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) 				dev_info(&dev->dev, "%s IRQ line is not shared "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) 					"with other domains. Turning ISR off\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) 					 dev_data->irq_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) 				dev_data->ack_intr = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) 		return IRQ_HANDLED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) 	return IRQ_NONE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) }