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 (!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->dev_state > AP_DEV_STATE_UNINITIATED) in ap_sm_event()
459 return ap_jumptable[aq->sm_state][event](aq); in ap_sm_event()
464 enum ap_sm_wait ap_sm_event_loop(struct ap_queue *aq, enum ap_sm_event event) in ap_sm_event_loop() argument
468 while ((wait = ap_sm_event(aq, event)) == AP_SM_WAIT_AGAIN) in ap_sm_event_loop()
480 struct ap_queue *aq = to_ap_queue(dev); in request_count_show() local
484 spin_lock_bh(&aq->lock); in request_count_show()
485 if (aq->dev_state > AP_DEV_STATE_UNINITIATED) { in request_count_show()
486 req_cnt = aq->total_request_count; in request_count_show()
489 spin_unlock_bh(&aq->lock); in request_count_show()
501 struct ap_queue *aq = to_ap_queue(dev); in request_count_store() local
503 spin_lock_bh(&aq->lock); in request_count_store()
504 aq->total_request_count = 0; in request_count_store()
505 spin_unlock_bh(&aq->lock); in request_count_store()
515 struct ap_queue *aq = to_ap_queue(dev); in requestq_count_show() local
518 spin_lock_bh(&aq->lock); in requestq_count_show()
519 if (aq->dev_state > AP_DEV_STATE_UNINITIATED) in requestq_count_show()
520 reqq_cnt = aq->requestq_count; in requestq_count_show()
521 spin_unlock_bh(&aq->lock); in requestq_count_show()
530 struct ap_queue *aq = to_ap_queue(dev); in pendingq_count_show() local
533 spin_lock_bh(&aq->lock); in pendingq_count_show()
534 if (aq->dev_state > AP_DEV_STATE_UNINITIATED) in pendingq_count_show()
535 penq_cnt = aq->pendingq_count; in pendingq_count_show()
536 spin_unlock_bh(&aq->lock); in pendingq_count_show()
545 struct ap_queue *aq = to_ap_queue(dev); in reset_show() local
548 spin_lock_bh(&aq->lock); in reset_show()
549 switch (aq->sm_state) { in reset_show()
561 spin_unlock_bh(&aq->lock); in reset_show()
569 struct ap_queue *aq = to_ap_queue(dev); in reset_store() local
571 spin_lock_bh(&aq->lock); in reset_store()
572 __ap_flush_queue(aq); in reset_store()
573 aq->sm_state = AP_SM_STATE_RESET_START; in reset_store()
574 ap_wait(ap_sm_event(aq, AP_SM_EVENT_POLL)); in reset_store()
575 spin_unlock_bh(&aq->lock); in reset_store()
578 __func__, AP_QID_CARD(aq->qid), AP_QID_QUEUE(aq->qid)); in reset_store()
588 struct ap_queue *aq = to_ap_queue(dev); in interrupt_show() local
591 spin_lock_bh(&aq->lock); in interrupt_show()
592 if (aq->sm_state == AP_SM_STATE_SETIRQ_WAIT) in interrupt_show()
594 else if (aq->interrupt) in interrupt_show()
598 spin_unlock_bh(&aq->lock); in interrupt_show()
607 struct ap_queue *aq = to_ap_queue(dev); in config_show() local
610 spin_lock_bh(&aq->lock); in config_show()
611 rc = scnprintf(buf, PAGE_SIZE, "%d\n", aq->config ? 1 : 0); in config_show()
612 spin_unlock_bh(&aq->lock); in config_show()
622 struct ap_queue *aq = to_ap_queue(dev); in states_show() local
625 spin_lock_bh(&aq->lock); in states_show()
627 switch (aq->dev_state) { in states_show()
644 if (aq->dev_state) { in states_show()
645 switch (aq->sm_state) { in states_show()
675 spin_unlock_bh(&aq->lock); in states_show()
684 struct ap_queue *aq = to_ap_queue(dev); in last_err_rc_show() local
687 spin_lock_bh(&aq->lock); in last_err_rc_show()
688 rc = aq->last_err_rc; in last_err_rc_show()
689 spin_unlock_bh(&aq->lock); in last_err_rc_show()
755 struct ap_queue *aq = to_ap_queue(dev); in ap_queue_device_release() local
758 hash_del(&aq->hnode); in ap_queue_device_release()
761 kfree(aq); in ap_queue_device_release()
766 struct ap_queue *aq; in ap_queue_create() local
768 aq = kzalloc(sizeof(*aq), GFP_KERNEL); in ap_queue_create()
769 if (!aq) in ap_queue_create()
771 aq->ap_dev.device.release = ap_queue_device_release; in ap_queue_create()
772 aq->ap_dev.device.type = &ap_queue_type; in ap_queue_create()
773 aq->ap_dev.device_type = device_type; in ap_queue_create()
774 aq->qid = qid; in ap_queue_create()
775 aq->interrupt = false; in ap_queue_create()
776 spin_lock_init(&aq->lock); in ap_queue_create()
777 INIT_LIST_HEAD(&aq->pendingq); in ap_queue_create()
778 INIT_LIST_HEAD(&aq->requestq); in ap_queue_create()
779 timer_setup(&aq->timeout, ap_request_timeout, 0); in ap_queue_create()
781 return aq; in ap_queue_create()
784 void ap_queue_init_reply(struct ap_queue *aq, struct ap_message *reply) in ap_queue_init_reply() argument
786 aq->reply = reply; in ap_queue_init_reply()
788 spin_lock_bh(&aq->lock); in ap_queue_init_reply()
789 ap_wait(ap_sm_event(aq, AP_SM_EVENT_POLL)); in ap_queue_init_reply()
790 spin_unlock_bh(&aq->lock); in ap_queue_init_reply()
799 int ap_queue_message(struct ap_queue *aq, struct ap_message *ap_msg) in ap_queue_message() argument
806 spin_lock_bh(&aq->lock); in ap_queue_message()
809 if (aq->dev_state == AP_DEV_STATE_OPERATING) { in ap_queue_message()
810 list_add_tail(&ap_msg->list, &aq->requestq); in ap_queue_message()
811 aq->requestq_count++; in ap_queue_message()
812 aq->total_request_count++; in ap_queue_message()
813 atomic64_inc(&aq->card->total_request_count); in ap_queue_message()
818 ap_wait(ap_sm_event_loop(aq, AP_SM_EVENT_POLL)); in ap_queue_message()
820 spin_unlock_bh(&aq->lock); in ap_queue_message()
836 void ap_cancel_message(struct ap_queue *aq, struct ap_message *ap_msg) in ap_cancel_message() argument
840 spin_lock_bh(&aq->lock); in ap_cancel_message()
842 list_for_each_entry(tmp, &aq->pendingq, list) in ap_cancel_message()
844 aq->pendingq_count--; in ap_cancel_message()
847 aq->requestq_count--; in ap_cancel_message()
851 spin_unlock_bh(&aq->lock); in ap_cancel_message()
861 static void __ap_flush_queue(struct ap_queue *aq) in __ap_flush_queue() argument
865 list_for_each_entry_safe(ap_msg, next, &aq->pendingq, list) { in __ap_flush_queue()
867 aq->pendingq_count--; in __ap_flush_queue()
869 ap_msg->receive(aq, ap_msg, NULL); in __ap_flush_queue()
871 list_for_each_entry_safe(ap_msg, next, &aq->requestq, list) { in __ap_flush_queue()
873 aq->requestq_count--; in __ap_flush_queue()
875 ap_msg->receive(aq, ap_msg, NULL); in __ap_flush_queue()
877 aq->queue_count = 0; in __ap_flush_queue()
880 void ap_flush_queue(struct ap_queue *aq) in ap_flush_queue() argument
882 spin_lock_bh(&aq->lock); in ap_flush_queue()
883 __ap_flush_queue(aq); in ap_flush_queue()
884 spin_unlock_bh(&aq->lock); in ap_flush_queue()
888 void ap_queue_prepare_remove(struct ap_queue *aq) in ap_queue_prepare_remove() argument
890 spin_lock_bh(&aq->lock); in ap_queue_prepare_remove()
892 __ap_flush_queue(aq); in ap_queue_prepare_remove()
894 aq->dev_state = AP_DEV_STATE_SHUTDOWN; in ap_queue_prepare_remove()
895 spin_unlock_bh(&aq->lock); in ap_queue_prepare_remove()
896 del_timer_sync(&aq->timeout); in ap_queue_prepare_remove()
899 void ap_queue_remove(struct ap_queue *aq) in ap_queue_remove() argument
907 spin_lock_bh(&aq->lock); in ap_queue_remove()
908 ap_zapq(aq->qid); in ap_queue_remove()
909 aq->dev_state = AP_DEV_STATE_UNINITIATED; in ap_queue_remove()
910 spin_unlock_bh(&aq->lock); in ap_queue_remove()
913 void ap_queue_init_state(struct ap_queue *aq) in ap_queue_init_state() argument
915 spin_lock_bh(&aq->lock); in ap_queue_init_state()
916 aq->dev_state = AP_DEV_STATE_OPERATING; in ap_queue_init_state()
917 aq->sm_state = AP_SM_STATE_RESET_START; in ap_queue_init_state()
918 ap_wait(ap_sm_event(aq, AP_SM_EVENT_POLL)); in ap_queue_init_state()
919 spin_unlock_bh(&aq->lock); in ap_queue_init_state()