Lines Matching defs:aq

19 static void __ap_flush_queue(struct ap_queue *aq);
30 static int ap_queue_enable_irq(struct ap_queue *aq, void *ind)
37 status = ap_aqic(aq->qid, qirqctrl, ind);
47 AP_QID_CARD(aq->qid),
48 AP_QID_QUEUE(aq->qid));
122 static enum ap_sm_wait ap_sm_nop(struct ap_queue *aq)
130 * @aq: pointer to the AP queue
134 static struct ap_queue_status ap_sm_recv(struct ap_queue *aq)
140 status = ap_dqap(aq->qid, &aq->reply->psmid,
141 aq->reply->msg, aq->reply->len);
144 aq->queue_count = max_t(int, 0, aq->queue_count - 1);
145 if (!status.queue_empty && !aq->queue_count)
146 aq->queue_count++;
147 if (aq->queue_count > 0)
148 mod_timer(&aq->timeout,
149 jiffies + aq->request_timeout);
150 list_for_each_entry(ap_msg, &aq->pendingq, list) {
151 if (ap_msg->psmid != aq->reply->psmid)
154 aq->pendingq_count--;
155 ap_msg->receive(aq, ap_msg, aq->reply);
161 __func__, aq->reply->psmid,
162 AP_QID_CARD(aq->qid), AP_QID_QUEUE(aq->qid));
166 if (!status.queue_empty || aq->queue_count <= 0)
169 aq->queue_count = 0;
170 list_splice_init(&aq->pendingq, &aq->requestq);
171 aq->requestq_count += aq->pendingq_count;
172 aq->pendingq_count = 0;
182 * @aq: pointer to the AP queue
186 static enum ap_sm_wait ap_sm_read(struct ap_queue *aq)
190 if (!aq->reply)
192 status = ap_sm_recv(aq);
195 if (aq->queue_count > 0) {
196 aq->sm_state = AP_SM_STATE_WORKING;
199 aq->sm_state = AP_SM_STATE_IDLE;
202 if (aq->queue_count > 0)
203 return aq->interrupt ?
205 aq->sm_state = AP_SM_STATE_IDLE;
208 aq->dev_state = AP_DEV_STATE_ERROR;
209 aq->last_err_rc = status.response_code;
212 AP_QID_CARD(aq->qid), AP_QID_QUEUE(aq->qid));
219 * @aq: pointer to the AP queue
223 static enum ap_sm_wait ap_sm_write(struct ap_queue *aq)
227 ap_qid_t qid = aq->qid;
229 if (aq->requestq_count <= 0)
232 ap_msg = list_entry(aq->requestq.next, struct ap_message, list);
245 aq->queue_count = max_t(int, 1, aq->queue_count + 1);
246 if (aq->queue_count == 1)
247 mod_timer(&aq->timeout, jiffies + aq->request_timeout);
248 list_move_tail(&ap_msg->list, &aq->pendingq);
249 aq->requestq_count--;
250 aq->pendingq_count++;
251 if (aq->queue_count < aq->card->queue_depth) {
252 aq->sm_state = AP_SM_STATE_WORKING;
257 aq->sm_state = AP_SM_STATE_QUEUE_FULL;
258 return aq->interrupt ?
261 aq->sm_state = AP_SM_STATE_RESET_WAIT;
269 aq->requestq_count--;
271 ap_msg->receive(aq, ap_msg, NULL);
274 aq->dev_state = AP_DEV_STATE_ERROR;
275 aq->last_err_rc = status.response_code;
278 AP_QID_CARD(aq->qid), AP_QID_QUEUE(aq->qid));
285 * @aq: pointer to the AP queue
289 static enum ap_sm_wait ap_sm_read_write(struct ap_queue *aq)
291 return min(ap_sm_read(aq), ap_sm_write(aq));
300 static enum ap_sm_wait ap_sm_reset(struct ap_queue *aq)
304 status = ap_rapq(aq->qid);
308 aq->sm_state = AP_SM_STATE_RESET_WAIT;
309 aq->interrupt = false;
312 aq->dev_state = AP_DEV_STATE_ERROR;
313 aq->last_err_rc = status.response_code;
316 AP_QID_CARD(aq->qid), AP_QID_QUEUE(aq->qid));
323 * @aq: pointer to the AP queue
327 static enum ap_sm_wait ap_sm_reset_wait(struct ap_queue *aq)
332 if (aq->queue_count > 0 && aq->reply)
334 status = ap_sm_recv(aq);
337 status = ap_tapq(aq->qid, NULL);
342 if (lsi_ptr && ap_queue_enable_irq(aq, lsi_ptr) == 0)
343 aq->sm_state = AP_SM_STATE_SETIRQ_WAIT;
345 aq->sm_state = (aq->queue_count > 0) ?
355 aq->dev_state = AP_DEV_STATE_ERROR;
356 aq->last_err_rc = status.response_code;
359 AP_QID_CARD(aq->qid), AP_QID_QUEUE(aq->qid));
366 * @aq: pointer to the AP queue
370 static enum ap_sm_wait ap_sm_setirq_wait(struct ap_queue *aq)
374 if (aq->queue_count > 0 && aq->reply)
376 status = ap_sm_recv(aq);
379 status = ap_tapq(aq->qid, NULL);
383 aq->interrupt = true;
384 aq->sm_state = (aq->queue_count > 0) ?
390 if (aq->queue_count > 0)
396 aq->dev_state = AP_DEV_STATE_ERROR;
397 aq->last_err_rc = status.response_code;
400 AP_QID_CARD(aq->qid), AP_QID_QUEUE(aq->qid));
435 enum ap_sm_wait ap_sm_event(struct ap_queue *aq, enum ap_sm_event event)
437 if (aq->dev_state > AP_DEV_STATE_UNINITIATED)
438 return ap_jumptable[aq->sm_state][event](aq);
443 enum ap_sm_wait ap_sm_event_loop(struct ap_queue *aq, enum ap_sm_event event)
447 while ((wait = ap_sm_event(aq, event)) == AP_SM_WAIT_AGAIN)
459 struct ap_queue *aq = to_ap_queue(dev);
463 spin_lock_bh(&aq->lock);
464 if (aq->dev_state > AP_DEV_STATE_UNINITIATED) {
465 req_cnt = aq->total_request_count;
468 spin_unlock_bh(&aq->lock);
480 struct ap_queue *aq = to_ap_queue(dev);
482 spin_lock_bh(&aq->lock);
483 aq->total_request_count = 0;
484 spin_unlock_bh(&aq->lock);
494 struct ap_queue *aq = to_ap_queue(dev);
497 spin_lock_bh(&aq->lock);
498 if (aq->dev_state > AP_DEV_STATE_UNINITIATED)
499 reqq_cnt = aq->requestq_count;
500 spin_unlock_bh(&aq->lock);
509 struct ap_queue *aq = to_ap_queue(dev);
512 spin_lock_bh(&aq->lock);
513 if (aq->dev_state > AP_DEV_STATE_UNINITIATED)
514 penq_cnt = aq->pendingq_count;
515 spin_unlock_bh(&aq->lock);
524 struct ap_queue *aq = to_ap_queue(dev);
527 spin_lock_bh(&aq->lock);
528 switch (aq->sm_state) {
540 spin_unlock_bh(&aq->lock);
548 struct ap_queue *aq = to_ap_queue(dev);
550 spin_lock_bh(&aq->lock);
551 __ap_flush_queue(aq);
552 aq->sm_state = AP_SM_STATE_RESET_START;
553 ap_wait(ap_sm_event(aq, AP_SM_EVENT_POLL));
554 spin_unlock_bh(&aq->lock);
557 AP_QID_CARD(aq->qid), AP_QID_QUEUE(aq->qid));
567 struct ap_queue *aq = to_ap_queue(dev);
570 spin_lock_bh(&aq->lock);
571 if (aq->sm_state == AP_SM_STATE_SETIRQ_WAIT)
573 else if (aq->interrupt)
577 spin_unlock_bh(&aq->lock);
586 struct ap_queue *aq = to_ap_queue(dev);
589 spin_lock_bh(&aq->lock);
590 rc = scnprintf(buf, PAGE_SIZE, "%d\n", aq->config ? 1 : 0);
591 spin_unlock_bh(&aq->lock);
601 struct ap_queue *aq = to_ap_queue(dev);
604 spin_lock_bh(&aq->lock);
606 switch (aq->dev_state) {
623 if (aq->dev_state) {
624 switch (aq->sm_state) {
654 spin_unlock_bh(&aq->lock);
663 struct ap_queue *aq = to_ap_queue(dev);
666 spin_lock_bh(&aq->lock);
667 rc = aq->last_err_rc;
668 spin_unlock_bh(&aq->lock);
734 struct ap_queue *aq = to_ap_queue(dev);
737 hash_del(&aq->hnode);
740 kfree(aq);
745 struct ap_queue *aq;
747 aq = kzalloc(sizeof(*aq), GFP_KERNEL);
748 if (!aq)
750 aq->ap_dev.device.release = ap_queue_device_release;
751 aq->ap_dev.device.type = &ap_queue_type;
752 aq->ap_dev.device_type = device_type;
753 aq->qid = qid;
754 aq->interrupt = false;
755 spin_lock_init(&aq->lock);
756 INIT_LIST_HEAD(&aq->pendingq);
757 INIT_LIST_HEAD(&aq->requestq);
758 timer_setup(&aq->timeout, ap_request_timeout, 0);
760 return aq;
763 void ap_queue_init_reply(struct ap_queue *aq, struct ap_message *reply)
765 aq->reply = reply;
767 spin_lock_bh(&aq->lock);
768 ap_wait(ap_sm_event(aq, AP_SM_EVENT_POLL));
769 spin_unlock_bh(&aq->lock);
775 * @aq: The AP device to queue the message to
778 int ap_queue_message(struct ap_queue *aq, struct ap_message *ap_msg)
785 spin_lock_bh(&aq->lock);
788 if (aq->dev_state == AP_DEV_STATE_OPERATING) {
789 list_add_tail(&ap_msg->list, &aq->requestq);
790 aq->requestq_count++;
791 aq->total_request_count++;
792 atomic64_inc(&aq->card->total_request_count);
797 ap_wait(ap_sm_event_loop(aq, AP_SM_EVENT_POLL));
799 spin_unlock_bh(&aq->lock);
807 * @aq: The AP device that has the message queued
815 void ap_cancel_message(struct ap_queue *aq, struct ap_message *ap_msg)
819 spin_lock_bh(&aq->lock);
821 list_for_each_entry(tmp, &aq->pendingq, list)
823 aq->pendingq_count--;
826 aq->requestq_count--;
830 spin_unlock_bh(&aq->lock);
836 * @aq: Pointer to the AP queue
840 static void __ap_flush_queue(struct ap_queue *aq)
844 list_for_each_entry_safe(ap_msg, next, &aq->pendingq, list) {
846 aq->pendingq_count--;
848 ap_msg->receive(aq, ap_msg, NULL);
850 list_for_each_entry_safe(ap_msg, next, &aq->requestq, list) {
852 aq->requestq_count--;
854 ap_msg->receive(aq, ap_msg, NULL);
856 aq->queue_count = 0;
859 void ap_flush_queue(struct ap_queue *aq)
861 spin_lock_bh(&aq->lock);
862 __ap_flush_queue(aq);
863 spin_unlock_bh(&aq->lock);
867 void ap_queue_prepare_remove(struct ap_queue *aq)
869 spin_lock_bh(&aq->lock);
871 __ap_flush_queue(aq);
873 aq->dev_state = AP_DEV_STATE_SHUTDOWN;
874 spin_unlock_bh(&aq->lock);
875 del_timer_sync(&aq->timeout);
878 void ap_queue_remove(struct ap_queue *aq)
886 spin_lock_bh(&aq->lock);
887 ap_zapq(aq->qid);
888 aq->dev_state = AP_DEV_STATE_UNINITIATED;
889 spin_unlock_bh(&aq->lock);
892 void ap_queue_init_state(struct ap_queue *aq)
894 spin_lock_bh(&aq->lock);
895 aq->dev_state = AP_DEV_STATE_OPERATING;
896 aq->sm_state = AP_SM_STATE_RESET_START;
897 ap_wait(ap_sm_event(aq, AP_SM_EVENT_POLL));
898 spin_unlock_bh(&aq->lock);