Lines Matching +full:bus +full:- +full:err

1 // SPDX-License-Identifier: GPL-2.0
27 #include <asm/xen/swiotlb-xen.h>
29 #define INVALID_EVTCHN (-1)
33 struct pci_bus *bus; member
64 return sd->pdev; in pcifront_get_pdev()
68 unsigned int domain, unsigned int bus, in pcifront_init_sd() argument
72 sd->sd.node = first_online_node; in pcifront_init_sd()
73 sd->sd.domain = domain; in pcifront_init_sd()
74 sd->pdev = pdev; in pcifront_init_sd()
104 if (test_bit(_XEN_PCIB_active, (unsigned long *)&pdev->sh_info->flags) in schedule_pcifront_aer_op()
105 && !test_and_set_bit(_PDEVB_op_active, &pdev->flags)) { in schedule_pcifront_aer_op()
106 dev_dbg(&pdev->xdev->dev, "schedule aer frontend job\n"); in schedule_pcifront_aer_op()
107 schedule_work(&pdev->op_work); in schedule_pcifront_aer_op()
113 int err = 0; in do_pci_op() local
114 struct xen_pci_op *active_op = &pdev->sh_info->op; in do_pci_op()
116 evtchn_port_t port = pdev->evtchn; in do_pci_op()
117 unsigned int irq = pdev->irq; in do_pci_op()
120 spin_lock_irqsave(&pdev->sh_info_lock, irq_flags); in do_pci_op()
126 set_bit(_XEN_PCIF_active, (unsigned long *)&pdev->sh_info->flags); in do_pci_op()
132 * (in the latter case we end up continually re-executing poll() with a in do_pci_op()
140 (unsigned long *)&pdev->sh_info->flags)) { in do_pci_op()
145 dev_err(&pdev->xdev->dev, in do_pci_op()
148 (unsigned long *)&pdev->sh_info->flags); in do_pci_op()
149 err = XEN_PCI_ERR_dev_not_found; in do_pci_op()
156 * reuse same evtchn with pci_conf backend response. So re-schedule in do_pci_op()
160 (unsigned long *)&pdev->sh_info->flags)) { in do_pci_op()
161 dev_err(&pdev->xdev->dev, in do_pci_op()
168 err = op->err; in do_pci_op()
170 spin_unlock_irqrestore(&pdev->sh_info_lock, irq_flags); in do_pci_op()
171 return err; in do_pci_op()
175 static int pcifront_bus_read(struct pci_bus *bus, unsigned int devfn, in pcifront_bus_read() argument
178 int err = 0; in pcifront_bus_read() local
181 .domain = pci_domain_nr(bus), in pcifront_bus_read()
182 .bus = bus->number, in pcifront_bus_read()
187 struct pcifront_sd *sd = bus->sysdata; in pcifront_bus_read()
190 dev_dbg(&pdev->xdev->dev, in pcifront_bus_read()
191 "read dev=%04x:%02x:%02x.%d - offset %x size %d\n", in pcifront_bus_read()
192 pci_domain_nr(bus), bus->number, PCI_SLOT(devfn), in pcifront_bus_read()
195 err = do_pci_op(pdev, &op); in pcifront_bus_read()
197 if (likely(!err)) { in pcifront_bus_read()
198 dev_dbg(&pdev->xdev->dev, "read got back value %x\n", in pcifront_bus_read()
202 } else if (err == -ENODEV) { in pcifront_bus_read()
204 err = 0; in pcifront_bus_read()
208 return errno_to_pcibios_err(err); in pcifront_bus_read()
212 static int pcifront_bus_write(struct pci_bus *bus, unsigned int devfn, in pcifront_bus_write() argument
217 .domain = pci_domain_nr(bus), in pcifront_bus_write()
218 .bus = bus->number, in pcifront_bus_write()
224 struct pcifront_sd *sd = bus->sysdata; in pcifront_bus_write()
227 dev_dbg(&pdev->xdev->dev, in pcifront_bus_write()
228 "write dev=%04x:%02x:%02x.%d - offset %x size %d val %x\n", in pcifront_bus_write()
229 pci_domain_nr(bus), bus->number, in pcifront_bus_write()
244 int err; in pci_frontend_enable_msix() local
248 .domain = pci_domain_nr(dev->bus), in pci_frontend_enable_msix()
249 .bus = dev->bus->number, in pci_frontend_enable_msix()
250 .devfn = dev->devfn, in pci_frontend_enable_msix()
253 struct pcifront_sd *sd = dev->bus->sysdata; in pci_frontend_enable_msix()
260 return -EINVAL; in pci_frontend_enable_msix()
264 msi_for_each_desc(entry, &dev->dev, MSI_DESC_NOTASSOCIATED) { in pci_frontend_enable_msix()
265 op.msix_entries[i].entry = entry->msi_index; in pci_frontend_enable_msix()
267 op.msix_entries[i].vector = -1; in pci_frontend_enable_msix()
271 err = do_pci_op(pdev, &op); in pci_frontend_enable_msix()
273 if (likely(!err)) { in pci_frontend_enable_msix()
278 pci_warn(dev, "MSI-X entry %d is invalid: %d!\n", in pci_frontend_enable_msix()
280 err = -EINVAL; in pci_frontend_enable_msix()
281 vector[i] = -1; in pci_frontend_enable_msix()
288 err = op.value; in pci_frontend_enable_msix()
291 pci_err(dev, "enable msix get err %x\n", err); in pci_frontend_enable_msix()
293 return err; in pci_frontend_enable_msix()
298 int err; in pci_frontend_disable_msix() local
301 .domain = pci_domain_nr(dev->bus), in pci_frontend_disable_msix()
302 .bus = dev->bus->number, in pci_frontend_disable_msix()
303 .devfn = dev->devfn, in pci_frontend_disable_msix()
305 struct pcifront_sd *sd = dev->bus->sysdata; in pci_frontend_disable_msix()
308 err = do_pci_op(pdev, &op); in pci_frontend_disable_msix()
311 if (err) in pci_frontend_disable_msix()
312 pci_err(dev, "pci_disable_msix get err %x\n", err); in pci_frontend_disable_msix()
317 int err; in pci_frontend_enable_msi() local
320 .domain = pci_domain_nr(dev->bus), in pci_frontend_enable_msi()
321 .bus = dev->bus->number, in pci_frontend_enable_msi()
322 .devfn = dev->devfn, in pci_frontend_enable_msi()
324 struct pcifront_sd *sd = dev->bus->sysdata; in pci_frontend_enable_msi()
327 err = do_pci_op(pdev, &op); in pci_frontend_enable_msi()
328 if (likely(!err)) { in pci_frontend_enable_msi()
333 err = -EINVAL; in pci_frontend_enable_msi()
334 vector[0] = -1; in pci_frontend_enable_msi()
338 "%x:%x\n", op.bus, op.devfn); in pci_frontend_enable_msi()
339 err = -EINVAL; in pci_frontend_enable_msi()
341 return err; in pci_frontend_enable_msi()
346 int err; in pci_frontend_disable_msi() local
349 .domain = pci_domain_nr(dev->bus), in pci_frontend_disable_msi()
350 .bus = dev->bus->number, in pci_frontend_disable_msi()
351 .devfn = dev->devfn, in pci_frontend_disable_msi()
353 struct pcifront_sd *sd = dev->bus->sysdata; in pci_frontend_disable_msi()
356 err = do_pci_op(pdev, &op); in pci_frontend_disable_msi()
357 if (err == XEN_PCI_ERR_dev_not_found) { in pci_frontend_disable_msi()
362 if (err) in pci_frontend_disable_msi()
385 /* Claim resources for the PCI frontend as-is, backend won't allow changes */
393 if (!r->parent && r->start && r->flags) { in pcifront_claim_resource()
394 dev_info(&pdev->xdev->dev, "claiming resource %s/%d\n", in pcifront_claim_resource()
397 dev_err(&pdev->xdev->dev, "Could not claim resource %s/%d! " in pcifront_claim_resource()
408 unsigned int domain, unsigned int bus, in pcifront_scan_bus() argument
415 * Scan the bus for functions and add. in pcifront_scan_bus()
429 dev_info(&pdev->xdev->dev, "New device on " in pcifront_scan_bus()
430 "%04x:%02x:%02x.%d found.\n", domain, bus, in pcifront_scan_bus()
438 unsigned int domain, unsigned int bus) in pcifront_scan_root() argument
444 int err = 0; in pcifront_scan_root() local
453 dev_err(&pdev->xdev->dev, in pcifront_scan_root()
454 "PCI Root in non-zero PCI Domain! domain=%d\n", domain); in pcifront_scan_root()
455 dev_err(&pdev->xdev->dev, in pcifront_scan_root()
457 err = -EINVAL; in pcifront_scan_root()
462 dev_info(&pdev->xdev->dev, "Creating PCI Frontend Bus %04x:%02x\n", in pcifront_scan_root()
463 domain, bus); in pcifront_scan_root()
468 err = -ENOMEM; in pcifront_scan_root()
474 pcifront_init_sd(sd, domain, bus, pdev); in pcifront_scan_root()
478 b = pci_scan_root_bus(&pdev->xdev->dev, bus, in pcifront_scan_root()
481 dev_err(&pdev->xdev->dev, in pcifront_scan_root()
482 "Error creating PCI Frontend Bus!\n"); in pcifront_scan_root()
483 err = -ENOMEM; in pcifront_scan_root()
489 bus_entry->bus = b; in pcifront_scan_root()
491 list_add(&bus_entry->list, &pdev->root_buses); in pcifront_scan_root()
497 err = pcifront_scan_bus(pdev, domain, bus, b); in pcifront_scan_root()
506 return err; in pcifront_scan_root()
512 return err; in pcifront_scan_root()
516 unsigned int domain, unsigned int bus) in pcifront_rescan_root() argument
518 int err; in pcifront_rescan_root() local
521 b = pci_find_bus(domain, bus); in pcifront_rescan_root()
523 /* If the bus is unknown, create it. */ in pcifront_rescan_root()
524 return pcifront_scan_root(pdev, domain, bus); in pcifront_rescan_root()
526 dev_info(&pdev->xdev->dev, "Rescanning PCI Frontend Bus %04x:%02x\n", in pcifront_rescan_root()
527 domain, bus); in pcifront_rescan_root()
529 err = pcifront_scan_bus(pdev, domain, bus, b); in pcifront_rescan_root()
537 return err; in pcifront_rescan_root()
540 static void free_root_bus_devs(struct pci_bus *bus) in free_root_bus_devs() argument
544 while (!list_empty(&bus->devices)) { in free_root_bus_devs()
545 dev = container_of(bus->devices.next, struct pci_dev, in free_root_bus_devs()
556 dev_dbg(&pdev->xdev->dev, "cleaning up root buses\n"); in pcifront_free_roots()
559 list_for_each_entry_safe(bus_entry, t, &pdev->root_buses, list) { in pcifront_free_roots()
560 list_del(&bus_entry->list); in pcifront_free_roots()
562 free_root_bus_devs(bus_entry->bus); in pcifront_free_roots()
564 kfree(bus_entry->bus->sysdata); in pcifront_free_roots()
566 device_unregister(bus_entry->bus->bridge); in pcifront_free_roots()
567 pci_remove_bus(bus_entry->bus); in pcifront_free_roots()
579 int bus = pdev->sh_info->aer_op.bus; in pcifront_common_process() local
580 int devfn = pdev->sh_info->aer_op.devfn; in pcifront_common_process()
581 int domain = pdev->sh_info->aer_op.domain; in pcifront_common_process()
584 dev_dbg(&pdev->xdev->dev, in pcifront_common_process()
585 "pcifront AER process: cmd %x (bus:%x, devfn%x)", in pcifront_common_process()
586 cmd, bus, devfn); in pcifront_common_process()
588 pcidev = pci_get_domain_bus_and_slot(domain, bus, devfn); in pcifront_common_process()
589 if (!pcidev || !pcidev->dev.driver) { in pcifront_common_process()
590 dev_err(&pdev->xdev->dev, "device or AER driver is NULL\n"); in pcifront_common_process()
594 pdrv = to_pci_driver(pcidev->dev.driver); in pcifront_common_process()
596 if (pdrv->err_handler && pdrv->err_handler->error_detected) { in pcifront_common_process()
600 return pdrv->err_handler->error_detected(pcidev, state); in pcifront_common_process()
602 return pdrv->err_handler->mmio_enabled(pcidev); in pcifront_common_process()
604 return pdrv->err_handler->slot_reset(pcidev); in pcifront_common_process()
606 pdrv->err_handler->resume(pcidev); in pcifront_common_process()
609 dev_err(&pdev->xdev->dev, in pcifront_common_process()
622 int cmd = pdev->sh_info->aer_op.cmd; in pcifront_do_aer()
624 (pci_channel_state_t)pdev->sh_info->aer_op.err; in pcifront_do_aer()
630 dev_dbg(&pdev->xdev->dev, in pcifront_do_aer()
631 "pcifront service aer bus %x devfn %x\n", in pcifront_do_aer()
632 pdev->sh_info->aer_op.bus, pdev->sh_info->aer_op.devfn); in pcifront_do_aer()
634 pdev->sh_info->aer_op.err = pcifront_common_process(cmd, pdev, state); in pcifront_do_aer()
638 clear_bit(_XEN_PCIB_active, (unsigned long *)&pdev->sh_info->flags); in pcifront_do_aer()
639 notify_remote_via_evtchn(pdev->evtchn); in pcifront_do_aer()
643 clear_bit(_PDEVB_op_active, &pdev->flags); in pcifront_do_aer()
659 int err = 0; in pcifront_connect_and_init_dma() local
664 dev_info(&pdev->xdev->dev, "Installing PCI frontend\n"); in pcifront_connect_and_init_dma()
667 err = -EEXIST; in pcifront_connect_and_init_dma()
671 return err; in pcifront_connect_and_init_dma()
679 dev_info(&pdev->xdev->dev, in pcifront_disconnect()
694 if (xenbus_setup_ring(xdev, GFP_KERNEL, (void **)&pdev->sh_info, 1, in alloc_pdev()
695 &pdev->gnt_ref)) { in alloc_pdev()
700 pdev->sh_info->flags = 0; in alloc_pdev()
703 set_bit(_XEN_PCIB_AERHANDLER, (void *)&pdev->sh_info->flags); in alloc_pdev()
705 dev_set_drvdata(&xdev->dev, pdev); in alloc_pdev()
706 pdev->xdev = xdev; in alloc_pdev()
708 INIT_LIST_HEAD(&pdev->root_buses); in alloc_pdev()
710 spin_lock_init(&pdev->sh_info_lock); in alloc_pdev()
712 pdev->evtchn = INVALID_EVTCHN; in alloc_pdev()
713 pdev->irq = -1; in alloc_pdev()
715 INIT_WORK(&pdev->op_work, pcifront_do_aer); in alloc_pdev()
717 dev_dbg(&xdev->dev, "Allocated pdev @ 0x%p pdev->sh_info @ 0x%p\n", in alloc_pdev()
718 pdev, pdev->sh_info); in alloc_pdev()
725 dev_dbg(&pdev->xdev->dev, "freeing pdev @ 0x%p\n", pdev); in free_pdev()
729 cancel_work_sync(&pdev->op_work); in free_pdev()
731 if (pdev->irq >= 0) in free_pdev()
732 unbind_from_irqhandler(pdev->irq, pdev); in free_pdev()
734 if (pdev->evtchn != INVALID_EVTCHN) in free_pdev()
735 xenbus_free_evtchn(pdev->xdev, pdev->evtchn); in free_pdev()
737 xenbus_teardown_ring((void **)&pdev->sh_info, 1, &pdev->gnt_ref); in free_pdev()
739 dev_set_drvdata(&pdev->xdev->dev, NULL); in free_pdev()
746 int err = 0; in pcifront_publish_info() local
749 err = xenbus_alloc_evtchn(pdev->xdev, &pdev->evtchn); in pcifront_publish_info()
750 if (err) in pcifront_publish_info()
753 err = bind_evtchn_to_irqhandler(pdev->evtchn, pcifront_handler_aer, in pcifront_publish_info()
756 if (err < 0) in pcifront_publish_info()
757 return err; in pcifront_publish_info()
759 pdev->irq = err; in pcifront_publish_info()
762 err = xenbus_transaction_start(&trans); in pcifront_publish_info()
763 if (err) { in pcifront_publish_info()
764 xenbus_dev_fatal(pdev->xdev, err, in pcifront_publish_info()
770 err = xenbus_printf(trans, pdev->xdev->nodename, in pcifront_publish_info()
771 "pci-op-ref", "%u", pdev->gnt_ref); in pcifront_publish_info()
772 if (!err) in pcifront_publish_info()
773 err = xenbus_printf(trans, pdev->xdev->nodename, in pcifront_publish_info()
774 "event-channel", "%u", pdev->evtchn); in pcifront_publish_info()
775 if (!err) in pcifront_publish_info()
776 err = xenbus_printf(trans, pdev->xdev->nodename, in pcifront_publish_info()
779 if (err) { in pcifront_publish_info()
781 xenbus_dev_fatal(pdev->xdev, err, in pcifront_publish_info()
785 err = xenbus_transaction_end(trans, 0); in pcifront_publish_info()
786 if (err == -EAGAIN) in pcifront_publish_info()
788 else if (err) { in pcifront_publish_info()
789 xenbus_dev_fatal(pdev->xdev, err, in pcifront_publish_info()
796 xenbus_switch_state(pdev->xdev, XenbusStateInitialised); in pcifront_publish_info()
798 dev_dbg(&pdev->xdev->dev, "publishing successful!\n"); in pcifront_publish_info()
801 return err; in pcifront_publish_info()
806 int err; in pcifront_connect() local
809 unsigned int domain, bus; in pcifront_connect() local
811 err = xenbus_scanf(XBT_NIL, pdev->xdev->otherend, in pcifront_connect()
813 if (err == -ENOENT) { in pcifront_connect()
814 xenbus_dev_error(pdev->xdev, err, in pcifront_connect()
816 err = pcifront_rescan_root(pdev, 0, 0); in pcifront_connect()
817 if (err) { in pcifront_connect()
818 xenbus_dev_fatal(pdev->xdev, err, in pcifront_connect()
823 } else if (err != 1) { in pcifront_connect()
824 xenbus_dev_fatal(pdev->xdev, err >= 0 ? -EINVAL : err, in pcifront_connect()
830 len = snprintf(str, sizeof(str), "root-%d", i); in pcifront_connect()
831 if (unlikely(len >= (sizeof(str) - 1))) in pcifront_connect()
834 err = xenbus_scanf(XBT_NIL, pdev->xdev->otherend, str, in pcifront_connect()
835 "%x:%x", &domain, &bus); in pcifront_connect()
836 if (err != 2) { in pcifront_connect()
837 xenbus_dev_fatal(pdev->xdev, err >= 0 ? -EINVAL : err, in pcifront_connect()
842 err = pcifront_rescan_root(pdev, domain, bus); in pcifront_connect()
843 if (err) { in pcifront_connect()
844 xenbus_dev_fatal(pdev->xdev, err, in pcifront_connect()
846 domain, bus); in pcifront_connect()
851 xenbus_switch_state(pdev->xdev, XenbusStateConnected); in pcifront_connect()
856 int err; in pcifront_try_connect() local
859 if (xenbus_read_driver_state(pdev->xdev->nodename) != in pcifront_try_connect()
863 err = pcifront_connect_and_init_dma(pdev); in pcifront_try_connect()
864 if (err && err != -EEXIST) { in pcifront_try_connect()
865 xenbus_dev_fatal(pdev->xdev, err, in pcifront_try_connect()
875 int err = 0; in pcifront_try_disconnect() local
879 prev_state = xenbus_read_driver_state(pdev->xdev->nodename); in pcifront_try_disconnect()
889 err = xenbus_switch_state(pdev->xdev, XenbusStateClosed); in pcifront_try_disconnect()
893 return err; in pcifront_try_disconnect()
898 if (xenbus_read_driver_state(pdev->xdev->nodename) == in pcifront_attach_devices()
905 int err = 0; in pcifront_detach_devices() local
908 unsigned int domain, bus, slot, func; in pcifront_detach_devices() local
912 state = xenbus_read_driver_state(pdev->xdev->nodename); in pcifront_detach_devices()
914 dev_dbg(&pdev->xdev->dev, "Handle skipped connect.\n"); in pcifront_detach_devices()
916 err = pcifront_connect_and_init_dma(pdev); in pcifront_detach_devices()
917 if (err && err != -EEXIST) { in pcifront_detach_devices()
918 xenbus_dev_fatal(pdev->xdev, err, in pcifront_detach_devices()
928 err = xenbus_scanf(XBT_NIL, pdev->xdev->otherend, "num_devs", "%d", in pcifront_detach_devices()
930 if (err != 1) { in pcifront_detach_devices()
931 if (err >= 0) in pcifront_detach_devices()
932 err = -EINVAL; in pcifront_detach_devices()
933 xenbus_dev_fatal(pdev->xdev, err, in pcifront_detach_devices()
942 l = snprintf(str, sizeof(str), "state-%d", i); in pcifront_detach_devices()
943 if (unlikely(l >= (sizeof(str) - 1))) { in pcifront_detach_devices()
944 err = -ENOMEM; in pcifront_detach_devices()
947 state = xenbus_read_unsigned(pdev->xdev->otherend, str, in pcifront_detach_devices()
954 l = snprintf(str, sizeof(str), "vdev-%d", i); in pcifront_detach_devices()
955 if (unlikely(l >= (sizeof(str) - 1))) { in pcifront_detach_devices()
956 err = -ENOMEM; in pcifront_detach_devices()
959 err = xenbus_scanf(XBT_NIL, pdev->xdev->otherend, str, in pcifront_detach_devices()
960 "%x:%x:%x.%x", &domain, &bus, &slot, &func); in pcifront_detach_devices()
961 if (err != 4) { in pcifront_detach_devices()
962 if (err >= 0) in pcifront_detach_devices()
963 err = -EINVAL; in pcifront_detach_devices()
964 xenbus_dev_fatal(pdev->xdev, err, in pcifront_detach_devices()
969 pci_dev = pci_get_domain_bus_and_slot(domain, bus, in pcifront_detach_devices()
972 dev_dbg(&pdev->xdev->dev, in pcifront_detach_devices()
974 domain, bus, slot, func); in pcifront_detach_devices()
982 dev_dbg(&pdev->xdev->dev, in pcifront_detach_devices()
984 domain, bus, slot, func); in pcifront_detach_devices()
988 err = xenbus_switch_state(pdev->xdev, XenbusStateReconfiguring); in pcifront_detach_devices()
991 return err; in pcifront_detach_devices()
997 struct pcifront_device *pdev = dev_get_drvdata(&xdev->dev); in pcifront_backend_changed()
1011 if (xdev->state == XenbusStateClosed) in pcifront_backend_changed()
1015 dev_warn(&xdev->dev, "backend going away!\n"); in pcifront_backend_changed()
1032 int err = 0; in pcifront_xenbus_probe() local
1036 err = -ENOMEM; in pcifront_xenbus_probe()
1037 xenbus_dev_fatal(xdev, err, in pcifront_xenbus_probe()
1042 err = pcifront_publish_info(pdev); in pcifront_xenbus_probe()
1043 if (err) in pcifront_xenbus_probe()
1047 return err; in pcifront_xenbus_probe()
1052 struct pcifront_device *pdev = dev_get_drvdata(&xdev->dev); in pcifront_xenbus_remove()
1074 return -ENODEV; in pcifront_init()
1077 return -ENODEV; in pcifront_init()