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 int 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
432 dev_info(&pdev->xdev->dev, "New device on " in pcifront_scan_bus()
440 static int pcifront_scan_root(struct pcifront_device *pdev, in pcifront_scan_root() argument
456 dev_err(&pdev->xdev->dev, in pcifront_scan_root()
458 dev_err(&pdev->xdev->dev, in pcifront_scan_root()
465 dev_info(&pdev->xdev->dev, "Creating PCI Frontend Bus %04x:%02x\n", in pcifront_scan_root()
477 pcifront_init_sd(sd, domain, bus, pdev); in pcifront_scan_root()
481 b = pci_scan_root_bus(&pdev->xdev->dev, bus, in pcifront_scan_root()
484 dev_err(&pdev->xdev->dev, in pcifront_scan_root()
494 list_add(&bus_entry->list, &pdev->root_buses); in pcifront_scan_root()
500 err = pcifront_scan_bus(pdev, domain, bus, b); in pcifront_scan_root()
503 pci_walk_bus(b, pcifront_claim_resource, pdev); in pcifront_scan_root()
518 static int pcifront_rescan_root(struct pcifront_device *pdev, in pcifront_rescan_root() argument
526 dev_err(&pdev->xdev->dev, in pcifront_rescan_root()
528 dev_err(&pdev->xdev->dev, in pcifront_rescan_root()
534 dev_info(&pdev->xdev->dev, "Rescanning PCI Frontend Bus %04x:%02x\n", in pcifront_rescan_root()
540 return pcifront_scan_root(pdev, domain, bus); in pcifront_rescan_root()
542 err = pcifront_scan_bus(pdev, domain, bus, b); in pcifront_rescan_root()
545 pci_walk_bus(b, pcifront_claim_resource, pdev); in pcifront_rescan_root()
565 static void pcifront_free_roots(struct pcifront_device *pdev) in pcifront_free_roots() argument
569 dev_dbg(&pdev->xdev->dev, "cleaning up root buses\n"); in pcifront_free_roots()
572 list_for_each_entry_safe(bus_entry, t, &pdev->root_buses, list) { in pcifront_free_roots()
588 struct pcifront_device *pdev, in pcifront_common_process() argument
592 int bus = pdev->sh_info->aer_op.bus; in pcifront_common_process()
593 int devfn = pdev->sh_info->aer_op.devfn; in pcifront_common_process()
594 int domain = pdev->sh_info->aer_op.domain; in pcifront_common_process()
597 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()
622 dev_err(&pdev->xdev->dev, in pcifront_common_process()
633 struct pcifront_device *pdev = in pcifront_do_aer() local
635 int cmd = pdev->sh_info->aer_op.cmd; in pcifront_do_aer()
637 (pci_channel_state_t)pdev->sh_info->aer_op.err; in pcifront_do_aer()
643 dev_dbg(&pdev->xdev->dev, in pcifront_do_aer()
645 pdev->sh_info->aer_op.bus, pdev->sh_info->aer_op.devfn); in pcifront_do_aer()
647 pdev->sh_info->aer_op.err = pcifront_common_process(cmd, pdev, state); in pcifront_do_aer()
651 clear_bit(_XEN_PCIB_active, (unsigned long *)&pdev->sh_info->flags); in pcifront_do_aer()
652 notify_remote_via_evtchn(pdev->evtchn); in pcifront_do_aer()
656 clear_bit(_PDEVB_op_active, &pdev->flags); in pcifront_do_aer()
659 schedule_pcifront_aer_op(pdev); in pcifront_do_aer()
665 struct pcifront_device *pdev = dev; in pcifront_handler_aer() local
667 schedule_pcifront_aer_op(pdev); in pcifront_handler_aer()
670 static int pcifront_connect_and_init_dma(struct pcifront_device *pdev) in pcifront_connect_and_init_dma() argument
677 dev_info(&pdev->xdev->dev, "Installing PCI frontend\n"); in pcifront_connect_and_init_dma()
678 pcifront_dev = pdev; in pcifront_connect_and_init_dma()
684 if (!err && !is_swiotlb_active(&pdev->xdev->dev)) { in pcifront_connect_and_init_dma()
687 dev_err(&pdev->xdev->dev, "Could not setup SWIOTLB!\n"); in pcifront_connect_and_init_dma()
692 static void pcifront_disconnect(struct pcifront_device *pdev) in pcifront_disconnect() argument
696 if (pdev == pcifront_dev) { in pcifront_disconnect()
697 dev_info(&pdev->xdev->dev, in pcifront_disconnect()
706 struct pcifront_device *pdev; in alloc_pdev() local
708 pdev = kzalloc(sizeof(struct pcifront_device), GFP_KERNEL); in alloc_pdev()
709 if (pdev == NULL) in alloc_pdev()
712 pdev->sh_info = in alloc_pdev()
714 if (pdev->sh_info == NULL) { in alloc_pdev()
715 kfree(pdev); in alloc_pdev()
716 pdev = NULL; in alloc_pdev()
719 pdev->sh_info->flags = 0; in alloc_pdev()
722 set_bit(_XEN_PCIB_AERHANDLER, (void *)&pdev->sh_info->flags); in alloc_pdev()
724 dev_set_drvdata(&xdev->dev, pdev); in alloc_pdev()
725 pdev->xdev = xdev; in alloc_pdev()
727 INIT_LIST_HEAD(&pdev->root_buses); in alloc_pdev()
729 spin_lock_init(&pdev->sh_info_lock); in alloc_pdev()
731 pdev->evtchn = INVALID_EVTCHN; in alloc_pdev()
732 pdev->gnt_ref = INVALID_GRANT_REF; in alloc_pdev()
733 pdev->irq = -1; in alloc_pdev()
735 INIT_WORK(&pdev->op_work, pcifront_do_aer); in alloc_pdev()
738 pdev, pdev->sh_info); in alloc_pdev()
740 return pdev; in alloc_pdev()
743 static void free_pdev(struct pcifront_device *pdev) in free_pdev() argument
745 dev_dbg(&pdev->xdev->dev, "freeing pdev @ 0x%p\n", pdev); in free_pdev()
747 pcifront_free_roots(pdev); in free_pdev()
749 cancel_work_sync(&pdev->op_work); in free_pdev()
751 if (pdev->irq >= 0) in free_pdev()
752 unbind_from_irqhandler(pdev->irq, pdev); in free_pdev()
754 if (pdev->evtchn != INVALID_EVTCHN) in free_pdev()
755 xenbus_free_evtchn(pdev->xdev, pdev->evtchn); in free_pdev()
757 if (pdev->gnt_ref != INVALID_GRANT_REF) in free_pdev()
758 gnttab_end_foreign_access(pdev->gnt_ref, 0 /* r/w page */, in free_pdev()
759 (unsigned long)pdev->sh_info); in free_pdev()
761 free_page((unsigned long)pdev->sh_info); in free_pdev()
763 dev_set_drvdata(&pdev->xdev->dev, NULL); in free_pdev()
765 kfree(pdev); in free_pdev()
768 static int pcifront_publish_info(struct pcifront_device *pdev) in pcifront_publish_info() argument
774 err = xenbus_grant_ring(pdev->xdev, pdev->sh_info, 1, &gref); in pcifront_publish_info()
778 pdev->gnt_ref = gref; in pcifront_publish_info()
780 err = xenbus_alloc_evtchn(pdev->xdev, &pdev->evtchn); in pcifront_publish_info()
784 err = bind_evtchn_to_irqhandler(pdev->evtchn, pcifront_handler_aer, in pcifront_publish_info()
785 0, "pcifront", pdev); in pcifront_publish_info()
790 pdev->irq = err; in pcifront_publish_info()
795 xenbus_dev_fatal(pdev->xdev, err, in pcifront_publish_info()
801 err = xenbus_printf(trans, pdev->xdev->nodename, in pcifront_publish_info()
802 "pci-op-ref", "%u", pdev->gnt_ref); in pcifront_publish_info()
804 err = xenbus_printf(trans, pdev->xdev->nodename, in pcifront_publish_info()
805 "event-channel", "%u", pdev->evtchn); in pcifront_publish_info()
807 err = xenbus_printf(trans, pdev->xdev->nodename, in pcifront_publish_info()
812 xenbus_dev_fatal(pdev->xdev, err, in pcifront_publish_info()
820 xenbus_dev_fatal(pdev->xdev, err, in pcifront_publish_info()
827 xenbus_switch_state(pdev->xdev, XenbusStateInitialised); in pcifront_publish_info()
829 dev_dbg(&pdev->xdev->dev, "publishing successful!\n"); in pcifront_publish_info()
835 static int pcifront_try_connect(struct pcifront_device *pdev) in pcifront_try_connect() argument
844 if (xenbus_read_driver_state(pdev->xdev->nodename) != in pcifront_try_connect()
848 err = pcifront_connect_and_init_dma(pdev); in pcifront_try_connect()
850 xenbus_dev_fatal(pdev->xdev, err, in pcifront_try_connect()
855 err = xenbus_scanf(XBT_NIL, pdev->xdev->otherend, in pcifront_try_connect()
858 xenbus_dev_error(pdev->xdev, err, in pcifront_try_connect()
860 err = pcifront_scan_root(pdev, 0, 0); in pcifront_try_connect()
862 xenbus_dev_fatal(pdev->xdev, err, in pcifront_try_connect()
870 xenbus_dev_fatal(pdev->xdev, err, in pcifront_try_connect()
882 err = xenbus_scanf(XBT_NIL, pdev->xdev->otherend, str, in pcifront_try_connect()
887 xenbus_dev_fatal(pdev->xdev, err, in pcifront_try_connect()
892 err = pcifront_scan_root(pdev, domain, bus); in pcifront_try_connect()
894 xenbus_dev_fatal(pdev->xdev, err, in pcifront_try_connect()
901 err = xenbus_switch_state(pdev->xdev, XenbusStateConnected); in pcifront_try_connect()
907 static int pcifront_try_disconnect(struct pcifront_device *pdev) in pcifront_try_disconnect() argument
913 prev_state = xenbus_read_driver_state(pdev->xdev->nodename); in pcifront_try_disconnect()
919 pcifront_free_roots(pdev); in pcifront_try_disconnect()
920 pcifront_disconnect(pdev); in pcifront_try_disconnect()
923 err = xenbus_switch_state(pdev->xdev, XenbusStateClosed); in pcifront_try_disconnect()
930 static int pcifront_attach_devices(struct pcifront_device *pdev) in pcifront_attach_devices() argument
937 if (xenbus_read_driver_state(pdev->xdev->nodename) != in pcifront_attach_devices()
941 err = xenbus_scanf(XBT_NIL, pdev->xdev->otherend, in pcifront_attach_devices()
944 xenbus_dev_error(pdev->xdev, err, in pcifront_attach_devices()
946 err = pcifront_rescan_root(pdev, 0, 0); in pcifront_attach_devices()
948 xenbus_dev_fatal(pdev->xdev, err, in pcifront_attach_devices()
956 xenbus_dev_fatal(pdev->xdev, err, in pcifront_attach_devices()
968 err = xenbus_scanf(XBT_NIL, pdev->xdev->otherend, str, in pcifront_attach_devices()
973 xenbus_dev_fatal(pdev->xdev, err, in pcifront_attach_devices()
978 err = pcifront_rescan_root(pdev, domain, bus); in pcifront_attach_devices()
980 xenbus_dev_fatal(pdev->xdev, err, in pcifront_attach_devices()
987 xenbus_switch_state(pdev->xdev, XenbusStateConnected); in pcifront_attach_devices()
993 static int pcifront_detach_devices(struct pcifront_device *pdev) in pcifront_detach_devices() argument
1001 if (xenbus_read_driver_state(pdev->xdev->nodename) != in pcifront_detach_devices()
1005 err = xenbus_scanf(XBT_NIL, pdev->xdev->otherend, "num_devs", "%d", in pcifront_detach_devices()
1010 xenbus_dev_fatal(pdev->xdev, err, in pcifront_detach_devices()
1024 state = xenbus_read_unsigned(pdev->xdev->otherend, str, in pcifront_detach_devices()
1036 err = xenbus_scanf(XBT_NIL, pdev->xdev->otherend, str, in pcifront_detach_devices()
1041 xenbus_dev_fatal(pdev->xdev, err, in pcifront_detach_devices()
1049 dev_dbg(&pdev->xdev->dev, in pcifront_detach_devices()
1059 dev_dbg(&pdev->xdev->dev, in pcifront_detach_devices()
1064 err = xenbus_switch_state(pdev->xdev, XenbusStateReconfiguring); in pcifront_detach_devices()
1073 struct pcifront_device *pdev = dev_get_drvdata(&xdev->dev); in pcifront_backend_changed() local
1083 pcifront_try_connect(pdev); in pcifront_backend_changed()
1092 pcifront_try_disconnect(pdev); in pcifront_backend_changed()
1096 pcifront_detach_devices(pdev); in pcifront_backend_changed()
1100 pcifront_attach_devices(pdev); in pcifront_backend_changed()
1109 struct pcifront_device *pdev = alloc_pdev(xdev); in pcifront_xenbus_probe() local
1111 if (pdev == NULL) { in pcifront_xenbus_probe()
1118 err = pcifront_publish_info(pdev); in pcifront_xenbus_probe()
1120 free_pdev(pdev); in pcifront_xenbus_probe()
1128 struct pcifront_device *pdev = dev_get_drvdata(&xdev->dev); in pcifront_xenbus_remove() local
1130 if (pdev) in pcifront_xenbus_remove()
1131 free_pdev(pdev); in pcifront_xenbus_remove()