Lines Matching refs:pdev
59 struct pcifront_device *pdev; member
65 return sd->pdev; in pcifront_get_pdev()
70 struct pcifront_device *pdev) in pcifront_init_sd() argument
75 sd->pdev = pdev; in pcifront_init_sd()
103 static inline void schedule_pcifront_aer_op(struct pcifront_device *pdev) in schedule_pcifront_aer_op() argument
105 if (test_bit(_XEN_PCIB_active, (unsigned long *)&pdev->sh_info->flags) in schedule_pcifront_aer_op()
106 && !test_and_set_bit(_PDEVB_op_active, &pdev->flags)) { in schedule_pcifront_aer_op()
107 dev_dbg(&pdev->xdev->dev, "schedule aer frontend job\n"); in schedule_pcifront_aer_op()
108 schedule_work(&pdev->op_work); in schedule_pcifront_aer_op()
112 static int do_pci_op(struct pcifront_device *pdev, struct xen_pci_op *op) in do_pci_op() argument
115 struct xen_pci_op *active_op = &pdev->sh_info->op; in do_pci_op()
117 evtchn_port_t port = pdev->evtchn; in do_pci_op()
118 unsigned irq = pdev->irq; in do_pci_op()
121 spin_lock_irqsave(&pdev->sh_info_lock, irq_flags); in do_pci_op()
127 set_bit(_XEN_PCIF_active, (unsigned long *)&pdev->sh_info->flags); in do_pci_op()
141 (unsigned long *)&pdev->sh_info->flags)) { in do_pci_op()
146 dev_err(&pdev->xdev->dev, in do_pci_op()
149 (unsigned long *)&pdev->sh_info->flags); in do_pci_op()
161 (unsigned long *)&pdev->sh_info->flags)) { in do_pci_op()
162 dev_err(&pdev->xdev->dev, in do_pci_op()
164 schedule_pcifront_aer_op(pdev); in do_pci_op()
171 spin_unlock_irqrestore(&pdev->sh_info_lock, irq_flags); in do_pci_op()
189 struct pcifront_device *pdev = pcifront_get_pdev(sd); in pcifront_bus_read() local
191 dev_dbg(&pdev->xdev->dev, in pcifront_bus_read()
196 err = do_pci_op(pdev, &op); in pcifront_bus_read()
199 dev_dbg(&pdev->xdev->dev, "read got back value %x\n", in pcifront_bus_read()
226 struct pcifront_device *pdev = pcifront_get_pdev(sd); in pcifront_bus_write() local
228 dev_dbg(&pdev->xdev->dev, in pcifront_bus_write()
233 return errno_to_pcibios_err(do_pci_op(pdev, &op)); in pcifront_bus_write()
255 struct pcifront_device *pdev = pcifront_get_pdev(sd); in pci_frontend_enable_msix() local
272 err = do_pci_op(pdev, &op); in pci_frontend_enable_msix()
307 struct pcifront_device *pdev = pcifront_get_pdev(sd); in pci_frontend_disable_msix() local
309 err = do_pci_op(pdev, &op); in pci_frontend_disable_msix()
326 struct pcifront_device *pdev = pcifront_get_pdev(sd); in pci_frontend_enable_msi() local
328 err = do_pci_op(pdev, &op); in pci_frontend_enable_msi()
355 struct pcifront_device *pdev = pcifront_get_pdev(sd); in pci_frontend_disable_msi() local
357 err = do_pci_op(pdev, &op); in pci_frontend_disable_msi()
389 struct pcifront_device *pdev = data; in pcifront_claim_resource() local
397 dev_info(&pdev->xdev->dev, "claiming resource %s/%d\n", in pcifront_claim_resource()
400 dev_err(&pdev->xdev->dev, "Could not claim resource %s/%d! " in pcifront_claim_resource()
410 static int pcifront_scan_bus(struct pcifront_device *pdev, in pcifront_scan_bus() argument
431 dev_info(&pdev->xdev->dev, "New device on " in pcifront_scan_bus()
439 static int pcifront_scan_root(struct pcifront_device *pdev, in pcifront_scan_root() argument
455 dev_err(&pdev->xdev->dev, in pcifront_scan_root()
457 dev_err(&pdev->xdev->dev, in pcifront_scan_root()
464 dev_info(&pdev->xdev->dev, "Creating PCI Frontend Bus %04x:%02x\n", in pcifront_scan_root()
476 pcifront_init_sd(sd, domain, bus, pdev); in pcifront_scan_root()
480 b = pci_scan_root_bus(&pdev->xdev->dev, bus, in pcifront_scan_root()
483 dev_err(&pdev->xdev->dev, in pcifront_scan_root()
493 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()
500 pci_walk_bus(b, pcifront_claim_resource, pdev); in pcifront_scan_root()
515 static int pcifront_rescan_root(struct pcifront_device *pdev, in pcifront_rescan_root() argument
523 dev_err(&pdev->xdev->dev, in pcifront_rescan_root()
525 dev_err(&pdev->xdev->dev, in pcifront_rescan_root()
531 dev_info(&pdev->xdev->dev, "Rescanning PCI Frontend Bus %04x:%02x\n", in pcifront_rescan_root()
537 return pcifront_scan_root(pdev, domain, bus); in pcifront_rescan_root()
539 err = pcifront_scan_bus(pdev, domain, bus, b); in pcifront_rescan_root()
542 pci_walk_bus(b, pcifront_claim_resource, pdev); in pcifront_rescan_root()
562 static void pcifront_free_roots(struct pcifront_device *pdev) in pcifront_free_roots() argument
566 dev_dbg(&pdev->xdev->dev, "cleaning up root buses\n"); in pcifront_free_roots()
569 list_for_each_entry_safe(bus_entry, t, &pdev->root_buses, list) { in pcifront_free_roots()
585 struct pcifront_device *pdev, in pcifront_common_process() argument
590 int bus = pdev->sh_info->aer_op.bus; in pcifront_common_process()
591 int devfn = pdev->sh_info->aer_op.devfn; in pcifront_common_process()
592 int domain = pdev->sh_info->aer_op.domain; in pcifront_common_process()
596 dev_dbg(&pdev->xdev->dev, in pcifront_common_process()
603 dev_err(&pdev->xdev->dev, "device or AER driver is NULL\n"); in pcifront_common_process()
631 dev_err(&pdev->xdev->dev, in pcifront_common_process()
648 struct pcifront_device *pdev = in pcifront_do_aer() local
650 int cmd = pdev->sh_info->aer_op.cmd; in pcifront_do_aer()
652 (pci_channel_state_t)pdev->sh_info->aer_op.err; in pcifront_do_aer()
656 dev_dbg(&pdev->xdev->dev, in pcifront_do_aer()
658 pdev->sh_info->aer_op.bus, pdev->sh_info->aer_op.devfn); in pcifront_do_aer()
660 pdev->sh_info->aer_op.err = pcifront_common_process(cmd, pdev, state); in pcifront_do_aer()
664 clear_bit(_XEN_PCIB_active, (unsigned long *)&pdev->sh_info->flags); in pcifront_do_aer()
665 notify_remote_via_evtchn(pdev->evtchn); in pcifront_do_aer()
669 clear_bit(_PDEVB_op_active, &pdev->flags); in pcifront_do_aer()
672 schedule_pcifront_aer_op(pdev); in pcifront_do_aer()
678 struct pcifront_device *pdev = dev; in pcifront_handler_aer() local
679 schedule_pcifront_aer_op(pdev); in pcifront_handler_aer()
682 static int pcifront_connect_and_init_dma(struct pcifront_device *pdev) in pcifront_connect_and_init_dma() argument
689 dev_info(&pdev->xdev->dev, "Installing PCI frontend\n"); in pcifront_connect_and_init_dma()
690 pcifront_dev = pdev; in pcifront_connect_and_init_dma()
699 dev_err(&pdev->xdev->dev, "Could not setup SWIOTLB!\n"); in pcifront_connect_and_init_dma()
704 static void pcifront_disconnect(struct pcifront_device *pdev) in pcifront_disconnect() argument
708 if (pdev == pcifront_dev) { in pcifront_disconnect()
709 dev_info(&pdev->xdev->dev, in pcifront_disconnect()
718 struct pcifront_device *pdev; in alloc_pdev() local
720 pdev = kzalloc(sizeof(struct pcifront_device), GFP_KERNEL); in alloc_pdev()
721 if (pdev == NULL) in alloc_pdev()
724 pdev->sh_info = in alloc_pdev()
726 if (pdev->sh_info == NULL) { in alloc_pdev()
727 kfree(pdev); in alloc_pdev()
728 pdev = NULL; in alloc_pdev()
731 pdev->sh_info->flags = 0; in alloc_pdev()
734 set_bit(_XEN_PCIB_AERHANDLER, (void *)&pdev->sh_info->flags); in alloc_pdev()
736 dev_set_drvdata(&xdev->dev, pdev); in alloc_pdev()
737 pdev->xdev = xdev; in alloc_pdev()
739 INIT_LIST_HEAD(&pdev->root_buses); in alloc_pdev()
741 spin_lock_init(&pdev->sh_info_lock); in alloc_pdev()
743 pdev->evtchn = INVALID_EVTCHN; in alloc_pdev()
744 pdev->gnt_ref = INVALID_GRANT_REF; in alloc_pdev()
745 pdev->irq = -1; in alloc_pdev()
747 INIT_WORK(&pdev->op_work, pcifront_do_aer); in alloc_pdev()
750 pdev, pdev->sh_info); in alloc_pdev()
752 return pdev; in alloc_pdev()
755 static void free_pdev(struct pcifront_device *pdev) in free_pdev() argument
757 dev_dbg(&pdev->xdev->dev, "freeing pdev @ 0x%p\n", pdev); in free_pdev()
759 pcifront_free_roots(pdev); in free_pdev()
761 cancel_work_sync(&pdev->op_work); in free_pdev()
763 if (pdev->irq >= 0) in free_pdev()
764 unbind_from_irqhandler(pdev->irq, pdev); in free_pdev()
766 if (pdev->evtchn != INVALID_EVTCHN) in free_pdev()
767 xenbus_free_evtchn(pdev->xdev, pdev->evtchn); in free_pdev()
769 if (pdev->gnt_ref != INVALID_GRANT_REF) in free_pdev()
770 gnttab_end_foreign_access(pdev->gnt_ref, 0 /* r/w page */, in free_pdev()
771 (unsigned long)pdev->sh_info); in free_pdev()
773 free_page((unsigned long)pdev->sh_info); in free_pdev()
775 dev_set_drvdata(&pdev->xdev->dev, NULL); in free_pdev()
777 kfree(pdev); in free_pdev()
780 static int pcifront_publish_info(struct pcifront_device *pdev) in pcifront_publish_info() argument
786 err = xenbus_grant_ring(pdev->xdev, pdev->sh_info, 1, &gref); in pcifront_publish_info()
790 pdev->gnt_ref = gref; in pcifront_publish_info()
792 err = xenbus_alloc_evtchn(pdev->xdev, &pdev->evtchn); in pcifront_publish_info()
796 err = bind_evtchn_to_irqhandler(pdev->evtchn, pcifront_handler_aer, in pcifront_publish_info()
797 0, "pcifront", pdev); in pcifront_publish_info()
802 pdev->irq = err; in pcifront_publish_info()
807 xenbus_dev_fatal(pdev->xdev, err, in pcifront_publish_info()
813 err = xenbus_printf(trans, pdev->xdev->nodename, in pcifront_publish_info()
814 "pci-op-ref", "%u", pdev->gnt_ref); in pcifront_publish_info()
816 err = xenbus_printf(trans, pdev->xdev->nodename, in pcifront_publish_info()
817 "event-channel", "%u", pdev->evtchn); in pcifront_publish_info()
819 err = xenbus_printf(trans, pdev->xdev->nodename, in pcifront_publish_info()
824 xenbus_dev_fatal(pdev->xdev, err, in pcifront_publish_info()
832 xenbus_dev_fatal(pdev->xdev, err, in pcifront_publish_info()
839 xenbus_switch_state(pdev->xdev, XenbusStateInitialised); in pcifront_publish_info()
841 dev_dbg(&pdev->xdev->dev, "publishing successful!\n"); in pcifront_publish_info()
847 static int pcifront_try_connect(struct pcifront_device *pdev) in pcifront_try_connect() argument
856 if (xenbus_read_driver_state(pdev->xdev->nodename) != in pcifront_try_connect()
860 err = pcifront_connect_and_init_dma(pdev); in pcifront_try_connect()
862 xenbus_dev_fatal(pdev->xdev, err, in pcifront_try_connect()
867 err = xenbus_scanf(XBT_NIL, pdev->xdev->otherend, in pcifront_try_connect()
870 xenbus_dev_error(pdev->xdev, err, in pcifront_try_connect()
872 err = pcifront_scan_root(pdev, 0, 0); in pcifront_try_connect()
874 xenbus_dev_fatal(pdev->xdev, err, in pcifront_try_connect()
882 xenbus_dev_fatal(pdev->xdev, err, in pcifront_try_connect()
894 err = xenbus_scanf(XBT_NIL, pdev->xdev->otherend, str, in pcifront_try_connect()
899 xenbus_dev_fatal(pdev->xdev, err, in pcifront_try_connect()
904 err = pcifront_scan_root(pdev, domain, bus); in pcifront_try_connect()
906 xenbus_dev_fatal(pdev->xdev, err, in pcifront_try_connect()
913 err = xenbus_switch_state(pdev->xdev, XenbusStateConnected); in pcifront_try_connect()
919 static int pcifront_try_disconnect(struct pcifront_device *pdev) in pcifront_try_disconnect() argument
925 prev_state = xenbus_read_driver_state(pdev->xdev->nodename); in pcifront_try_disconnect()
931 pcifront_free_roots(pdev); in pcifront_try_disconnect()
932 pcifront_disconnect(pdev); in pcifront_try_disconnect()
935 err = xenbus_switch_state(pdev->xdev, XenbusStateClosed); in pcifront_try_disconnect()
942 static int pcifront_attach_devices(struct pcifront_device *pdev) in pcifront_attach_devices() argument
949 if (xenbus_read_driver_state(pdev->xdev->nodename) != in pcifront_attach_devices()
953 err = xenbus_scanf(XBT_NIL, pdev->xdev->otherend, in pcifront_attach_devices()
956 xenbus_dev_error(pdev->xdev, err, in pcifront_attach_devices()
958 err = pcifront_rescan_root(pdev, 0, 0); in pcifront_attach_devices()
960 xenbus_dev_fatal(pdev->xdev, err, in pcifront_attach_devices()
968 xenbus_dev_fatal(pdev->xdev, err, in pcifront_attach_devices()
980 err = xenbus_scanf(XBT_NIL, pdev->xdev->otherend, str, in pcifront_attach_devices()
985 xenbus_dev_fatal(pdev->xdev, err, in pcifront_attach_devices()
990 err = pcifront_rescan_root(pdev, domain, bus); in pcifront_attach_devices()
992 xenbus_dev_fatal(pdev->xdev, err, in pcifront_attach_devices()
999 xenbus_switch_state(pdev->xdev, XenbusStateConnected); in pcifront_attach_devices()
1005 static int pcifront_detach_devices(struct pcifront_device *pdev) in pcifront_detach_devices() argument
1013 if (xenbus_read_driver_state(pdev->xdev->nodename) != in pcifront_detach_devices()
1017 err = xenbus_scanf(XBT_NIL, pdev->xdev->otherend, "num_devs", "%d", in pcifront_detach_devices()
1022 xenbus_dev_fatal(pdev->xdev, err, in pcifront_detach_devices()
1035 state = xenbus_read_unsigned(pdev->xdev->otherend, str, in pcifront_detach_devices()
1047 err = xenbus_scanf(XBT_NIL, pdev->xdev->otherend, str, in pcifront_detach_devices()
1052 xenbus_dev_fatal(pdev->xdev, err, in pcifront_detach_devices()
1060 dev_dbg(&pdev->xdev->dev, in pcifront_detach_devices()
1070 dev_dbg(&pdev->xdev->dev, in pcifront_detach_devices()
1075 err = xenbus_switch_state(pdev->xdev, XenbusStateReconfiguring); in pcifront_detach_devices()
1084 struct pcifront_device *pdev = dev_get_drvdata(&xdev->dev); in pcifront_backend_changed() local
1094 pcifront_try_connect(pdev); in pcifront_backend_changed()
1103 pcifront_try_disconnect(pdev); in pcifront_backend_changed()
1107 pcifront_detach_devices(pdev); in pcifront_backend_changed()
1111 pcifront_attach_devices(pdev); in pcifront_backend_changed()
1120 struct pcifront_device *pdev = alloc_pdev(xdev); in pcifront_xenbus_probe() local
1122 if (pdev == NULL) { in pcifront_xenbus_probe()
1129 err = pcifront_publish_info(pdev); in pcifront_xenbus_probe()
1131 free_pdev(pdev); in pcifront_xenbus_probe()
1139 struct pcifront_device *pdev = dev_get_drvdata(&xdev->dev); in pcifront_xenbus_remove() local
1140 if (pdev) in pcifront_xenbus_remove()
1141 free_pdev(pdev); in pcifront_xenbus_remove()