Lines Matching refs:aq

19 static void __ap_flush_queue(struct ap_queue *aq);
30 static int ap_queue_enable_interruption(struct ap_queue *aq, void *ind) in ap_queue_enable_interruption() argument
37 status = ap_aqic(aq->qid, qirqctrl, ind); in ap_queue_enable_interruption()
47 AP_QID_CARD(aq->qid), in ap_queue_enable_interruption()
48 AP_QID_QUEUE(aq->qid)); in ap_queue_enable_interruption()
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
139 status = ap_dqap(aq->qid, &aq->reply->psmid, in ap_sm_recv()
140 aq->reply->msg, aq->reply->len); in ap_sm_recv()
143 aq->queue_count--; in ap_sm_recv()
144 if (aq->queue_count > 0) in ap_sm_recv()
145 mod_timer(&aq->timeout, in ap_sm_recv()
146 jiffies + aq->request_timeout); in ap_sm_recv()
147 list_for_each_entry(ap_msg, &aq->pendingq, list) { in ap_sm_recv()
148 if (ap_msg->psmid != aq->reply->psmid) in ap_sm_recv()
151 aq->pendingq_count--; in ap_sm_recv()
152 ap_msg->receive(aq, ap_msg, aq->reply); in ap_sm_recv()
157 if (!status.queue_empty || aq->queue_count <= 0) in ap_sm_recv()
160 aq->queue_count = 0; in ap_sm_recv()
161 list_splice_init(&aq->pendingq, &aq->requestq); in ap_sm_recv()
162 aq->requestq_count += aq->pendingq_count; in ap_sm_recv()
163 aq->pendingq_count = 0; in ap_sm_recv()
177 static enum ap_sm_wait ap_sm_read(struct ap_queue *aq) in ap_sm_read() argument
181 if (!aq->reply) in ap_sm_read()
183 status = ap_sm_recv(aq); in ap_sm_read()
186 if (aq->queue_count > 0) { in ap_sm_read()
187 aq->sm_state = AP_SM_STATE_WORKING; in ap_sm_read()
190 aq->sm_state = AP_SM_STATE_IDLE; in ap_sm_read()
193 if (aq->queue_count > 0) in ap_sm_read()
195 aq->sm_state = AP_SM_STATE_IDLE; in ap_sm_read()
198 aq->dev_state = AP_DEV_STATE_ERROR; in ap_sm_read()
199 aq->last_err_rc = status.response_code; in ap_sm_read()
202 AP_QID_CARD(aq->qid), AP_QID_QUEUE(aq->qid)); in ap_sm_read()
213 static enum ap_sm_wait ap_sm_write(struct ap_queue *aq) in ap_sm_write() argument
217 ap_qid_t qid = aq->qid; in ap_sm_write()
219 if (aq->requestq_count <= 0) in ap_sm_write()
222 ap_msg = list_entry(aq->requestq.next, struct ap_message, list); in ap_sm_write()
235 aq->queue_count++; in ap_sm_write()
236 if (aq->queue_count == 1) in ap_sm_write()
237 mod_timer(&aq->timeout, jiffies + aq->request_timeout); in ap_sm_write()
238 list_move_tail(&ap_msg->list, &aq->pendingq); in ap_sm_write()
239 aq->requestq_count--; in ap_sm_write()
240 aq->pendingq_count++; in ap_sm_write()
241 if (aq->queue_count < aq->card->queue_depth) { in ap_sm_write()
242 aq->sm_state = AP_SM_STATE_WORKING; in ap_sm_write()
247 aq->sm_state = AP_SM_STATE_QUEUE_FULL; in ap_sm_write()
250 aq->sm_state = AP_SM_STATE_RESET_WAIT; in ap_sm_write()
258 aq->requestq_count--; in ap_sm_write()
260 ap_msg->receive(aq, ap_msg, NULL); in ap_sm_write()
263 aq->dev_state = AP_DEV_STATE_ERROR; in ap_sm_write()
264 aq->last_err_rc = status.response_code; in ap_sm_write()
267 AP_QID_CARD(aq->qid), AP_QID_QUEUE(aq->qid)); in ap_sm_write()
278 static enum ap_sm_wait ap_sm_read_write(struct ap_queue *aq) in ap_sm_read_write() argument
280 return min(ap_sm_read(aq), ap_sm_write(aq)); in ap_sm_read_write()
289 static enum ap_sm_wait ap_sm_reset(struct ap_queue *aq) in ap_sm_reset() argument
293 status = ap_rapq(aq->qid); in ap_sm_reset()
297 aq->sm_state = AP_SM_STATE_RESET_WAIT; in ap_sm_reset()
298 aq->interrupt = AP_INTR_DISABLED; in ap_sm_reset()
301 aq->dev_state = AP_DEV_STATE_ERROR; in ap_sm_reset()
302 aq->last_err_rc = status.response_code; in ap_sm_reset()
305 AP_QID_CARD(aq->qid), AP_QID_QUEUE(aq->qid)); in ap_sm_reset()
316 static enum ap_sm_wait ap_sm_reset_wait(struct ap_queue *aq) in ap_sm_reset_wait() argument
321 if (aq->queue_count > 0 && aq->reply) in ap_sm_reset_wait()
323 status = ap_sm_recv(aq); in ap_sm_reset_wait()
326 status = ap_tapq(aq->qid, NULL); in ap_sm_reset_wait()
331 if (lsi_ptr && ap_queue_enable_interruption(aq, lsi_ptr) == 0) in ap_sm_reset_wait()
332 aq->sm_state = AP_SM_STATE_SETIRQ_WAIT; in ap_sm_reset_wait()
334 aq->sm_state = (aq->queue_count > 0) ? in ap_sm_reset_wait()
344 aq->dev_state = AP_DEV_STATE_ERROR; in ap_sm_reset_wait()
345 aq->last_err_rc = status.response_code; in ap_sm_reset_wait()
348 AP_QID_CARD(aq->qid), AP_QID_QUEUE(aq->qid)); in ap_sm_reset_wait()
359 static enum ap_sm_wait ap_sm_setirq_wait(struct ap_queue *aq) in ap_sm_setirq_wait() argument
363 if (aq->queue_count > 0 && aq->reply) in ap_sm_setirq_wait()
365 status = ap_sm_recv(aq); in ap_sm_setirq_wait()
368 status = ap_tapq(aq->qid, NULL); in ap_sm_setirq_wait()
372 aq->interrupt = AP_INTR_ENABLED; in ap_sm_setirq_wait()
373 aq->sm_state = (aq->queue_count > 0) ? in ap_sm_setirq_wait()
379 if (aq->queue_count > 0) in ap_sm_setirq_wait()
385 aq->dev_state = AP_DEV_STATE_ERROR; in ap_sm_setirq_wait()
386 aq->last_err_rc = status.response_code; in ap_sm_setirq_wait()
389 AP_QID_CARD(aq->qid), AP_QID_QUEUE(aq->qid)); in ap_sm_setirq_wait()
424 enum ap_sm_wait ap_sm_event(struct ap_queue *aq, enum ap_sm_event event) in ap_sm_event() argument
426 if (aq->dev_state > AP_DEV_STATE_UNINITIATED) in ap_sm_event()
427 return ap_jumptable[aq->sm_state][event](aq); in ap_sm_event()
432 enum ap_sm_wait ap_sm_event_loop(struct ap_queue *aq, enum ap_sm_event event) in ap_sm_event_loop() argument
436 while ((wait = ap_sm_event(aq, event)) == AP_SM_WAIT_AGAIN) in ap_sm_event_loop()
448 struct ap_queue *aq = to_ap_queue(dev); in request_count_show() local
452 spin_lock_bh(&aq->lock); in request_count_show()
453 if (aq->dev_state > AP_DEV_STATE_UNINITIATED) { in request_count_show()
454 req_cnt = aq->total_request_count; in request_count_show()
457 spin_unlock_bh(&aq->lock); in request_count_show()
469 struct ap_queue *aq = to_ap_queue(dev); in request_count_store() local
471 spin_lock_bh(&aq->lock); in request_count_store()
472 aq->total_request_count = 0; in request_count_store()
473 spin_unlock_bh(&aq->lock); in request_count_store()
483 struct ap_queue *aq = to_ap_queue(dev); in requestq_count_show() local
486 spin_lock_bh(&aq->lock); in requestq_count_show()
487 if (aq->dev_state > AP_DEV_STATE_UNINITIATED) in requestq_count_show()
488 reqq_cnt = aq->requestq_count; in requestq_count_show()
489 spin_unlock_bh(&aq->lock); in requestq_count_show()
498 struct ap_queue *aq = to_ap_queue(dev); in pendingq_count_show() local
501 spin_lock_bh(&aq->lock); in pendingq_count_show()
502 if (aq->dev_state > AP_DEV_STATE_UNINITIATED) in pendingq_count_show()
503 penq_cnt = aq->pendingq_count; in pendingq_count_show()
504 spin_unlock_bh(&aq->lock); in pendingq_count_show()
513 struct ap_queue *aq = to_ap_queue(dev); in reset_show() local
516 spin_lock_bh(&aq->lock); in reset_show()
517 switch (aq->sm_state) { in reset_show()
529 spin_unlock_bh(&aq->lock); in reset_show()
537 struct ap_queue *aq = to_ap_queue(dev); in reset_store() local
539 spin_lock_bh(&aq->lock); in reset_store()
540 __ap_flush_queue(aq); in reset_store()
541 aq->sm_state = AP_SM_STATE_RESET_START; in reset_store()
542 ap_wait(ap_sm_event(aq, AP_SM_EVENT_POLL)); in reset_store()
543 spin_unlock_bh(&aq->lock); in reset_store()
546 AP_QID_CARD(aq->qid), AP_QID_QUEUE(aq->qid)); in reset_store()
556 struct ap_queue *aq = to_ap_queue(dev); in interrupt_show() local
559 spin_lock_bh(&aq->lock); in interrupt_show()
560 if (aq->sm_state == AP_SM_STATE_SETIRQ_WAIT) in interrupt_show()
562 else if (aq->interrupt == AP_INTR_ENABLED) in interrupt_show()
566 spin_unlock_bh(&aq->lock); in interrupt_show()
575 struct ap_queue *aq = to_ap_queue(dev); in config_show() local
578 spin_lock_bh(&aq->lock); in config_show()
579 rc = scnprintf(buf, PAGE_SIZE, "%d\n", aq->config ? 1 : 0); in config_show()
580 spin_unlock_bh(&aq->lock); in config_show()
590 struct ap_queue *aq = to_ap_queue(dev); in states_show() local
593 spin_lock_bh(&aq->lock); in states_show()
595 switch (aq->dev_state) { in states_show()
612 if (aq->dev_state) { in states_show()
613 switch (aq->sm_state) { in states_show()
643 spin_unlock_bh(&aq->lock); in states_show()
652 struct ap_queue *aq = to_ap_queue(dev); in last_err_rc_show() local
655 spin_lock_bh(&aq->lock); in last_err_rc_show()
656 rc = aq->last_err_rc; in last_err_rc_show()
657 spin_unlock_bh(&aq->lock); in last_err_rc_show()
723 struct ap_queue *aq = to_ap_queue(dev); in ap_queue_device_release() local
726 hash_del(&aq->hnode); in ap_queue_device_release()
729 kfree(aq); in ap_queue_device_release()
734 struct ap_queue *aq; in ap_queue_create() local
736 aq = kzalloc(sizeof(*aq), GFP_KERNEL); in ap_queue_create()
737 if (!aq) in ap_queue_create()
739 aq->ap_dev.device.release = ap_queue_device_release; in ap_queue_create()
740 aq->ap_dev.device.type = &ap_queue_type; in ap_queue_create()
741 aq->ap_dev.device_type = device_type; in ap_queue_create()
742 aq->qid = qid; in ap_queue_create()
743 aq->interrupt = AP_INTR_DISABLED; in ap_queue_create()
744 spin_lock_init(&aq->lock); in ap_queue_create()
745 INIT_LIST_HEAD(&aq->pendingq); in ap_queue_create()
746 INIT_LIST_HEAD(&aq->requestq); in ap_queue_create()
747 timer_setup(&aq->timeout, ap_request_timeout, 0); in ap_queue_create()
749 return aq; in ap_queue_create()
752 void ap_queue_init_reply(struct ap_queue *aq, struct ap_message *reply) in ap_queue_init_reply() argument
754 aq->reply = reply; in ap_queue_init_reply()
756 spin_lock_bh(&aq->lock); in ap_queue_init_reply()
757 ap_wait(ap_sm_event(aq, AP_SM_EVENT_POLL)); in ap_queue_init_reply()
758 spin_unlock_bh(&aq->lock); in ap_queue_init_reply()
767 int ap_queue_message(struct ap_queue *aq, struct ap_message *ap_msg) in ap_queue_message() argument
774 spin_lock_bh(&aq->lock); in ap_queue_message()
777 if (aq->dev_state == AP_DEV_STATE_OPERATING) { in ap_queue_message()
778 list_add_tail(&ap_msg->list, &aq->requestq); in ap_queue_message()
779 aq->requestq_count++; in ap_queue_message()
780 aq->total_request_count++; in ap_queue_message()
781 atomic64_inc(&aq->card->total_request_count); in ap_queue_message()
786 ap_wait(ap_sm_event_loop(aq, AP_SM_EVENT_POLL)); in ap_queue_message()
788 spin_unlock_bh(&aq->lock); in ap_queue_message()
804 void ap_cancel_message(struct ap_queue *aq, struct ap_message *ap_msg) in ap_cancel_message() argument
808 spin_lock_bh(&aq->lock); in ap_cancel_message()
810 list_for_each_entry(tmp, &aq->pendingq, list) in ap_cancel_message()
812 aq->pendingq_count--; in ap_cancel_message()
815 aq->requestq_count--; in ap_cancel_message()
819 spin_unlock_bh(&aq->lock); in ap_cancel_message()
829 static void __ap_flush_queue(struct ap_queue *aq) in __ap_flush_queue() argument
833 list_for_each_entry_safe(ap_msg, next, &aq->pendingq, list) { in __ap_flush_queue()
835 aq->pendingq_count--; in __ap_flush_queue()
837 ap_msg->receive(aq, ap_msg, NULL); in __ap_flush_queue()
839 list_for_each_entry_safe(ap_msg, next, &aq->requestq, list) { in __ap_flush_queue()
841 aq->requestq_count--; in __ap_flush_queue()
843 ap_msg->receive(aq, ap_msg, NULL); in __ap_flush_queue()
845 aq->queue_count = 0; in __ap_flush_queue()
848 void ap_flush_queue(struct ap_queue *aq) in ap_flush_queue() argument
850 spin_lock_bh(&aq->lock); in ap_flush_queue()
851 __ap_flush_queue(aq); in ap_flush_queue()
852 spin_unlock_bh(&aq->lock); in ap_flush_queue()
856 void ap_queue_prepare_remove(struct ap_queue *aq) in ap_queue_prepare_remove() argument
858 spin_lock_bh(&aq->lock); in ap_queue_prepare_remove()
860 __ap_flush_queue(aq); in ap_queue_prepare_remove()
862 aq->dev_state = AP_DEV_STATE_SHUTDOWN; in ap_queue_prepare_remove()
863 spin_unlock_bh(&aq->lock); in ap_queue_prepare_remove()
864 del_timer_sync(&aq->timeout); in ap_queue_prepare_remove()
867 void ap_queue_remove(struct ap_queue *aq) in ap_queue_remove() argument
875 spin_lock_bh(&aq->lock); in ap_queue_remove()
876 ap_zapq(aq->qid); in ap_queue_remove()
877 aq->dev_state = AP_DEV_STATE_UNINITIATED; in ap_queue_remove()
878 spin_unlock_bh(&aq->lock); in ap_queue_remove()
881 void ap_queue_init_state(struct ap_queue *aq) in ap_queue_init_state() argument
883 spin_lock_bh(&aq->lock); in ap_queue_init_state()
884 aq->dev_state = AP_DEV_STATE_OPERATING; in ap_queue_init_state()
885 aq->sm_state = AP_SM_STATE_RESET_START; in ap_queue_init_state()
886 ap_wait(ap_sm_event(aq, AP_SM_EVENT_POLL)); in ap_queue_init_state()
887 spin_unlock_bh(&aq->lock); in ap_queue_init_state()