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