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, 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 (aq->queue_count > 0) in ap_sm_recv()
161 mod_timer(&aq->timeout, in ap_sm_recv()
162 jiffies + aq->request_timeout); in ap_sm_recv()
163 list_for_each_entry(ap_msg, &aq->pendingq, list) { in ap_sm_recv()
164 if (ap_msg->psmid != aq->reply->psmid) in ap_sm_recv()
167 aq->pendingq_count--; in ap_sm_recv()
170 ap_msg->receive(aq, ap_msg, NULL); in ap_sm_recv()
172 ap_msg->receive(aq, ap_msg, aq->reply); in ap_sm_recv()
179 __func__, aq->reply->psmid, in ap_sm_recv()
180 AP_QID_CARD(aq->qid), AP_QID_QUEUE(aq->qid)); in ap_sm_recv()
184 if (!status.queue_empty || aq->queue_count <= 0) in ap_sm_recv()
187 aq->queue_count = 0; in ap_sm_recv()
188 list_splice_init(&aq->pendingq, &aq->requestq); in ap_sm_recv()
189 aq->requestq_count += aq->pendingq_count; in ap_sm_recv()
190 aq->pendingq_count = 0; in ap_sm_recv()
204 static enum ap_sm_wait ap_sm_read(struct ap_queue *aq) in ap_sm_read() argument
208 if (!aq->reply) in ap_sm_read()
210 status = ap_sm_recv(aq); in ap_sm_read()
213 if (aq->queue_count > 0) { in ap_sm_read()
214 aq->sm_state = AP_SM_STATE_WORKING; in ap_sm_read()
217 aq->sm_state = AP_SM_STATE_IDLE; in ap_sm_read()
220 if (aq->queue_count > 0) in ap_sm_read()
221 return aq->interrupt ? in ap_sm_read()
223 aq->sm_state = AP_SM_STATE_IDLE; in ap_sm_read()
226 aq->dev_state = AP_DEV_STATE_ERROR; in ap_sm_read()
227 aq->last_err_rc = status.response_code; in ap_sm_read()
230 AP_QID_CARD(aq->qid), AP_QID_QUEUE(aq->qid)); in ap_sm_read()
241 static enum ap_sm_wait ap_sm_write(struct ap_queue *aq) in ap_sm_write() argument
245 ap_qid_t qid = aq->qid; in ap_sm_write()
247 if (aq->requestq_count <= 0) in ap_sm_write()
250 ap_msg = list_entry(aq->requestq.next, struct ap_message, list); in ap_sm_write()
263 aq->queue_count = max_t(int, 1, aq->queue_count + 1); in ap_sm_write()
264 if (aq->queue_count == 1) in ap_sm_write()
265 mod_timer(&aq->timeout, jiffies + aq->request_timeout); in ap_sm_write()
266 list_move_tail(&ap_msg->list, &aq->pendingq); in ap_sm_write()
267 aq->requestq_count--; in ap_sm_write()
268 aq->pendingq_count++; in ap_sm_write()
269 if (aq->queue_count < aq->card->queue_depth) { in ap_sm_write()
270 aq->sm_state = AP_SM_STATE_WORKING; in ap_sm_write()
275 aq->sm_state = AP_SM_STATE_QUEUE_FULL; in ap_sm_write()
276 return aq->interrupt ? in ap_sm_write()
279 aq->sm_state = AP_SM_STATE_RESET_WAIT; in ap_sm_write()
287 aq->requestq_count--; in ap_sm_write()
289 ap_msg->receive(aq, ap_msg, NULL); in ap_sm_write()
292 aq->dev_state = AP_DEV_STATE_ERROR; in ap_sm_write()
293 aq->last_err_rc = status.response_code; in ap_sm_write()
296 AP_QID_CARD(aq->qid), AP_QID_QUEUE(aq->qid)); in ap_sm_write()
307 static enum ap_sm_wait ap_sm_read_write(struct ap_queue *aq) in ap_sm_read_write() argument
309 return min(ap_sm_read(aq), ap_sm_write(aq)); in ap_sm_read_write()
318 static enum ap_sm_wait ap_sm_reset(struct ap_queue *aq) in ap_sm_reset() argument
322 status = ap_rapq(aq->qid); in ap_sm_reset()
326 aq->sm_state = AP_SM_STATE_RESET_WAIT; in ap_sm_reset()
327 aq->interrupt = false; in ap_sm_reset()
330 aq->dev_state = AP_DEV_STATE_ERROR; in ap_sm_reset()
331 aq->last_err_rc = status.response_code; in ap_sm_reset()
334 AP_QID_CARD(aq->qid), AP_QID_QUEUE(aq->qid)); in ap_sm_reset()
345 static enum ap_sm_wait ap_sm_reset_wait(struct ap_queue *aq) in ap_sm_reset_wait() argument
350 if (aq->queue_count > 0 && aq->reply) in ap_sm_reset_wait()
352 status = ap_sm_recv(aq); in ap_sm_reset_wait()
355 status = ap_tapq(aq->qid, NULL); in ap_sm_reset_wait()
360 if (lsi_ptr && ap_queue_enable_irq(aq, lsi_ptr) == 0) in ap_sm_reset_wait()
361 aq->sm_state = AP_SM_STATE_SETIRQ_WAIT; in ap_sm_reset_wait()
363 aq->sm_state = (aq->queue_count > 0) ? in ap_sm_reset_wait()
373 aq->dev_state = AP_DEV_STATE_ERROR; in ap_sm_reset_wait()
374 aq->last_err_rc = status.response_code; in ap_sm_reset_wait()
377 AP_QID_CARD(aq->qid), AP_QID_QUEUE(aq->qid)); in ap_sm_reset_wait()
388 static enum ap_sm_wait ap_sm_setirq_wait(struct ap_queue *aq) in ap_sm_setirq_wait() argument
392 if (aq->queue_count > 0 && aq->reply) in ap_sm_setirq_wait()
394 status = ap_sm_recv(aq); in ap_sm_setirq_wait()
397 status = ap_tapq(aq->qid, NULL); in ap_sm_setirq_wait()
401 aq->interrupt = true; in ap_sm_setirq_wait()
402 aq->sm_state = (aq->queue_count > 0) ? in ap_sm_setirq_wait()
408 if (aq->queue_count > 0) in ap_sm_setirq_wait()
414 aq->dev_state = AP_DEV_STATE_ERROR; in ap_sm_setirq_wait()
415 aq->last_err_rc = status.response_code; in ap_sm_setirq_wait()
418 AP_QID_CARD(aq->qid), AP_QID_QUEUE(aq->qid)); in ap_sm_setirq_wait()
453 enum ap_sm_wait ap_sm_event(struct ap_queue *aq, enum ap_sm_event event) in ap_sm_event() argument
455 if (aq->dev_state > AP_DEV_STATE_UNINITIATED) in ap_sm_event()
456 return ap_jumptable[aq->sm_state][event](aq); in ap_sm_event()
461 enum ap_sm_wait ap_sm_event_loop(struct ap_queue *aq, enum ap_sm_event event) in ap_sm_event_loop() argument
465 while ((wait = ap_sm_event(aq, event)) == AP_SM_WAIT_AGAIN) in ap_sm_event_loop()
477 struct ap_queue *aq = to_ap_queue(dev); in request_count_show() local
481 spin_lock_bh(&aq->lock); in request_count_show()
482 if (aq->dev_state > AP_DEV_STATE_UNINITIATED) { in request_count_show()
483 req_cnt = aq->total_request_count; in request_count_show()
486 spin_unlock_bh(&aq->lock); in request_count_show()
498 struct ap_queue *aq = to_ap_queue(dev); in request_count_store() local
500 spin_lock_bh(&aq->lock); in request_count_store()
501 aq->total_request_count = 0; in request_count_store()
502 spin_unlock_bh(&aq->lock); in request_count_store()
512 struct ap_queue *aq = to_ap_queue(dev); in requestq_count_show() local
515 spin_lock_bh(&aq->lock); in requestq_count_show()
516 if (aq->dev_state > AP_DEV_STATE_UNINITIATED) in requestq_count_show()
517 reqq_cnt = aq->requestq_count; in requestq_count_show()
518 spin_unlock_bh(&aq->lock); in requestq_count_show()
527 struct ap_queue *aq = to_ap_queue(dev); in pendingq_count_show() local
530 spin_lock_bh(&aq->lock); in pendingq_count_show()
531 if (aq->dev_state > AP_DEV_STATE_UNINITIATED) in pendingq_count_show()
532 penq_cnt = aq->pendingq_count; in pendingq_count_show()
533 spin_unlock_bh(&aq->lock); in pendingq_count_show()
542 struct ap_queue *aq = to_ap_queue(dev); in reset_show() local
545 spin_lock_bh(&aq->lock); in reset_show()
546 switch (aq->sm_state) { in reset_show()
558 spin_unlock_bh(&aq->lock); in reset_show()
566 struct ap_queue *aq = to_ap_queue(dev); in reset_store() local
568 spin_lock_bh(&aq->lock); in reset_store()
569 __ap_flush_queue(aq); in reset_store()
570 aq->sm_state = AP_SM_STATE_RESET_START; in reset_store()
571 ap_wait(ap_sm_event(aq, AP_SM_EVENT_POLL)); in reset_store()
572 spin_unlock_bh(&aq->lock); in reset_store()
575 AP_QID_CARD(aq->qid), AP_QID_QUEUE(aq->qid)); in reset_store()
585 struct ap_queue *aq = to_ap_queue(dev); in interrupt_show() local
588 spin_lock_bh(&aq->lock); in interrupt_show()
589 if (aq->sm_state == AP_SM_STATE_SETIRQ_WAIT) in interrupt_show()
591 else if (aq->interrupt) in interrupt_show()
595 spin_unlock_bh(&aq->lock); in interrupt_show()
604 struct ap_queue *aq = to_ap_queue(dev); in config_show() local
607 spin_lock_bh(&aq->lock); in config_show()
608 rc = scnprintf(buf, PAGE_SIZE, "%d\n", aq->config ? 1 : 0); in config_show()
609 spin_unlock_bh(&aq->lock); in config_show()
619 struct ap_queue *aq = to_ap_queue(dev); in states_show() local
622 spin_lock_bh(&aq->lock); in states_show()
624 switch (aq->dev_state) { in states_show()
641 if (aq->dev_state) { in states_show()
642 switch (aq->sm_state) { in states_show()
672 spin_unlock_bh(&aq->lock); in states_show()
681 struct ap_queue *aq = to_ap_queue(dev); in last_err_rc_show() local
684 spin_lock_bh(&aq->lock); in last_err_rc_show()
685 rc = aq->last_err_rc; in last_err_rc_show()
686 spin_unlock_bh(&aq->lock); in last_err_rc_show()
752 struct ap_queue *aq = to_ap_queue(dev); in ap_queue_device_release() local
755 hash_del(&aq->hnode); in ap_queue_device_release()
758 kfree(aq); in ap_queue_device_release()
763 struct ap_queue *aq; in ap_queue_create() local
765 aq = kzalloc(sizeof(*aq), GFP_KERNEL); in ap_queue_create()
766 if (!aq) in ap_queue_create()
768 aq->ap_dev.device.release = ap_queue_device_release; in ap_queue_create()
769 aq->ap_dev.device.type = &ap_queue_type; in ap_queue_create()
770 aq->ap_dev.device_type = device_type; in ap_queue_create()
771 aq->qid = qid; in ap_queue_create()
772 aq->interrupt = false; in ap_queue_create()
773 spin_lock_init(&aq->lock); in ap_queue_create()
774 INIT_LIST_HEAD(&aq->pendingq); in ap_queue_create()
775 INIT_LIST_HEAD(&aq->requestq); in ap_queue_create()
776 timer_setup(&aq->timeout, ap_request_timeout, 0); in ap_queue_create()
778 return aq; in ap_queue_create()
781 void ap_queue_init_reply(struct ap_queue *aq, struct ap_message *reply) in ap_queue_init_reply() argument
783 aq->reply = reply; in ap_queue_init_reply()
785 spin_lock_bh(&aq->lock); in ap_queue_init_reply()
786 ap_wait(ap_sm_event(aq, AP_SM_EVENT_POLL)); in ap_queue_init_reply()
787 spin_unlock_bh(&aq->lock); in ap_queue_init_reply()
796 int ap_queue_message(struct ap_queue *aq, struct ap_message *ap_msg) in ap_queue_message() argument
803 spin_lock_bh(&aq->lock); in ap_queue_message()
806 if (aq->dev_state == AP_DEV_STATE_OPERATING) { in ap_queue_message()
807 list_add_tail(&ap_msg->list, &aq->requestq); in ap_queue_message()
808 aq->requestq_count++; in ap_queue_message()
809 aq->total_request_count++; in ap_queue_message()
810 atomic64_inc(&aq->card->total_request_count); in ap_queue_message()
815 ap_wait(ap_sm_event_loop(aq, AP_SM_EVENT_POLL)); in ap_queue_message()
817 spin_unlock_bh(&aq->lock); in ap_queue_message()
833 void ap_cancel_message(struct ap_queue *aq, struct ap_message *ap_msg) in ap_cancel_message() argument
837 spin_lock_bh(&aq->lock); in ap_cancel_message()
839 list_for_each_entry(tmp, &aq->pendingq, list) in ap_cancel_message()
841 aq->pendingq_count--; in ap_cancel_message()
844 aq->requestq_count--; in ap_cancel_message()
848 spin_unlock_bh(&aq->lock); in ap_cancel_message()
858 static void __ap_flush_queue(struct ap_queue *aq) in __ap_flush_queue() argument
862 list_for_each_entry_safe(ap_msg, next, &aq->pendingq, list) { in __ap_flush_queue()
864 aq->pendingq_count--; in __ap_flush_queue()
866 ap_msg->receive(aq, ap_msg, NULL); in __ap_flush_queue()
868 list_for_each_entry_safe(ap_msg, next, &aq->requestq, list) { in __ap_flush_queue()
870 aq->requestq_count--; in __ap_flush_queue()
872 ap_msg->receive(aq, ap_msg, NULL); in __ap_flush_queue()
874 aq->queue_count = 0; in __ap_flush_queue()
877 void ap_flush_queue(struct ap_queue *aq) in ap_flush_queue() argument
879 spin_lock_bh(&aq->lock); in ap_flush_queue()
880 __ap_flush_queue(aq); in ap_flush_queue()
881 spin_unlock_bh(&aq->lock); in ap_flush_queue()
885 void ap_queue_prepare_remove(struct ap_queue *aq) in ap_queue_prepare_remove() argument
887 spin_lock_bh(&aq->lock); in ap_queue_prepare_remove()
889 __ap_flush_queue(aq); in ap_queue_prepare_remove()
891 aq->dev_state = AP_DEV_STATE_SHUTDOWN; in ap_queue_prepare_remove()
892 spin_unlock_bh(&aq->lock); in ap_queue_prepare_remove()
893 del_timer_sync(&aq->timeout); in ap_queue_prepare_remove()
896 void ap_queue_remove(struct ap_queue *aq) in ap_queue_remove() argument
904 spin_lock_bh(&aq->lock); in ap_queue_remove()
905 ap_zapq(aq->qid); in ap_queue_remove()
906 aq->dev_state = AP_DEV_STATE_UNINITIATED; in ap_queue_remove()
907 spin_unlock_bh(&aq->lock); in ap_queue_remove()
910 void ap_queue_init_state(struct ap_queue *aq) in ap_queue_init_state() argument
912 spin_lock_bh(&aq->lock); in ap_queue_init_state()
913 aq->dev_state = AP_DEV_STATE_OPERATING; in ap_queue_init_state()
914 aq->sm_state = AP_SM_STATE_RESET_START; in ap_queue_init_state()
915 ap_wait(ap_sm_event(aq, AP_SM_EVENT_POLL)); in ap_queue_init_state()
916 spin_unlock_bh(&aq->lock); in ap_queue_init_state()