Lines Matching refs:aq
19 static void __ap_flush_queue(struct ap_queue *aq);
25 static inline bool ap_q_supports_bind(struct ap_queue *aq) in ap_q_supports_bind() argument
27 return ap_test_bit(&aq->card->functions, AP_FUNC_EP11) || in ap_q_supports_bind()
28 ap_test_bit(&aq->card->functions, AP_FUNC_ACCEL); in ap_q_supports_bind()
31 static inline bool ap_q_supports_assoc(struct ap_queue *aq) in ap_q_supports_assoc() argument
33 return ap_test_bit(&aq->card->functions, AP_FUNC_EP11); in ap_q_supports_assoc()
45 static int ap_queue_enable_irq(struct ap_queue *aq, void *ind) in ap_queue_enable_irq() argument
52 status = ap_aqic(aq->qid, qirqctrl, virt_to_phys(ind)); in ap_queue_enable_irq()
64 AP_QID_CARD(aq->qid), in ap_queue_enable_irq()
65 AP_QID_QUEUE(aq->qid)); in ap_queue_enable_irq()
98 static enum ap_sm_wait ap_sm_nop(struct ap_queue *aq) in ap_sm_nop() argument
110 static struct ap_queue_status ap_sm_recv(struct ap_queue *aq) in ap_sm_recv() argument
127 status = ap_dqap(aq->qid, &aq->reply->psmid, in ap_sm_recv()
128 aq->reply->msg, aq->reply->bufsize, in ap_sm_recv()
129 &aq->reply->len, &reslen, &resgr0); in ap_sm_recv()
135 aq->queue_count = max_t(int, 0, aq->queue_count - 1); in ap_sm_recv()
136 if (!status.queue_empty && !aq->queue_count) in ap_sm_recv()
137 aq->queue_count++; in ap_sm_recv()
138 if (aq->queue_count > 0) in ap_sm_recv()
139 mod_timer(&aq->timeout, in ap_sm_recv()
140 jiffies + aq->request_timeout); in ap_sm_recv()
141 list_for_each_entry(ap_msg, &aq->pendingq, list) { in ap_sm_recv()
142 if (ap_msg->psmid != aq->reply->psmid) in ap_sm_recv()
145 aq->pendingq_count--; in ap_sm_recv()
148 ap_msg->receive(aq, ap_msg, NULL); in ap_sm_recv()
150 ap_msg->receive(aq, ap_msg, aq->reply); in ap_sm_recv()
157 __func__, aq->reply->psmid, in ap_sm_recv()
158 AP_QID_CARD(aq->qid), AP_QID_QUEUE(aq->qid)); in ap_sm_recv()
162 if (!status.queue_empty || aq->queue_count <= 0) in ap_sm_recv()
165 aq->queue_count = 0; in ap_sm_recv()
166 list_splice_init(&aq->pendingq, &aq->requestq); in ap_sm_recv()
167 aq->requestq_count += aq->pendingq_count; in ap_sm_recv()
168 aq->pendingq_count = 0; in ap_sm_recv()
182 static enum ap_sm_wait ap_sm_read(struct ap_queue *aq) in ap_sm_read() argument
186 if (!aq->reply) in ap_sm_read()
188 status = ap_sm_recv(aq); in ap_sm_read()
193 if (aq->queue_count > 0) { in ap_sm_read()
194 aq->sm_state = AP_SM_STATE_WORKING; in ap_sm_read()
197 aq->sm_state = AP_SM_STATE_IDLE; in ap_sm_read()
200 if (aq->queue_count > 0) in ap_sm_read()
201 return aq->interrupt ? in ap_sm_read()
203 aq->sm_state = AP_SM_STATE_IDLE; in ap_sm_read()
206 aq->dev_state = AP_DEV_STATE_ERROR; in ap_sm_read()
207 aq->last_err_rc = status.response_code; in ap_sm_read()
210 AP_QID_CARD(aq->qid), AP_QID_QUEUE(aq->qid)); in ap_sm_read()
221 static enum ap_sm_wait ap_sm_write(struct ap_queue *aq) in ap_sm_write() argument
225 ap_qid_t qid = aq->qid; in ap_sm_write()
227 if (aq->requestq_count <= 0) in ap_sm_write()
231 ap_msg = list_entry(aq->requestq.next, struct ap_message, list); in ap_sm_write()
239 aq->queue_count = max_t(int, 1, aq->queue_count + 1); in ap_sm_write()
240 if (aq->queue_count == 1) in ap_sm_write()
241 mod_timer(&aq->timeout, jiffies + aq->request_timeout); in ap_sm_write()
242 list_move_tail(&ap_msg->list, &aq->pendingq); in ap_sm_write()
243 aq->requestq_count--; in ap_sm_write()
244 aq->pendingq_count++; in ap_sm_write()
245 if (aq->queue_count < aq->card->queue_depth) { in ap_sm_write()
246 aq->sm_state = AP_SM_STATE_WORKING; in ap_sm_write()
251 aq->sm_state = AP_SM_STATE_QUEUE_FULL; in ap_sm_write()
252 return aq->interrupt ? in ap_sm_write()
255 aq->sm_state = AP_SM_STATE_RESET_WAIT; in ap_sm_write()
263 aq->requestq_count--; in ap_sm_write()
265 ap_msg->receive(aq, ap_msg, NULL); in ap_sm_write()
268 aq->dev_state = AP_DEV_STATE_ERROR; in ap_sm_write()
269 aq->last_err_rc = status.response_code; in ap_sm_write()
272 AP_QID_CARD(aq->qid), AP_QID_QUEUE(aq->qid)); in ap_sm_write()
283 static enum ap_sm_wait ap_sm_read_write(struct ap_queue *aq) in ap_sm_read_write() argument
285 return min(ap_sm_read(aq), ap_sm_write(aq)); in ap_sm_read_write()
294 static enum ap_sm_wait ap_sm_reset(struct ap_queue *aq) in ap_sm_reset() argument
298 status = ap_rapq(aq->qid, aq->rapq_fbit); in ap_sm_reset()
304 aq->sm_state = AP_SM_STATE_RESET_WAIT; in ap_sm_reset()
305 aq->interrupt = false; in ap_sm_reset()
306 aq->rapq_fbit = 0; in ap_sm_reset()
309 aq->dev_state = AP_DEV_STATE_ERROR; in ap_sm_reset()
310 aq->last_err_rc = status.response_code; in ap_sm_reset()
313 AP_QID_CARD(aq->qid), AP_QID_QUEUE(aq->qid)); in ap_sm_reset()
324 static enum ap_sm_wait ap_sm_reset_wait(struct ap_queue *aq) in ap_sm_reset_wait() argument
329 if (aq->queue_count > 0 && aq->reply) in ap_sm_reset_wait()
331 status = ap_sm_recv(aq); in ap_sm_reset_wait()
334 status = ap_tapq(aq->qid, NULL); in ap_sm_reset_wait()
339 if (lsi_ptr && ap_queue_enable_irq(aq, lsi_ptr) == 0) in ap_sm_reset_wait()
340 aq->sm_state = AP_SM_STATE_SETIRQ_WAIT; in ap_sm_reset_wait()
342 aq->sm_state = (aq->queue_count > 0) ? in ap_sm_reset_wait()
352 aq->dev_state = AP_DEV_STATE_ERROR; in ap_sm_reset_wait()
353 aq->last_err_rc = status.response_code; in ap_sm_reset_wait()
356 AP_QID_CARD(aq->qid), AP_QID_QUEUE(aq->qid)); in ap_sm_reset_wait()
367 static enum ap_sm_wait ap_sm_setirq_wait(struct ap_queue *aq) in ap_sm_setirq_wait() argument
371 if (aq->queue_count > 0 && aq->reply) in ap_sm_setirq_wait()
373 status = ap_sm_recv(aq); in ap_sm_setirq_wait()
376 status = ap_tapq(aq->qid, NULL); in ap_sm_setirq_wait()
380 aq->interrupt = true; in ap_sm_setirq_wait()
381 aq->sm_state = (aq->queue_count > 0) ? in ap_sm_setirq_wait()
387 if (aq->queue_count > 0) in ap_sm_setirq_wait()
393 aq->dev_state = AP_DEV_STATE_ERROR; in ap_sm_setirq_wait()
394 aq->last_err_rc = status.response_code; in ap_sm_setirq_wait()
397 AP_QID_CARD(aq->qid), AP_QID_QUEUE(aq->qid)); in ap_sm_setirq_wait()
407 static enum ap_sm_wait ap_sm_assoc_wait(struct ap_queue *aq) in ap_sm_assoc_wait() argument
412 status = ap_test_queue(aq->qid, 1, &info); in ap_sm_assoc_wait()
415 aq->dev_state = AP_DEV_STATE_ERROR; in ap_sm_assoc_wait()
416 aq->last_err_rc = status.response_code; in ap_sm_assoc_wait()
419 AP_QID_CARD(aq->qid), AP_QID_QUEUE(aq->qid)); in ap_sm_assoc_wait()
423 aq->dev_state = AP_DEV_STATE_ERROR; in ap_sm_assoc_wait()
424 aq->last_err_rc = status.response_code; in ap_sm_assoc_wait()
427 AP_QID_CARD(aq->qid), AP_QID_QUEUE(aq->qid)); in ap_sm_assoc_wait()
435 aq->sm_state = AP_SM_STATE_IDLE; in ap_sm_assoc_wait()
437 __func__, AP_QID_CARD(aq->qid), in ap_sm_assoc_wait()
438 AP_QID_QUEUE(aq->qid), aq->assoc_idx); in ap_sm_assoc_wait()
445 aq->assoc_idx = ASSOC_IDX_INVALID; in ap_sm_assoc_wait()
446 aq->dev_state = AP_DEV_STATE_ERROR; in ap_sm_assoc_wait()
447 aq->last_err_rc = status.response_code; in ap_sm_assoc_wait()
450 AP_QID_CARD(aq->qid), AP_QID_QUEUE(aq->qid)); in ap_sm_assoc_wait()
489 enum ap_sm_wait ap_sm_event(struct ap_queue *aq, enum ap_sm_event event) in ap_sm_event() argument
491 if (aq->config && !aq->chkstop && in ap_sm_event()
492 aq->dev_state > AP_DEV_STATE_UNINITIATED) in ap_sm_event()
493 return ap_jumptable[aq->sm_state][event](aq); in ap_sm_event()
498 enum ap_sm_wait ap_sm_event_loop(struct ap_queue *aq, enum ap_sm_event event) in ap_sm_event_loop() argument
502 while ((wait = ap_sm_event(aq, event)) == AP_SM_WAIT_AGAIN) in ap_sm_event_loop()
514 struct ap_queue *aq = to_ap_queue(dev); in request_count_show() local
518 spin_lock_bh(&aq->lock); in request_count_show()
519 if (aq->dev_state > AP_DEV_STATE_UNINITIATED) { in request_count_show()
520 req_cnt = aq->total_request_count; in request_count_show()
523 spin_unlock_bh(&aq->lock); in request_count_show()
535 struct ap_queue *aq = to_ap_queue(dev); in request_count_store() local
537 spin_lock_bh(&aq->lock); in request_count_store()
538 aq->total_request_count = 0; in request_count_store()
539 spin_unlock_bh(&aq->lock); in request_count_store()
549 struct ap_queue *aq = to_ap_queue(dev); in requestq_count_show() local
552 spin_lock_bh(&aq->lock); in requestq_count_show()
553 if (aq->dev_state > AP_DEV_STATE_UNINITIATED) in requestq_count_show()
554 reqq_cnt = aq->requestq_count; in requestq_count_show()
555 spin_unlock_bh(&aq->lock); in requestq_count_show()
564 struct ap_queue *aq = to_ap_queue(dev); in pendingq_count_show() local
567 spin_lock_bh(&aq->lock); in pendingq_count_show()
568 if (aq->dev_state > AP_DEV_STATE_UNINITIATED) in pendingq_count_show()
569 penq_cnt = aq->pendingq_count; in pendingq_count_show()
570 spin_unlock_bh(&aq->lock); in pendingq_count_show()
579 struct ap_queue *aq = to_ap_queue(dev); in reset_show() local
582 spin_lock_bh(&aq->lock); in reset_show()
583 switch (aq->sm_state) { in reset_show()
595 spin_unlock_bh(&aq->lock); in reset_show()
603 struct ap_queue *aq = to_ap_queue(dev); in reset_store() local
605 spin_lock_bh(&aq->lock); in reset_store()
606 __ap_flush_queue(aq); in reset_store()
607 aq->sm_state = AP_SM_STATE_RESET_START; in reset_store()
608 ap_wait(ap_sm_event(aq, AP_SM_EVENT_POLL)); in reset_store()
609 spin_unlock_bh(&aq->lock); in reset_store()
612 __func__, AP_QID_CARD(aq->qid), AP_QID_QUEUE(aq->qid)); in reset_store()
622 struct ap_queue *aq = to_ap_queue(dev); in interrupt_show() local
625 spin_lock_bh(&aq->lock); in interrupt_show()
626 if (aq->sm_state == AP_SM_STATE_SETIRQ_WAIT) in interrupt_show()
628 else if (aq->interrupt) in interrupt_show()
632 spin_unlock_bh(&aq->lock); in interrupt_show()
641 struct ap_queue *aq = to_ap_queue(dev); in config_show() local
644 spin_lock_bh(&aq->lock); in config_show()
645 rc = sysfs_emit(buf, "%d\n", aq->config ? 1 : 0); in config_show()
646 spin_unlock_bh(&aq->lock); in config_show()
655 struct ap_queue *aq = to_ap_queue(dev); in chkstop_show() local
658 spin_lock_bh(&aq->lock); in chkstop_show()
659 rc = sysfs_emit(buf, "%d\n", aq->chkstop ? 1 : 0); in chkstop_show()
660 spin_unlock_bh(&aq->lock); in chkstop_show()
669 struct ap_queue *aq = to_ap_queue(dev); in ap_functions_show() local
673 status = ap_test_queue(aq->qid, 1, &info); in ap_functions_show()
677 AP_QID_CARD(aq->qid), AP_QID_QUEUE(aq->qid)); in ap_functions_show()
690 struct ap_queue *aq = to_ap_queue(dev); in states_show() local
693 spin_lock_bh(&aq->lock); in states_show()
695 switch (aq->dev_state) { in states_show()
712 if (aq->dev_state) { in states_show()
713 switch (aq->sm_state) { in states_show()
739 spin_unlock_bh(&aq->lock); in states_show()
748 struct ap_queue *aq = to_ap_queue(dev); in last_err_rc_show() local
751 spin_lock_bh(&aq->lock); in last_err_rc_show()
752 rc = aq->last_err_rc; in last_err_rc_show()
753 spin_unlock_bh(&aq->lock); in last_err_rc_show()
822 struct ap_queue *aq = to_ap_queue(dev); in se_bind_show() local
826 if (!ap_q_supports_bind(aq)) in se_bind_show()
829 status = ap_test_queue(aq->qid, 1, &info); in se_bind_show()
833 AP_QID_CARD(aq->qid), AP_QID_QUEUE(aq->qid)); in se_bind_show()
849 struct ap_queue *aq = to_ap_queue(dev); in se_bind_store() local
854 if (!ap_q_supports_bind(aq)) in se_bind_store()
864 spin_lock_bh(&aq->lock); in se_bind_store()
865 if (aq->sm_state < AP_SM_STATE_IDLE) { in se_bind_store()
866 spin_unlock_bh(&aq->lock); in se_bind_store()
869 status = ap_bapq(aq->qid); in se_bind_store()
870 spin_unlock_bh(&aq->lock); in se_bind_store()
874 AP_QID_CARD(aq->qid), in se_bind_store()
875 AP_QID_QUEUE(aq->qid)); in se_bind_store()
880 spin_lock_bh(&aq->lock); in se_bind_store()
881 __ap_flush_queue(aq); in se_bind_store()
882 aq->rapq_fbit = 1; in se_bind_store()
883 aq->assoc_idx = ASSOC_IDX_INVALID; in se_bind_store()
884 aq->sm_state = AP_SM_STATE_RESET_START; in se_bind_store()
885 ap_wait(ap_sm_event(aq, AP_SM_EVENT_POLL)); in se_bind_store()
886 spin_unlock_bh(&aq->lock); in se_bind_store()
897 struct ap_queue *aq = to_ap_queue(dev); in se_associate_show() local
901 if (!ap_q_supports_assoc(aq)) in se_associate_show()
904 status = ap_test_queue(aq->qid, 1, &info); in se_associate_show()
908 AP_QID_CARD(aq->qid), AP_QID_QUEUE(aq->qid)); in se_associate_show()
914 if (aq->assoc_idx == ASSOC_IDX_INVALID) { in se_associate_show()
918 return sysfs_emit(buf, "associated %u\n", aq->assoc_idx); in se_associate_show()
920 if (aq->assoc_idx != ASSOC_IDX_INVALID) in se_associate_show()
932 struct ap_queue *aq = to_ap_queue(dev); in se_associate_store() local
937 if (!ap_q_supports_assoc(aq)) in se_associate_store()
947 spin_lock_bh(&aq->lock); in se_associate_store()
950 if (aq->sm_state != AP_SM_STATE_IDLE) { in se_associate_store()
951 spin_unlock_bh(&aq->lock); in se_associate_store()
956 if (aq->assoc_idx != ASSOC_IDX_INVALID) { in se_associate_store()
957 spin_unlock_bh(&aq->lock); in se_associate_store()
962 status = ap_aapq(aq->qid, value); in se_associate_store()
966 aq->sm_state = AP_SM_STATE_ASSOC_WAIT; in se_associate_store()
967 aq->assoc_idx = value; in se_associate_store()
968 ap_wait(ap_sm_event(aq, AP_SM_EVENT_POLL)); in se_associate_store()
969 spin_unlock_bh(&aq->lock); in se_associate_store()
972 spin_unlock_bh(&aq->lock); in se_associate_store()
975 AP_QID_CARD(aq->qid), AP_QID_QUEUE(aq->qid)); in se_associate_store()
1001 struct ap_queue *aq = to_ap_queue(dev); in ap_queue_device_release() local
1004 hash_del(&aq->hnode); in ap_queue_device_release()
1007 kfree(aq); in ap_queue_device_release()
1012 struct ap_queue *aq; in ap_queue_create() local
1014 aq = kzalloc(sizeof(*aq), GFP_KERNEL); in ap_queue_create()
1015 if (!aq) in ap_queue_create()
1017 aq->ap_dev.device.release = ap_queue_device_release; in ap_queue_create()
1018 aq->ap_dev.device.type = &ap_queue_type; in ap_queue_create()
1019 aq->ap_dev.device_type = device_type; in ap_queue_create()
1022 aq->ap_dev.device.groups = ap_queue_dev_sb_attr_groups; in ap_queue_create()
1023 aq->qid = qid; in ap_queue_create()
1024 aq->interrupt = false; in ap_queue_create()
1025 spin_lock_init(&aq->lock); in ap_queue_create()
1026 INIT_LIST_HEAD(&aq->pendingq); in ap_queue_create()
1027 INIT_LIST_HEAD(&aq->requestq); in ap_queue_create()
1028 timer_setup(&aq->timeout, ap_request_timeout, 0); in ap_queue_create()
1030 return aq; in ap_queue_create()
1033 void ap_queue_init_reply(struct ap_queue *aq, struct ap_message *reply) in ap_queue_init_reply() argument
1035 aq->reply = reply; in ap_queue_init_reply()
1037 spin_lock_bh(&aq->lock); in ap_queue_init_reply()
1038 ap_wait(ap_sm_event(aq, AP_SM_EVENT_POLL)); in ap_queue_init_reply()
1039 spin_unlock_bh(&aq->lock); in ap_queue_init_reply()
1048 int ap_queue_message(struct ap_queue *aq, struct ap_message *ap_msg) in ap_queue_message() argument
1055 spin_lock_bh(&aq->lock); in ap_queue_message()
1058 if (aq->dev_state == AP_DEV_STATE_OPERATING) { in ap_queue_message()
1059 list_add_tail(&ap_msg->list, &aq->requestq); in ap_queue_message()
1060 aq->requestq_count++; in ap_queue_message()
1061 aq->total_request_count++; in ap_queue_message()
1062 atomic64_inc(&aq->card->total_request_count); in ap_queue_message()
1068 ap_wait(ap_sm_event_loop(aq, AP_SM_EVENT_POLL)); in ap_queue_message()
1070 spin_unlock_bh(&aq->lock); in ap_queue_message()
1086 void ap_cancel_message(struct ap_queue *aq, struct ap_message *ap_msg) in ap_cancel_message() argument
1090 spin_lock_bh(&aq->lock); in ap_cancel_message()
1092 list_for_each_entry(tmp, &aq->pendingq, list) in ap_cancel_message()
1094 aq->pendingq_count--; in ap_cancel_message()
1097 aq->requestq_count--; in ap_cancel_message()
1101 spin_unlock_bh(&aq->lock); in ap_cancel_message()
1111 static void __ap_flush_queue(struct ap_queue *aq) in __ap_flush_queue() argument
1115 list_for_each_entry_safe(ap_msg, next, &aq->pendingq, list) { in __ap_flush_queue()
1117 aq->pendingq_count--; in __ap_flush_queue()
1119 ap_msg->receive(aq, ap_msg, NULL); in __ap_flush_queue()
1121 list_for_each_entry_safe(ap_msg, next, &aq->requestq, list) { in __ap_flush_queue()
1123 aq->requestq_count--; in __ap_flush_queue()
1125 ap_msg->receive(aq, ap_msg, NULL); in __ap_flush_queue()
1127 aq->queue_count = 0; in __ap_flush_queue()
1130 void ap_flush_queue(struct ap_queue *aq) in ap_flush_queue() argument
1132 spin_lock_bh(&aq->lock); in ap_flush_queue()
1133 __ap_flush_queue(aq); in ap_flush_queue()
1134 spin_unlock_bh(&aq->lock); in ap_flush_queue()
1138 void ap_queue_prepare_remove(struct ap_queue *aq) in ap_queue_prepare_remove() argument
1140 spin_lock_bh(&aq->lock); in ap_queue_prepare_remove()
1142 __ap_flush_queue(aq); in ap_queue_prepare_remove()
1144 aq->dev_state = AP_DEV_STATE_SHUTDOWN; in ap_queue_prepare_remove()
1145 spin_unlock_bh(&aq->lock); in ap_queue_prepare_remove()
1146 del_timer_sync(&aq->timeout); in ap_queue_prepare_remove()
1149 void ap_queue_remove(struct ap_queue *aq) in ap_queue_remove() argument
1157 spin_lock_bh(&aq->lock); in ap_queue_remove()
1158 ap_zapq(aq->qid, 0); in ap_queue_remove()
1159 aq->dev_state = AP_DEV_STATE_UNINITIATED; in ap_queue_remove()
1160 spin_unlock_bh(&aq->lock); in ap_queue_remove()
1163 void ap_queue_init_state(struct ap_queue *aq) in ap_queue_init_state() argument
1165 spin_lock_bh(&aq->lock); in ap_queue_init_state()
1166 aq->dev_state = AP_DEV_STATE_OPERATING; in ap_queue_init_state()
1167 aq->sm_state = AP_SM_STATE_RESET_START; in ap_queue_init_state()
1168 aq->last_err_rc = 0; in ap_queue_init_state()
1169 aq->assoc_idx = ASSOC_IDX_INVALID; in ap_queue_init_state()
1170 ap_wait(ap_sm_event(aq, AP_SM_EVENT_POLL)); in ap_queue_init_state()
1171 spin_unlock_bh(&aq->lock); in ap_queue_init_state()