Lines Matching refs:ap_dev
60 static int __ap_poll_device(struct ap_device *ap_dev, unsigned long *flags);
64 static void ap_reset(struct ap_device *ap_dev);
588 static void ap_increase_queue_count(struct ap_device *ap_dev) in ap_increase_queue_count() argument
590 int timeout = ap_dev->drv->request_timeout; in ap_increase_queue_count()
592 ap_dev->queue_count++; in ap_increase_queue_count()
593 if (ap_dev->queue_count == 1) { in ap_increase_queue_count()
594 mod_timer(&ap_dev->timeout, jiffies + timeout); in ap_increase_queue_count()
595 ap_dev->reset = AP_RESET_ARMED; in ap_increase_queue_count()
606 static void ap_decrease_queue_count(struct ap_device *ap_dev) in ap_decrease_queue_count() argument
608 int timeout = ap_dev->drv->request_timeout; in ap_decrease_queue_count()
610 ap_dev->queue_count--; in ap_decrease_queue_count()
611 if (ap_dev->queue_count > 0) in ap_decrease_queue_count()
612 mod_timer(&ap_dev->timeout, jiffies + timeout); in ap_decrease_queue_count()
619 ap_dev->reset = AP_RESET_IGNORE; in ap_decrease_queue_count()
628 struct ap_device *ap_dev = to_ap_dev(dev); in ap_hwtype_show() local
629 return snprintf(buf, PAGE_SIZE, "%d\n", ap_dev->device_type); in ap_hwtype_show()
636 struct ap_device *ap_dev = to_ap_dev(dev); in ap_depth_show() local
637 return snprintf(buf, PAGE_SIZE, "%d\n", ap_dev->queue_depth); in ap_depth_show()
645 struct ap_device *ap_dev = to_ap_dev(dev); in ap_request_count_show() local
648 spin_lock_bh(&ap_dev->lock); in ap_request_count_show()
649 rc = snprintf(buf, PAGE_SIZE, "%d\n", ap_dev->total_request_count); in ap_request_count_show()
650 spin_unlock_bh(&ap_dev->lock); in ap_request_count_show()
684 struct ap_device *ap_dev = to_ap_dev(dev); in ap_bus_match() local
694 (id->dev_type != ap_dev->device_type)) in ap_bus_match()
711 struct ap_device *ap_dev = to_ap_dev(dev); in ap_uevent() local
714 if (!ap_dev) in ap_uevent()
718 retval = add_uevent_var(env, "DEV_TYPE=%04X", ap_dev->device_type); in ap_uevent()
723 retval = add_uevent_var(env, "MODALIAS=ap:t%02X", ap_dev->device_type); in ap_uevent()
730 struct ap_device *ap_dev = to_ap_dev(dev); in ap_bus_suspend() local
750 spin_lock_bh(&ap_dev->lock); in ap_bus_suspend()
751 __ap_poll_device(ap_dev, &flags); in ap_bus_suspend()
752 spin_unlock_bh(&ap_dev->lock); in ap_bus_suspend()
755 spin_lock_bh(&ap_dev->lock); in ap_bus_suspend()
756 ap_dev->unregistered = 1; in ap_bus_suspend()
757 spin_unlock_bh(&ap_dev->lock); in ap_bus_suspend()
765 struct ap_device *ap_dev = to_ap_dev(dev); in ap_bus_resume() local
791 if (AP_QID_QUEUE(ap_dev->qid) != ap_domain_index) { in ap_bus_resume()
792 spin_lock_bh(&ap_dev->lock); in ap_bus_resume()
793 ap_dev->qid = AP_MKQID(AP_QID_DEVICE(ap_dev->qid), in ap_bus_resume()
795 spin_unlock_bh(&ap_dev->lock); in ap_bus_resume()
812 struct ap_device *ap_dev = to_ap_dev(dev); in ap_device_probe() local
816 ap_dev->drv = ap_drv; in ap_device_probe()
817 rc = ap_drv->probe ? ap_drv->probe(ap_dev) : -ENODEV; in ap_device_probe()
820 list_add(&ap_dev->list, &ap_device_list); in ap_device_probe()
832 static void __ap_flush_queue(struct ap_device *ap_dev) in __ap_flush_queue() argument
836 list_for_each_entry_safe(ap_msg, next, &ap_dev->pendingq, list) { in __ap_flush_queue()
838 ap_dev->pendingq_count--; in __ap_flush_queue()
839 ap_dev->drv->receive(ap_dev, ap_msg, ERR_PTR(-ENODEV)); in __ap_flush_queue()
841 list_for_each_entry_safe(ap_msg, next, &ap_dev->requestq, list) { in __ap_flush_queue()
843 ap_dev->requestq_count--; in __ap_flush_queue()
844 ap_dev->drv->receive(ap_dev, ap_msg, ERR_PTR(-ENODEV)); in __ap_flush_queue()
848 void ap_flush_queue(struct ap_device *ap_dev) in ap_flush_queue() argument
850 spin_lock_bh(&ap_dev->lock); in ap_flush_queue()
851 __ap_flush_queue(ap_dev); in ap_flush_queue()
852 spin_unlock_bh(&ap_dev->lock); in ap_flush_queue()
858 struct ap_device *ap_dev = to_ap_dev(dev); in ap_device_remove() local
859 struct ap_driver *ap_drv = ap_dev->drv; in ap_device_remove()
861 ap_flush_queue(ap_dev); in ap_device_remove()
862 del_timer_sync(&ap_dev->timeout); in ap_device_remove()
864 list_del_init(&ap_dev->list); in ap_device_remove()
867 ap_drv->remove(ap_dev); in ap_device_remove()
868 spin_lock_bh(&ap_dev->lock); in ap_device_remove()
869 atomic_sub(ap_dev->queue_count, &ap_poll_requests); in ap_device_remove()
870 spin_unlock_bh(&ap_dev->lock); in ap_device_remove()
1043 static int ap_probe_device_type(struct ap_device *ap_dev) in ap_probe_device_type() argument
1103 status = __ap_send(ap_dev->qid, 0x0102030405060708ULL, in ap_probe_device_type()
1113 status = __ap_recv(ap_dev->qid, &psmid, reply, 4096); in ap_probe_device_type()
1121 ap_dev->device_type = AP_DEVICE_TYPE_PCICC; in ap_probe_device_type()
1123 ap_dev->device_type = AP_DEVICE_TYPE_PCICA; in ap_probe_device_type()
1154 struct ap_device *ap_dev = to_ap_dev(dev); in ap_device_release() local
1156 kfree(ap_dev); in ap_device_release()
1161 struct ap_device *ap_dev; in ap_scan_bus() local
1183 ap_dev = to_ap_dev(dev); in ap_scan_bus()
1184 spin_lock_bh(&ap_dev->lock); in ap_scan_bus()
1185 if (rc || ap_dev->unregistered) { in ap_scan_bus()
1186 spin_unlock_bh(&ap_dev->lock); in ap_scan_bus()
1187 if (ap_dev->unregistered) in ap_scan_bus()
1193 spin_unlock_bh(&ap_dev->lock); in ap_scan_bus()
1202 ap_dev = kzalloc(sizeof(*ap_dev), GFP_KERNEL); in ap_scan_bus()
1203 if (!ap_dev) in ap_scan_bus()
1205 ap_dev->qid = qid; in ap_scan_bus()
1206 ap_dev->queue_depth = queue_depth; in ap_scan_bus()
1207 ap_dev->unregistered = 1; in ap_scan_bus()
1208 spin_lock_init(&ap_dev->lock); in ap_scan_bus()
1209 INIT_LIST_HEAD(&ap_dev->pendingq); in ap_scan_bus()
1210 INIT_LIST_HEAD(&ap_dev->requestq); in ap_scan_bus()
1211 INIT_LIST_HEAD(&ap_dev->list); in ap_scan_bus()
1212 setup_timer(&ap_dev->timeout, ap_request_timeout, in ap_scan_bus()
1213 (unsigned long) ap_dev); in ap_scan_bus()
1216 if (ap_probe_device_type(ap_dev)) { in ap_scan_bus()
1217 kfree(ap_dev); in ap_scan_bus()
1223 kfree(ap_dev); in ap_scan_bus()
1227 ap_dev->device_type = AP_DEVICE_TYPE_CEX3C; in ap_scan_bus()
1229 ap_dev->device_type = AP_DEVICE_TYPE_CEX3A; in ap_scan_bus()
1231 kfree(ap_dev); in ap_scan_bus()
1236 ap_dev->device_type = device_type; in ap_scan_bus()
1239 ap_dev->device.bus = &ap_bus_type; in ap_scan_bus()
1240 ap_dev->device.parent = ap_root_device; in ap_scan_bus()
1241 if (dev_set_name(&ap_dev->device, "card%02x", in ap_scan_bus()
1242 AP_QID_DEVICE(ap_dev->qid))) { in ap_scan_bus()
1243 kfree(ap_dev); in ap_scan_bus()
1246 ap_dev->device.release = ap_device_release; in ap_scan_bus()
1247 rc = device_register(&ap_dev->device); in ap_scan_bus()
1249 put_device(&ap_dev->device); in ap_scan_bus()
1253 rc = sysfs_create_group(&ap_dev->device.kobj, in ap_scan_bus()
1256 spin_lock_bh(&ap_dev->lock); in ap_scan_bus()
1257 ap_dev->unregistered = 0; in ap_scan_bus()
1258 spin_unlock_bh(&ap_dev->lock); in ap_scan_bus()
1261 device_unregister(&ap_dev->device); in ap_scan_bus()
1314 static int ap_poll_read(struct ap_device *ap_dev, unsigned long *flags) in ap_poll_read() argument
1319 if (ap_dev->queue_count <= 0) in ap_poll_read()
1321 status = __ap_recv(ap_dev->qid, &ap_dev->reply->psmid, in ap_poll_read()
1322 ap_dev->reply->message, ap_dev->reply->length); in ap_poll_read()
1326 ap_decrease_queue_count(ap_dev); in ap_poll_read()
1327 list_for_each_entry(ap_msg, &ap_dev->pendingq, list) { in ap_poll_read()
1328 if (ap_msg->psmid != ap_dev->reply->psmid) in ap_poll_read()
1331 ap_dev->pendingq_count--; in ap_poll_read()
1332 ap_dev->drv->receive(ap_dev, ap_msg, ap_dev->reply); in ap_poll_read()
1335 if (ap_dev->queue_count > 0) in ap_poll_read()
1341 atomic_sub(ap_dev->queue_count, &ap_poll_requests); in ap_poll_read()
1342 ap_dev->queue_count = 0; in ap_poll_read()
1343 list_splice_init(&ap_dev->pendingq, &ap_dev->requestq); in ap_poll_read()
1344 ap_dev->requestq_count += ap_dev->pendingq_count; in ap_poll_read()
1345 ap_dev->pendingq_count = 0; in ap_poll_read()
1363 static int ap_poll_write(struct ap_device *ap_dev, unsigned long *flags) in ap_poll_write() argument
1368 if (ap_dev->requestq_count <= 0 || in ap_poll_write()
1369 ap_dev->queue_count >= ap_dev->queue_depth) in ap_poll_write()
1372 ap_msg = list_entry(ap_dev->requestq.next, struct ap_message, list); in ap_poll_write()
1373 status = __ap_send(ap_dev->qid, ap_msg->psmid, in ap_poll_write()
1378 ap_increase_queue_count(ap_dev); in ap_poll_write()
1379 list_move_tail(&ap_msg->list, &ap_dev->pendingq); in ap_poll_write()
1380 ap_dev->requestq_count--; in ap_poll_write()
1381 ap_dev->pendingq_count++; in ap_poll_write()
1382 if (ap_dev->queue_count < ap_dev->queue_depth && in ap_poll_write()
1383 ap_dev->requestq_count > 0) in ap_poll_write()
1411 static inline int ap_poll_queue(struct ap_device *ap_dev, unsigned long *flags) in ap_poll_queue() argument
1415 rc = ap_poll_read(ap_dev, flags); in ap_poll_queue()
1418 return ap_poll_write(ap_dev, flags); in ap_poll_queue()
1428 static int __ap_queue_message(struct ap_device *ap_dev, struct ap_message *ap_msg) in __ap_queue_message() argument
1432 if (list_empty(&ap_dev->requestq) && in __ap_queue_message()
1433 ap_dev->queue_count < ap_dev->queue_depth) { in __ap_queue_message()
1434 status = __ap_send(ap_dev->qid, ap_msg->psmid, in __ap_queue_message()
1439 list_add_tail(&ap_msg->list, &ap_dev->pendingq); in __ap_queue_message()
1441 ap_dev->pendingq_count++; in __ap_queue_message()
1442 ap_increase_queue_count(ap_dev); in __ap_queue_message()
1443 ap_dev->total_request_count++; in __ap_queue_message()
1447 list_add_tail(&ap_msg->list, &ap_dev->requestq); in __ap_queue_message()
1448 ap_dev->requestq_count++; in __ap_queue_message()
1449 ap_dev->total_request_count++; in __ap_queue_message()
1453 ap_dev->drv->receive(ap_dev, ap_msg, ERR_PTR(-EINVAL)); in __ap_queue_message()
1456 ap_dev->drv->receive(ap_dev, ap_msg, ERR_PTR(-ENODEV)); in __ap_queue_message()
1460 list_add_tail(&ap_msg->list, &ap_dev->requestq); in __ap_queue_message()
1461 ap_dev->requestq_count++; in __ap_queue_message()
1462 ap_dev->total_request_count++; in __ap_queue_message()
1469 void ap_queue_message(struct ap_device *ap_dev, struct ap_message *ap_msg) in ap_queue_message() argument
1474 spin_lock_bh(&ap_dev->lock); in ap_queue_message()
1475 if (!ap_dev->unregistered) { in ap_queue_message()
1477 rc = ap_poll_queue(ap_dev, &flags); in ap_queue_message()
1479 rc = __ap_queue_message(ap_dev, ap_msg); in ap_queue_message()
1483 ap_dev->unregistered = 1; in ap_queue_message()
1485 ap_dev->drv->receive(ap_dev, ap_msg, ERR_PTR(-ENODEV)); in ap_queue_message()
1488 spin_unlock_bh(&ap_dev->lock); in ap_queue_message()
1490 device_unregister(&ap_dev->device); in ap_queue_message()
1504 void ap_cancel_message(struct ap_device *ap_dev, struct ap_message *ap_msg) in ap_cancel_message() argument
1508 spin_lock_bh(&ap_dev->lock); in ap_cancel_message()
1510 list_for_each_entry(tmp, &ap_dev->pendingq, list) in ap_cancel_message()
1512 ap_dev->pendingq_count--; in ap_cancel_message()
1515 ap_dev->requestq_count--; in ap_cancel_message()
1519 spin_unlock_bh(&ap_dev->lock); in ap_cancel_message()
1542 static void ap_reset(struct ap_device *ap_dev) in ap_reset() argument
1546 ap_dev->reset = AP_RESET_IGNORE; in ap_reset()
1547 atomic_sub(ap_dev->queue_count, &ap_poll_requests); in ap_reset()
1548 ap_dev->queue_count = 0; in ap_reset()
1549 list_splice_init(&ap_dev->pendingq, &ap_dev->requestq); in ap_reset()
1550 ap_dev->requestq_count += ap_dev->pendingq_count; in ap_reset()
1551 ap_dev->pendingq_count = 0; in ap_reset()
1552 rc = ap_init_queue(ap_dev->qid); in ap_reset()
1554 ap_dev->unregistered = 1; in ap_reset()
1559 static int __ap_poll_device(struct ap_device *ap_dev, unsigned long *flags) in __ap_poll_device() argument
1561 if (!ap_dev->unregistered) { in __ap_poll_device()
1562 if (ap_poll_queue(ap_dev, flags)) in __ap_poll_device()
1563 ap_dev->unregistered = 1; in __ap_poll_device()
1564 if (ap_dev->reset == AP_RESET_DO) in __ap_poll_device()
1565 ap_reset(ap_dev); in __ap_poll_device()
1581 struct ap_device *ap_dev; in ap_poll_all() local
1592 list_for_each_entry(ap_dev, &ap_device_list, list) { in ap_poll_all()
1593 spin_lock(&ap_dev->lock); in ap_poll_all()
1594 __ap_poll_device(ap_dev, &flags); in ap_poll_all()
1595 spin_unlock(&ap_dev->lock); in ap_poll_all()
1618 struct ap_device *ap_dev; in ap_poll_thread() local
1640 list_for_each_entry(ap_dev, &ap_device_list, list) { in ap_poll_thread()
1641 spin_lock(&ap_dev->lock); in ap_poll_thread()
1642 __ap_poll_device(ap_dev, &flags); in ap_poll_thread()
1643 spin_unlock(&ap_dev->lock); in ap_poll_thread()
1689 struct ap_device *ap_dev = (struct ap_device *) data; in ap_request_timeout() local
1691 if (ap_dev->reset == AP_RESET_ARMED) { in ap_request_timeout()
1692 ap_dev->reset = AP_RESET_DO; in ap_request_timeout()