Lines Matching refs:aq

19 static void __ap_flush_queue(struct ap_queue *aq);
30 static int ap_queue_enable_irq(struct ap_queue *aq, void *ind) in ap_queue_enable_irq() argument
37 status = ap_aqic(aq->qid, qirqctrl, virt_to_phys(ind)); in ap_queue_enable_irq()
47 AP_QID_CARD(aq->qid), in ap_queue_enable_irq()
48 AP_QID_QUEUE(aq->qid)); in ap_queue_enable_irq()
122 static enum ap_sm_wait ap_sm_nop(struct ap_queue *aq) in ap_sm_nop() argument
134 static struct ap_queue_status ap_sm_recv(struct ap_queue *aq) in ap_sm_recv() argument
151 status = ap_dqap(aq->qid, &aq->reply->psmid, in ap_sm_recv()
152 aq->reply->msg, aq->reply->bufsize, in ap_sm_recv()
159 aq->queue_count = max_t(int, 0, aq->queue_count - 1); in ap_sm_recv()
160 if (!status.queue_empty && !aq->queue_count) in ap_sm_recv()
161 aq->queue_count++; in ap_sm_recv()
162 if (aq->queue_count > 0) in ap_sm_recv()
163 mod_timer(&aq->timeout, in ap_sm_recv()
164 jiffies + aq->request_timeout); in ap_sm_recv()
165 list_for_each_entry(ap_msg, &aq->pendingq, list) { in ap_sm_recv()
166 if (ap_msg->psmid != aq->reply->psmid) in ap_sm_recv()
169 aq->pendingq_count--; in ap_sm_recv()
172 ap_msg->receive(aq, ap_msg, NULL); in ap_sm_recv()
174 ap_msg->receive(aq, ap_msg, aq->reply); in ap_sm_recv()
181 __func__, aq->reply->psmid, in ap_sm_recv()
182 AP_QID_CARD(aq->qid), AP_QID_QUEUE(aq->qid)); in ap_sm_recv()
186 if (!status.queue_empty || aq->queue_count <= 0) in ap_sm_recv()
189 aq->queue_count = 0; in ap_sm_recv()
190 list_splice_init(&aq->pendingq, &aq->requestq); in ap_sm_recv()
191 aq->requestq_count += aq->pendingq_count; in ap_sm_recv()
192 aq->pendingq_count = 0; in ap_sm_recv()
206 static enum ap_sm_wait ap_sm_read(struct ap_queue *aq) in ap_sm_read() argument
210 if (!aq->reply) in ap_sm_read()
212 status = ap_sm_recv(aq); in ap_sm_read()
215 if (aq->queue_count > 0) { in ap_sm_read()
216 aq->sm_state = AP_SM_STATE_WORKING; in ap_sm_read()
219 aq->sm_state = AP_SM_STATE_IDLE; in ap_sm_read()
222 if (aq->queue_count > 0) in ap_sm_read()
223 return aq->interrupt ? in ap_sm_read()
225 aq->sm_state = AP_SM_STATE_IDLE; in ap_sm_read()
228 aq->dev_state = AP_DEV_STATE_ERROR; in ap_sm_read()
229 aq->last_err_rc = status.response_code; in ap_sm_read()
232 AP_QID_CARD(aq->qid), AP_QID_QUEUE(aq->qid)); in ap_sm_read()
243 static enum ap_sm_wait ap_sm_write(struct ap_queue *aq) in ap_sm_write() argument
247 ap_qid_t qid = aq->qid; in ap_sm_write()
249 if (aq->requestq_count <= 0) in ap_sm_write()
253 ap_msg = list_entry(aq->requestq.next, struct ap_message, list); in ap_sm_write()
266 aq->queue_count = max_t(int, 1, aq->queue_count + 1); in ap_sm_write()
267 if (aq->queue_count == 1) in ap_sm_write()
268 mod_timer(&aq->timeout, jiffies + aq->request_timeout); in ap_sm_write()
269 list_move_tail(&ap_msg->list, &aq->pendingq); in ap_sm_write()
270 aq->requestq_count--; in ap_sm_write()
271 aq->pendingq_count++; in ap_sm_write()
272 if (aq->queue_count < aq->card->queue_depth) { in ap_sm_write()
273 aq->sm_state = AP_SM_STATE_WORKING; in ap_sm_write()
278 aq->sm_state = AP_SM_STATE_QUEUE_FULL; in ap_sm_write()
279 return aq->interrupt ? in ap_sm_write()
282 aq->sm_state = AP_SM_STATE_RESET_WAIT; in ap_sm_write()
290 aq->requestq_count--; in ap_sm_write()
292 ap_msg->receive(aq, ap_msg, NULL); in ap_sm_write()
295 aq->dev_state = AP_DEV_STATE_ERROR; in ap_sm_write()
296 aq->last_err_rc = status.response_code; in ap_sm_write()
299 AP_QID_CARD(aq->qid), AP_QID_QUEUE(aq->qid)); in ap_sm_write()
310 static enum ap_sm_wait ap_sm_read_write(struct ap_queue *aq) in ap_sm_read_write() argument
312 return min(ap_sm_read(aq), ap_sm_write(aq)); in ap_sm_read_write()
321 static enum ap_sm_wait ap_sm_reset(struct ap_queue *aq) in ap_sm_reset() argument
325 status = ap_rapq(aq->qid); in ap_sm_reset()
329 aq->sm_state = AP_SM_STATE_RESET_WAIT; in ap_sm_reset()
330 aq->interrupt = false; in ap_sm_reset()
333 aq->dev_state = AP_DEV_STATE_ERROR; in ap_sm_reset()
334 aq->last_err_rc = status.response_code; in ap_sm_reset()
337 AP_QID_CARD(aq->qid), AP_QID_QUEUE(aq->qid)); in ap_sm_reset()
348 static enum ap_sm_wait ap_sm_reset_wait(struct ap_queue *aq) in ap_sm_reset_wait() argument
353 if (aq->queue_count > 0 && aq->reply) in ap_sm_reset_wait()
355 status = ap_sm_recv(aq); in ap_sm_reset_wait()
358 status = ap_tapq(aq->qid, NULL); in ap_sm_reset_wait()
363 if (lsi_ptr && ap_queue_enable_irq(aq, lsi_ptr) == 0) in ap_sm_reset_wait()
364 aq->sm_state = AP_SM_STATE_SETIRQ_WAIT; in ap_sm_reset_wait()
366 aq->sm_state = (aq->queue_count > 0) ? in ap_sm_reset_wait()
376 aq->dev_state = AP_DEV_STATE_ERROR; in ap_sm_reset_wait()
377 aq->last_err_rc = status.response_code; in ap_sm_reset_wait()
380 AP_QID_CARD(aq->qid), AP_QID_QUEUE(aq->qid)); in ap_sm_reset_wait()
391 static enum ap_sm_wait ap_sm_setirq_wait(struct ap_queue *aq) in ap_sm_setirq_wait() argument
395 if (aq->queue_count > 0 && aq->reply) in ap_sm_setirq_wait()
397 status = ap_sm_recv(aq); in ap_sm_setirq_wait()
400 status = ap_tapq(aq->qid, NULL); in ap_sm_setirq_wait()
404 aq->interrupt = true; in ap_sm_setirq_wait()
405 aq->sm_state = (aq->queue_count > 0) ? in ap_sm_setirq_wait()
411 if (aq->queue_count > 0) in ap_sm_setirq_wait()
417 aq->dev_state = AP_DEV_STATE_ERROR; in ap_sm_setirq_wait()
418 aq->last_err_rc = status.response_code; in ap_sm_setirq_wait()
421 AP_QID_CARD(aq->qid), AP_QID_QUEUE(aq->qid)); in ap_sm_setirq_wait()
456 enum ap_sm_wait ap_sm_event(struct ap_queue *aq, enum ap_sm_event event) in ap_sm_event() argument
458 if (aq->config && !aq->chkstop && in ap_sm_event()
459 aq->dev_state > AP_DEV_STATE_UNINITIATED) in ap_sm_event()
460 return ap_jumptable[aq->sm_state][event](aq); in ap_sm_event()
465 enum ap_sm_wait ap_sm_event_loop(struct ap_queue *aq, enum ap_sm_event event) in ap_sm_event_loop() argument
469 while ((wait = ap_sm_event(aq, event)) == AP_SM_WAIT_AGAIN) in ap_sm_event_loop()
481 struct ap_queue *aq = to_ap_queue(dev); in request_count_show() local
485 spin_lock_bh(&aq->lock); in request_count_show()
486 if (aq->dev_state > AP_DEV_STATE_UNINITIATED) { in request_count_show()
487 req_cnt = aq->total_request_count; in request_count_show()
490 spin_unlock_bh(&aq->lock); in request_count_show()
502 struct ap_queue *aq = to_ap_queue(dev); in request_count_store() local
504 spin_lock_bh(&aq->lock); in request_count_store()
505 aq->total_request_count = 0; in request_count_store()
506 spin_unlock_bh(&aq->lock); in request_count_store()
516 struct ap_queue *aq = to_ap_queue(dev); in requestq_count_show() local
519 spin_lock_bh(&aq->lock); in requestq_count_show()
520 if (aq->dev_state > AP_DEV_STATE_UNINITIATED) in requestq_count_show()
521 reqq_cnt = aq->requestq_count; in requestq_count_show()
522 spin_unlock_bh(&aq->lock); in requestq_count_show()
531 struct ap_queue *aq = to_ap_queue(dev); in pendingq_count_show() local
534 spin_lock_bh(&aq->lock); in pendingq_count_show()
535 if (aq->dev_state > AP_DEV_STATE_UNINITIATED) in pendingq_count_show()
536 penq_cnt = aq->pendingq_count; in pendingq_count_show()
537 spin_unlock_bh(&aq->lock); in pendingq_count_show()
546 struct ap_queue *aq = to_ap_queue(dev); in reset_show() local
549 spin_lock_bh(&aq->lock); in reset_show()
550 switch (aq->sm_state) { in reset_show()
562 spin_unlock_bh(&aq->lock); in reset_show()
570 struct ap_queue *aq = to_ap_queue(dev); in reset_store() local
572 spin_lock_bh(&aq->lock); in reset_store()
573 __ap_flush_queue(aq); in reset_store()
574 aq->sm_state = AP_SM_STATE_RESET_START; in reset_store()
575 ap_wait(ap_sm_event(aq, AP_SM_EVENT_POLL)); in reset_store()
576 spin_unlock_bh(&aq->lock); in reset_store()
579 __func__, AP_QID_CARD(aq->qid), AP_QID_QUEUE(aq->qid)); in reset_store()
589 struct ap_queue *aq = to_ap_queue(dev); in interrupt_show() local
592 spin_lock_bh(&aq->lock); in interrupt_show()
593 if (aq->sm_state == AP_SM_STATE_SETIRQ_WAIT) in interrupt_show()
595 else if (aq->interrupt) in interrupt_show()
599 spin_unlock_bh(&aq->lock); in interrupt_show()
608 struct ap_queue *aq = to_ap_queue(dev); in config_show() local
611 spin_lock_bh(&aq->lock); in config_show()
612 rc = scnprintf(buf, PAGE_SIZE, "%d\n", aq->config ? 1 : 0); in config_show()
613 spin_unlock_bh(&aq->lock); in config_show()
622 struct ap_queue *aq = to_ap_queue(dev); in chkstop_show() local
625 spin_lock_bh(&aq->lock); in chkstop_show()
626 rc = scnprintf(buf, PAGE_SIZE, "%d\n", aq->chkstop ? 1 : 0); in chkstop_show()
627 spin_unlock_bh(&aq->lock); in chkstop_show()
637 struct ap_queue *aq = to_ap_queue(dev); in states_show() local
640 spin_lock_bh(&aq->lock); in states_show()
642 switch (aq->dev_state) { in states_show()
659 if (aq->dev_state) { in states_show()
660 switch (aq->sm_state) { in states_show()
690 spin_unlock_bh(&aq->lock); in states_show()
699 struct ap_queue *aq = to_ap_queue(dev); in last_err_rc_show() local
702 spin_lock_bh(&aq->lock); in last_err_rc_show()
703 rc = aq->last_err_rc; in last_err_rc_show()
704 spin_unlock_bh(&aq->lock); in last_err_rc_show()
771 struct ap_queue *aq = to_ap_queue(dev); in ap_queue_device_release() local
774 hash_del(&aq->hnode); in ap_queue_device_release()
777 kfree(aq); in ap_queue_device_release()
782 struct ap_queue *aq; in ap_queue_create() local
784 aq = kzalloc(sizeof(*aq), GFP_KERNEL); in ap_queue_create()
785 if (!aq) in ap_queue_create()
787 aq->ap_dev.device.release = ap_queue_device_release; in ap_queue_create()
788 aq->ap_dev.device.type = &ap_queue_type; in ap_queue_create()
789 aq->ap_dev.device_type = device_type; in ap_queue_create()
790 aq->qid = qid; in ap_queue_create()
791 aq->interrupt = false; in ap_queue_create()
792 spin_lock_init(&aq->lock); in ap_queue_create()
793 INIT_LIST_HEAD(&aq->pendingq); in ap_queue_create()
794 INIT_LIST_HEAD(&aq->requestq); in ap_queue_create()
795 timer_setup(&aq->timeout, ap_request_timeout, 0); in ap_queue_create()
797 return aq; in ap_queue_create()
800 void ap_queue_init_reply(struct ap_queue *aq, struct ap_message *reply) in ap_queue_init_reply() argument
802 aq->reply = reply; in ap_queue_init_reply()
804 spin_lock_bh(&aq->lock); in ap_queue_init_reply()
805 ap_wait(ap_sm_event(aq, AP_SM_EVENT_POLL)); in ap_queue_init_reply()
806 spin_unlock_bh(&aq->lock); in ap_queue_init_reply()
815 int ap_queue_message(struct ap_queue *aq, struct ap_message *ap_msg) in ap_queue_message() argument
822 spin_lock_bh(&aq->lock); in ap_queue_message()
825 if (aq->dev_state == AP_DEV_STATE_OPERATING) { in ap_queue_message()
826 list_add_tail(&ap_msg->list, &aq->requestq); in ap_queue_message()
827 aq->requestq_count++; in ap_queue_message()
828 aq->total_request_count++; in ap_queue_message()
829 atomic64_inc(&aq->card->total_request_count); in ap_queue_message()
835 ap_wait(ap_sm_event_loop(aq, AP_SM_EVENT_POLL)); in ap_queue_message()
837 spin_unlock_bh(&aq->lock); in ap_queue_message()
853 void ap_cancel_message(struct ap_queue *aq, struct ap_message *ap_msg) in ap_cancel_message() argument
857 spin_lock_bh(&aq->lock); in ap_cancel_message()
859 list_for_each_entry(tmp, &aq->pendingq, list) in ap_cancel_message()
861 aq->pendingq_count--; in ap_cancel_message()
864 aq->requestq_count--; in ap_cancel_message()
868 spin_unlock_bh(&aq->lock); in ap_cancel_message()
878 static void __ap_flush_queue(struct ap_queue *aq) in __ap_flush_queue() argument
882 list_for_each_entry_safe(ap_msg, next, &aq->pendingq, list) { in __ap_flush_queue()
884 aq->pendingq_count--; in __ap_flush_queue()
886 ap_msg->receive(aq, ap_msg, NULL); in __ap_flush_queue()
888 list_for_each_entry_safe(ap_msg, next, &aq->requestq, list) { in __ap_flush_queue()
890 aq->requestq_count--; in __ap_flush_queue()
892 ap_msg->receive(aq, ap_msg, NULL); in __ap_flush_queue()
894 aq->queue_count = 0; in __ap_flush_queue()
897 void ap_flush_queue(struct ap_queue *aq) in ap_flush_queue() argument
899 spin_lock_bh(&aq->lock); in ap_flush_queue()
900 __ap_flush_queue(aq); in ap_flush_queue()
901 spin_unlock_bh(&aq->lock); in ap_flush_queue()
905 void ap_queue_prepare_remove(struct ap_queue *aq) in ap_queue_prepare_remove() argument
907 spin_lock_bh(&aq->lock); in ap_queue_prepare_remove()
909 __ap_flush_queue(aq); in ap_queue_prepare_remove()
911 aq->dev_state = AP_DEV_STATE_SHUTDOWN; in ap_queue_prepare_remove()
912 spin_unlock_bh(&aq->lock); in ap_queue_prepare_remove()
913 del_timer_sync(&aq->timeout); in ap_queue_prepare_remove()
916 void ap_queue_remove(struct ap_queue *aq) in ap_queue_remove() argument
924 spin_lock_bh(&aq->lock); in ap_queue_remove()
925 ap_zapq(aq->qid); in ap_queue_remove()
926 aq->dev_state = AP_DEV_STATE_UNINITIATED; in ap_queue_remove()
927 spin_unlock_bh(&aq->lock); in ap_queue_remove()
930 void ap_queue_init_state(struct ap_queue *aq) in ap_queue_init_state() argument
932 spin_lock_bh(&aq->lock); in ap_queue_init_state()
933 aq->dev_state = AP_DEV_STATE_OPERATING; in ap_queue_init_state()
934 aq->sm_state = AP_SM_STATE_RESET_START; in ap_queue_init_state()
935 aq->last_err_rc = 0; in ap_queue_init_state()
936 ap_wait(ap_sm_event(aq, AP_SM_EVENT_POLL)); in ap_queue_init_state()
937 spin_unlock_bh(&aq->lock); in ap_queue_init_state()