Lines Matching refs:ap_dev
59 static int __ap_poll_device(struct ap_device *ap_dev, unsigned long *flags);
63 static void ap_reset(struct ap_device *ap_dev);
625 static void ap_increase_queue_count(struct ap_device *ap_dev) in ap_increase_queue_count() argument
627 int timeout = ap_dev->drv->request_timeout; in ap_increase_queue_count()
629 ap_dev->queue_count++; in ap_increase_queue_count()
630 if (ap_dev->queue_count == 1) { in ap_increase_queue_count()
631 mod_timer(&ap_dev->timeout, jiffies + timeout); in ap_increase_queue_count()
632 ap_dev->reset = AP_RESET_ARMED; in ap_increase_queue_count()
643 static void ap_decrease_queue_count(struct ap_device *ap_dev) in ap_decrease_queue_count() argument
645 int timeout = ap_dev->drv->request_timeout; in ap_decrease_queue_count()
647 ap_dev->queue_count--; in ap_decrease_queue_count()
648 if (ap_dev->queue_count > 0) in ap_decrease_queue_count()
649 mod_timer(&ap_dev->timeout, jiffies + timeout); in ap_decrease_queue_count()
656 ap_dev->reset = AP_RESET_IGNORE; in ap_decrease_queue_count()
665 struct ap_device *ap_dev = to_ap_dev(dev); in ap_hwtype_show() local
666 return snprintf(buf, PAGE_SIZE, "%d\n", ap_dev->device_type); in ap_hwtype_show()
674 struct ap_device *ap_dev = to_ap_dev(dev); in ap_raw_hwtype_show() local
676 return snprintf(buf, PAGE_SIZE, "%d\n", ap_dev->raw_hwtype); in ap_raw_hwtype_show()
684 struct ap_device *ap_dev = to_ap_dev(dev); in ap_depth_show() local
685 return snprintf(buf, PAGE_SIZE, "%d\n", ap_dev->queue_depth); in ap_depth_show()
693 struct ap_device *ap_dev = to_ap_dev(dev); in ap_request_count_show() local
696 spin_lock_bh(&ap_dev->lock); in ap_request_count_show()
697 rc = snprintf(buf, PAGE_SIZE, "%d\n", ap_dev->total_request_count); in ap_request_count_show()
698 spin_unlock_bh(&ap_dev->lock); in ap_request_count_show()
707 struct ap_device *ap_dev = to_ap_dev(dev); in ap_requestq_count_show() local
710 spin_lock_bh(&ap_dev->lock); in ap_requestq_count_show()
711 rc = snprintf(buf, PAGE_SIZE, "%d\n", ap_dev->requestq_count); in ap_requestq_count_show()
712 spin_unlock_bh(&ap_dev->lock); in ap_requestq_count_show()
721 struct ap_device *ap_dev = to_ap_dev(dev); in ap_pendingq_count_show() local
724 spin_lock_bh(&ap_dev->lock); in ap_pendingq_count_show()
725 rc = snprintf(buf, PAGE_SIZE, "%d\n", ap_dev->pendingq_count); in ap_pendingq_count_show()
726 spin_unlock_bh(&ap_dev->lock); in ap_pendingq_count_show()
743 struct ap_device *ap_dev = to_ap_dev(dev); in ap_functions_show() local
744 return snprintf(buf, PAGE_SIZE, "0x%08X\n", ap_dev->functions); in ap_functions_show()
773 struct ap_device *ap_dev = to_ap_dev(dev); in ap_bus_match() local
783 (id->dev_type != ap_dev->device_type)) in ap_bus_match()
800 struct ap_device *ap_dev = to_ap_dev(dev); in ap_uevent() local
803 if (!ap_dev) in ap_uevent()
807 retval = add_uevent_var(env, "DEV_TYPE=%04X", ap_dev->device_type); in ap_uevent()
812 retval = add_uevent_var(env, "MODALIAS=ap:t%02X", ap_dev->device_type); in ap_uevent()
819 struct ap_device *ap_dev = to_ap_dev(dev); in ap_bus_suspend() local
839 spin_lock_bh(&ap_dev->lock); in ap_bus_suspend()
840 __ap_poll_device(ap_dev, &flags); in ap_bus_suspend()
841 spin_unlock_bh(&ap_dev->lock); in ap_bus_suspend()
844 spin_lock_bh(&ap_dev->lock); in ap_bus_suspend()
845 ap_dev->unregistered = 1; in ap_bus_suspend()
846 spin_unlock_bh(&ap_dev->lock); in ap_bus_suspend()
853 struct ap_device *ap_dev = to_ap_dev(dev); in ap_bus_resume() local
893 if (AP_QID_QUEUE(ap_dev->qid) != ap_domain_index) { in ap_bus_resume()
894 spin_lock_bh(&ap_dev->lock); in ap_bus_resume()
895 ap_dev->qid = AP_MKQID(AP_QID_DEVICE(ap_dev->qid), in ap_bus_resume()
897 spin_unlock_bh(&ap_dev->lock); in ap_bus_resume()
914 struct ap_device *ap_dev = to_ap_dev(dev); in ap_device_probe() local
918 ap_dev->drv = ap_drv; in ap_device_probe()
921 list_add(&ap_dev->list, &ap_device_list); in ap_device_probe()
924 rc = ap_drv->probe ? ap_drv->probe(ap_dev) : -ENODEV; in ap_device_probe()
927 list_del_init(&ap_dev->list); in ap_device_probe()
939 static void __ap_flush_queue(struct ap_device *ap_dev) in __ap_flush_queue() argument
943 list_for_each_entry_safe(ap_msg, next, &ap_dev->pendingq, list) { in __ap_flush_queue()
945 ap_dev->pendingq_count--; in __ap_flush_queue()
946 ap_msg->receive(ap_dev, ap_msg, ERR_PTR(-ENODEV)); in __ap_flush_queue()
948 list_for_each_entry_safe(ap_msg, next, &ap_dev->requestq, list) { in __ap_flush_queue()
950 ap_dev->requestq_count--; in __ap_flush_queue()
951 ap_msg->receive(ap_dev, ap_msg, ERR_PTR(-ENODEV)); in __ap_flush_queue()
955 void ap_flush_queue(struct ap_device *ap_dev) in ap_flush_queue() argument
957 spin_lock_bh(&ap_dev->lock); in ap_flush_queue()
958 __ap_flush_queue(ap_dev); in ap_flush_queue()
959 spin_unlock_bh(&ap_dev->lock); in ap_flush_queue()
965 struct ap_device *ap_dev = to_ap_dev(dev); in ap_device_remove() local
966 struct ap_driver *ap_drv = ap_dev->drv; in ap_device_remove()
968 ap_flush_queue(ap_dev); in ap_device_remove()
969 del_timer_sync(&ap_dev->timeout); in ap_device_remove()
971 list_del_init(&ap_dev->list); in ap_device_remove()
974 ap_drv->remove(ap_dev); in ap_device_remove()
975 spin_lock_bh(&ap_dev->lock); in ap_device_remove()
976 atomic_sub(ap_dev->queue_count, &ap_poll_requests); in ap_device_remove()
977 spin_unlock_bh(&ap_dev->lock); in ap_device_remove()
1293 static int ap_probe_device_type(struct ap_device *ap_dev) in ap_probe_device_type() argument
1353 status = __ap_send(ap_dev->qid, 0x0102030405060708ULL, in ap_probe_device_type()
1363 status = __ap_recv(ap_dev->qid, &psmid, reply, 4096); in ap_probe_device_type()
1371 ap_dev->device_type = AP_DEVICE_TYPE_PCICC; in ap_probe_device_type()
1373 ap_dev->device_type = AP_DEVICE_TYPE_PCICA; in ap_probe_device_type()
1404 struct ap_device *ap_dev = to_ap_dev(dev); in ap_device_release() local
1406 kfree(ap_dev); in ap_device_release()
1411 struct ap_device *ap_dev; in ap_scan_bus() local
1438 ap_dev = to_ap_dev(dev); in ap_scan_bus()
1439 spin_lock_bh(&ap_dev->lock); in ap_scan_bus()
1440 if (rc || ap_dev->unregistered) { in ap_scan_bus()
1441 spin_unlock_bh(&ap_dev->lock); in ap_scan_bus()
1442 if (ap_dev->unregistered) in ap_scan_bus()
1448 spin_unlock_bh(&ap_dev->lock); in ap_scan_bus()
1457 ap_dev = kzalloc(sizeof(*ap_dev), GFP_KERNEL); in ap_scan_bus()
1458 if (!ap_dev) in ap_scan_bus()
1460 ap_dev->qid = qid; in ap_scan_bus()
1461 ap_dev->queue_depth = queue_depth; in ap_scan_bus()
1462 ap_dev->unregistered = 1; in ap_scan_bus()
1463 spin_lock_init(&ap_dev->lock); in ap_scan_bus()
1464 INIT_LIST_HEAD(&ap_dev->pendingq); in ap_scan_bus()
1465 INIT_LIST_HEAD(&ap_dev->requestq); in ap_scan_bus()
1466 INIT_LIST_HEAD(&ap_dev->list); in ap_scan_bus()
1467 setup_timer(&ap_dev->timeout, ap_request_timeout, in ap_scan_bus()
1468 (unsigned long) ap_dev); in ap_scan_bus()
1472 if (ap_probe_device_type(ap_dev)) { in ap_scan_bus()
1473 kfree(ap_dev); in ap_scan_bus()
1478 ap_dev->device_type = device_type; in ap_scan_bus()
1480 ap_dev->raw_hwtype = device_type; in ap_scan_bus()
1484 ap_dev->functions = device_functions; in ap_scan_bus()
1486 ap_dev->functions = 0u; in ap_scan_bus()
1488 ap_dev->device.bus = &ap_bus_type; in ap_scan_bus()
1489 ap_dev->device.parent = ap_root_device; in ap_scan_bus()
1490 if (dev_set_name(&ap_dev->device, "card%02x", in ap_scan_bus()
1491 AP_QID_DEVICE(ap_dev->qid))) { in ap_scan_bus()
1492 kfree(ap_dev); in ap_scan_bus()
1495 ap_dev->device.release = ap_device_release; in ap_scan_bus()
1496 rc = device_register(&ap_dev->device); in ap_scan_bus()
1498 put_device(&ap_dev->device); in ap_scan_bus()
1502 rc = sysfs_create_group(&ap_dev->device.kobj, in ap_scan_bus()
1505 spin_lock_bh(&ap_dev->lock); in ap_scan_bus()
1506 ap_dev->unregistered = 0; in ap_scan_bus()
1507 spin_unlock_bh(&ap_dev->lock); in ap_scan_bus()
1510 device_unregister(&ap_dev->device); in ap_scan_bus()
1560 static int ap_poll_read(struct ap_device *ap_dev, unsigned long *flags) in ap_poll_read() argument
1565 if (ap_dev->queue_count <= 0) in ap_poll_read()
1567 status = __ap_recv(ap_dev->qid, &ap_dev->reply->psmid, in ap_poll_read()
1568 ap_dev->reply->message, ap_dev->reply->length); in ap_poll_read()
1572 ap_decrease_queue_count(ap_dev); in ap_poll_read()
1573 list_for_each_entry(ap_msg, &ap_dev->pendingq, list) { in ap_poll_read()
1574 if (ap_msg->psmid != ap_dev->reply->psmid) in ap_poll_read()
1577 ap_dev->pendingq_count--; in ap_poll_read()
1578 ap_msg->receive(ap_dev, ap_msg, ap_dev->reply); in ap_poll_read()
1581 if (ap_dev->queue_count > 0) in ap_poll_read()
1587 atomic_sub(ap_dev->queue_count, &ap_poll_requests); in ap_poll_read()
1588 ap_dev->queue_count = 0; in ap_poll_read()
1589 list_splice_init(&ap_dev->pendingq, &ap_dev->requestq); in ap_poll_read()
1590 ap_dev->requestq_count += ap_dev->pendingq_count; in ap_poll_read()
1591 ap_dev->pendingq_count = 0; in ap_poll_read()
1609 static int ap_poll_write(struct ap_device *ap_dev, unsigned long *flags) in ap_poll_write() argument
1614 if (ap_dev->requestq_count <= 0 || in ap_poll_write()
1615 ap_dev->queue_count >= ap_dev->queue_depth) in ap_poll_write()
1618 ap_msg = list_entry(ap_dev->requestq.next, struct ap_message, list); in ap_poll_write()
1619 status = __ap_send(ap_dev->qid, ap_msg->psmid, in ap_poll_write()
1624 ap_increase_queue_count(ap_dev); in ap_poll_write()
1625 list_move_tail(&ap_msg->list, &ap_dev->pendingq); in ap_poll_write()
1626 ap_dev->requestq_count--; in ap_poll_write()
1627 ap_dev->pendingq_count++; in ap_poll_write()
1628 if (ap_dev->queue_count < ap_dev->queue_depth && in ap_poll_write()
1629 ap_dev->requestq_count > 0) in ap_poll_write()
1657 static inline int ap_poll_queue(struct ap_device *ap_dev, unsigned long *flags) in ap_poll_queue() argument
1661 rc = ap_poll_read(ap_dev, flags); in ap_poll_queue()
1664 return ap_poll_write(ap_dev, flags); in ap_poll_queue()
1674 static int __ap_queue_message(struct ap_device *ap_dev, struct ap_message *ap_msg) in __ap_queue_message() argument
1678 if (list_empty(&ap_dev->requestq) && in __ap_queue_message()
1679 ap_dev->queue_count < ap_dev->queue_depth) { in __ap_queue_message()
1680 status = __ap_send(ap_dev->qid, ap_msg->psmid, in __ap_queue_message()
1685 list_add_tail(&ap_msg->list, &ap_dev->pendingq); in __ap_queue_message()
1687 ap_dev->pendingq_count++; in __ap_queue_message()
1688 ap_increase_queue_count(ap_dev); in __ap_queue_message()
1689 ap_dev->total_request_count++; in __ap_queue_message()
1693 list_add_tail(&ap_msg->list, &ap_dev->requestq); in __ap_queue_message()
1694 ap_dev->requestq_count++; in __ap_queue_message()
1695 ap_dev->total_request_count++; in __ap_queue_message()
1699 ap_msg->receive(ap_dev, ap_msg, ERR_PTR(-EINVAL)); in __ap_queue_message()
1702 ap_msg->receive(ap_dev, ap_msg, ERR_PTR(-ENODEV)); in __ap_queue_message()
1706 list_add_tail(&ap_msg->list, &ap_dev->requestq); in __ap_queue_message()
1707 ap_dev->requestq_count++; in __ap_queue_message()
1708 ap_dev->total_request_count++; in __ap_queue_message()
1715 void ap_queue_message(struct ap_device *ap_dev, struct ap_message *ap_msg) in ap_queue_message() argument
1724 spin_lock_bh(&ap_dev->lock); in ap_queue_message()
1725 if (!ap_dev->unregistered) { in ap_queue_message()
1727 rc = ap_poll_queue(ap_dev, &flags); in ap_queue_message()
1729 rc = __ap_queue_message(ap_dev, ap_msg); in ap_queue_message()
1733 ap_dev->unregistered = 1; in ap_queue_message()
1735 ap_msg->receive(ap_dev, ap_msg, ERR_PTR(-ENODEV)); in ap_queue_message()
1738 spin_unlock_bh(&ap_dev->lock); in ap_queue_message()
1740 device_unregister(&ap_dev->device); in ap_queue_message()
1754 void ap_cancel_message(struct ap_device *ap_dev, struct ap_message *ap_msg) in ap_cancel_message() argument
1758 spin_lock_bh(&ap_dev->lock); in ap_cancel_message()
1760 list_for_each_entry(tmp, &ap_dev->pendingq, list) in ap_cancel_message()
1762 ap_dev->pendingq_count--; in ap_cancel_message()
1765 ap_dev->requestq_count--; in ap_cancel_message()
1769 spin_unlock_bh(&ap_dev->lock); in ap_cancel_message()
1792 static void ap_reset(struct ap_device *ap_dev) in ap_reset() argument
1796 ap_dev->reset = AP_RESET_IGNORE; in ap_reset()
1797 atomic_sub(ap_dev->queue_count, &ap_poll_requests); in ap_reset()
1798 ap_dev->queue_count = 0; in ap_reset()
1799 list_splice_init(&ap_dev->pendingq, &ap_dev->requestq); in ap_reset()
1800 ap_dev->requestq_count += ap_dev->pendingq_count; in ap_reset()
1801 ap_dev->pendingq_count = 0; in ap_reset()
1802 rc = ap_init_queue(ap_dev->qid); in ap_reset()
1804 ap_dev->unregistered = 1; in ap_reset()
1809 static int __ap_poll_device(struct ap_device *ap_dev, unsigned long *flags) in __ap_poll_device() argument
1811 if (!ap_dev->unregistered) { in __ap_poll_device()
1812 if (ap_poll_queue(ap_dev, flags)) in __ap_poll_device()
1813 ap_dev->unregistered = 1; in __ap_poll_device()
1814 if (ap_dev->reset == AP_RESET_DO) in __ap_poll_device()
1815 ap_reset(ap_dev); in __ap_poll_device()
1831 struct ap_device *ap_dev; in ap_poll_all() local
1842 list_for_each_entry(ap_dev, &ap_device_list, list) { in ap_poll_all()
1843 spin_lock(&ap_dev->lock); in ap_poll_all()
1844 __ap_poll_device(ap_dev, &flags); in ap_poll_all()
1845 spin_unlock(&ap_dev->lock); in ap_poll_all()
1868 struct ap_device *ap_dev; in ap_poll_thread() local
1890 list_for_each_entry(ap_dev, &ap_device_list, list) { in ap_poll_thread()
1891 spin_lock(&ap_dev->lock); in ap_poll_thread()
1892 __ap_poll_device(ap_dev, &flags); in ap_poll_thread()
1893 spin_unlock(&ap_dev->lock); in ap_poll_thread()
1939 struct ap_device *ap_dev = (struct ap_device *) data; in ap_request_timeout() local
1941 if (ap_dev->reset == AP_RESET_ARMED) { in ap_request_timeout()
1942 ap_dev->reset = AP_RESET_DO; in ap_request_timeout()