Lines Matching refs:queue
82 static int queue_empty(struct ddcb_queue *queue) in queue_empty() argument
84 return queue->ddcb_next == queue->ddcb_act; in queue_empty()
87 static int queue_enqueued_ddcbs(struct ddcb_queue *queue) in queue_enqueued_ddcbs() argument
89 if (queue->ddcb_next >= queue->ddcb_act) in queue_enqueued_ddcbs()
90 return queue->ddcb_next - queue->ddcb_act; in queue_enqueued_ddcbs()
92 return queue->ddcb_max - (queue->ddcb_act - queue->ddcb_next); in queue_enqueued_ddcbs()
95 static int queue_free_ddcbs(struct ddcb_queue *queue) in queue_free_ddcbs() argument
97 int free_ddcbs = queue->ddcb_max - queue_enqueued_ddcbs(queue) - 1; in queue_free_ddcbs()
163 static void print_ddcb_info(struct genwqe_dev *cd, struct ddcb_queue *queue) in print_ddcb_info() argument
174 cd->card_idx, queue->ddcb_act, queue->ddcb_next); in print_ddcb_info()
176 pddcb = queue->ddcb_vaddr; in print_ddcb_info()
177 for (i = 0; i < queue->ddcb_max; i++) { in print_ddcb_info()
180 i == queue->ddcb_act ? '>' : ' ', in print_ddcb_info()
265 static int enqueue_ddcb(struct genwqe_dev *cd, struct ddcb_queue *queue, in enqueue_ddcb() argument
282 prev_no = (ddcb_no == 0) ? queue->ddcb_max - 1 : ddcb_no - 1; in enqueue_ddcb()
283 prev_ddcb = &queue->ddcb_vaddr[prev_no]; in enqueue_ddcb()
312 __genwqe_writeq(cd, queue->IO_QUEUE_OFFSET, num); /* start queue */ in enqueue_ddcb()
332 struct ddcb_queue *queue = req->queue; in copy_ddcb_results() local
333 struct ddcb *pddcb = &queue->ddcb_vaddr[req->num]; in copy_ddcb_results()
348 queue->ddcb_max - 1 : ddcb_no - 1; in copy_ddcb_results()
349 struct ddcb *prev_pddcb = &queue->ddcb_vaddr[prev_no]; in copy_ddcb_results()
366 struct ddcb_queue *queue) in genwqe_check_ddcb_queue() argument
372 spin_lock_irqsave(&queue->ddcb_lock, flags); in genwqe_check_ddcb_queue()
375 while (!queue_empty(queue) && (ddcbs_finished < queue->ddcb_max)) { in genwqe_check_ddcb_queue()
381 pddcb = &queue->ddcb_vaddr[queue->ddcb_act]; in genwqe_check_ddcb_queue()
390 req = queue->ddcb_req[queue->ddcb_act]; in genwqe_check_ddcb_queue()
408 u64 ddcb_offs = (u64)pddcb - (u64)queue->ddcb_vaddr; in genwqe_check_ddcb_queue()
410 errcnts = __genwqe_readq(cd, queue->IO_QUEUE_ERRCNTS); in genwqe_check_ddcb_queue()
411 status = __genwqe_readq(cd, queue->IO_QUEUE_STATUS); in genwqe_check_ddcb_queue()
417 queue->ddcb_daddr + ddcb_offs); in genwqe_check_ddcb_queue()
420 copy_ddcb_results(req, queue->ddcb_act); in genwqe_check_ddcb_queue()
421 queue->ddcb_req[queue->ddcb_act] = NULL; /* take from queue */ in genwqe_check_ddcb_queue()
442 queue->ddcbs_completed++; in genwqe_check_ddcb_queue()
443 queue->ddcbs_in_flight--; in genwqe_check_ddcb_queue()
447 wake_up_interruptible(&queue->ddcb_waitqs[queue->ddcb_act]); in genwqe_check_ddcb_queue()
448 wake_up_interruptible(&queue->busy_waitq); in genwqe_check_ddcb_queue()
451 queue->ddcb_act = (queue->ddcb_act + 1) % queue->ddcb_max; in genwqe_check_ddcb_queue()
456 spin_unlock_irqrestore(&queue->ddcb_lock, flags); in genwqe_check_ddcb_queue()
481 struct ddcb_queue *queue; in __genwqe_wait_ddcb() local
487 queue = req->queue; in __genwqe_wait_ddcb()
488 if (queue == NULL) in __genwqe_wait_ddcb()
492 if (ddcb_no >= queue->ddcb_max) in __genwqe_wait_ddcb()
495 rc = wait_event_interruptible_timeout(queue->ddcb_waitqs[ddcb_no], in __genwqe_wait_ddcb()
506 struct ddcb_queue *queue = req->queue; in __genwqe_wait_ddcb() local
514 genwqe_check_ddcb_queue(cd, req->queue); in __genwqe_wait_ddcb()
524 __genwqe_readq(cd, queue->IO_QUEUE_STATUS)); in __genwqe_wait_ddcb()
526 pddcb = &queue->ddcb_vaddr[req->num]; in __genwqe_wait_ddcb()
529 print_ddcb_info(cd, req->queue); in __genwqe_wait_ddcb()
568 struct ddcb_queue *queue, in get_next_ddcb() argument
574 if (queue_free_ddcbs(queue) == 0) /* queue is full */ in get_next_ddcb()
578 pddcb = &queue->ddcb_vaddr[queue->ddcb_next]; in get_next_ddcb()
585 *num = queue->ddcb_next; /* internal DDCB number */ in get_next_ddcb()
586 queue->ddcb_next = (queue->ddcb_next + 1) % queue->ddcb_max; in get_next_ddcb()
601 pddcb->seqnum_16 = cpu_to_be16(queue->ddcb_seq++); in get_next_ddcb()
625 struct ddcb_queue *queue = req->queue; in __genwqe_purge_ddcb() local
638 pddcb = &queue->ddcb_vaddr[req->num]; in __genwqe_purge_ddcb()
642 spin_lock_irqsave(&queue->ddcb_lock, flags); in __genwqe_purge_ddcb()
665 spin_unlock_irqrestore(&queue->ddcb_lock, flags); in __genwqe_purge_ddcb()
681 queue->ddcbs_in_flight--; in __genwqe_purge_ddcb()
682 queue->ddcb_req[req->num] = NULL; /* delete from array */ in __genwqe_purge_ddcb()
697 (queue->ddcb_act == req->num)) { in __genwqe_purge_ddcb()
698 queue->ddcb_act = ((queue->ddcb_act + 1) % in __genwqe_purge_ddcb()
699 queue->ddcb_max); in __genwqe_purge_ddcb()
702 spin_unlock_irqrestore(&queue->ddcb_lock, flags); in __genwqe_purge_ddcb()
710 queue_status = __genwqe_readq(cd, queue->IO_QUEUE_STATUS); in __genwqe_purge_ddcb()
720 print_ddcb_info(cd, req->queue); in __genwqe_purge_ddcb()
759 struct ddcb_queue *queue; in __genwqe_enqueue_ddcb() local
772 queue = req->queue = &cd->queue; in __genwqe_enqueue_ddcb()
778 genwqe_check_ddcb_queue(cd, queue); in __genwqe_enqueue_ddcb()
785 spin_lock_irqsave(&queue->ddcb_lock, flags); in __genwqe_enqueue_ddcb()
787 pddcb = get_next_ddcb(cd, queue, &req->num); /* get ptr and num */ in __genwqe_enqueue_ddcb()
791 spin_unlock_irqrestore(&queue->ddcb_lock, flags); in __genwqe_enqueue_ddcb()
794 queue->return_on_busy++; in __genwqe_enqueue_ddcb()
798 queue->wait_on_busy++; in __genwqe_enqueue_ddcb()
799 rc = wait_event_interruptible(queue->busy_waitq, in __genwqe_enqueue_ddcb()
800 queue_free_ddcbs(queue) != 0); in __genwqe_enqueue_ddcb()
809 if (queue->ddcb_req[req->num] != NULL) { in __genwqe_enqueue_ddcb()
810 spin_unlock_irqrestore(&queue->ddcb_lock, flags); in __genwqe_enqueue_ddcb()
818 queue->ddcb_req[req->num] = req; in __genwqe_enqueue_ddcb()
892 enqueue_ddcb(cd, queue, pddcb, req->num); in __genwqe_enqueue_ddcb()
893 queue->ddcbs_in_flight++; in __genwqe_enqueue_ddcb()
895 if (queue->ddcbs_in_flight > queue->ddcbs_max_in_flight) in __genwqe_enqueue_ddcb()
896 queue->ddcbs_max_in_flight = queue->ddcbs_in_flight; in __genwqe_enqueue_ddcb()
899 spin_unlock_irqrestore(&queue->ddcb_lock, flags); in __genwqe_enqueue_ddcb()
981 struct ddcb_queue *queue = &cd->queue; in genwqe_next_ddcb_ready() local
983 spin_lock_irqsave(&queue->ddcb_lock, flags); in genwqe_next_ddcb_ready()
985 if (queue_empty(queue)) { /* empty queue */ in genwqe_next_ddcb_ready()
986 spin_unlock_irqrestore(&queue->ddcb_lock, flags); in genwqe_next_ddcb_ready()
990 pddcb = &queue->ddcb_vaddr[queue->ddcb_act]; in genwqe_next_ddcb_ready()
992 spin_unlock_irqrestore(&queue->ddcb_lock, flags); in genwqe_next_ddcb_ready()
996 spin_unlock_irqrestore(&queue->ddcb_lock, flags); in genwqe_next_ddcb_ready()
1012 struct ddcb_queue *queue = &cd->queue; in genwqe_ddcbs_in_flight() local
1014 spin_lock_irqsave(&queue->ddcb_lock, flags); in genwqe_ddcbs_in_flight()
1015 ddcbs_in_flight += queue->ddcbs_in_flight; in genwqe_ddcbs_in_flight()
1016 spin_unlock_irqrestore(&queue->ddcb_lock, flags); in genwqe_ddcbs_in_flight()
1021 static int setup_ddcb_queue(struct genwqe_dev *cd, struct ddcb_queue *queue) in setup_ddcb_queue() argument
1034 queue->ddcbs_in_flight = 0; /* statistics */ in setup_ddcb_queue()
1035 queue->ddcbs_max_in_flight = 0; in setup_ddcb_queue()
1036 queue->ddcbs_completed = 0; in setup_ddcb_queue()
1037 queue->return_on_busy = 0; in setup_ddcb_queue()
1038 queue->wait_on_busy = 0; in setup_ddcb_queue()
1040 queue->ddcb_seq = 0x100; /* start sequence number */ in setup_ddcb_queue()
1041 queue->ddcb_max = GENWQE_DDCB_MAX; in setup_ddcb_queue()
1042 queue->ddcb_vaddr = __genwqe_alloc_consistent(cd, queue_size, in setup_ddcb_queue()
1043 &queue->ddcb_daddr); in setup_ddcb_queue()
1044 if (queue->ddcb_vaddr == NULL) { in setup_ddcb_queue()
1049 queue->ddcb_req = kcalloc(queue->ddcb_max, sizeof(struct ddcb_requ *), in setup_ddcb_queue()
1051 if (!queue->ddcb_req) { in setup_ddcb_queue()
1056 queue->ddcb_waitqs = kcalloc(queue->ddcb_max, in setup_ddcb_queue()
1059 if (!queue->ddcb_waitqs) { in setup_ddcb_queue()
1064 for (i = 0; i < queue->ddcb_max; i++) { in setup_ddcb_queue()
1065 pddcb = &queue->ddcb_vaddr[i]; /* DDCBs */ in setup_ddcb_queue()
1069 queue->ddcb_req[i] = NULL; /* requests */ in setup_ddcb_queue()
1070 init_waitqueue_head(&queue->ddcb_waitqs[i]); /* waitqueues */ in setup_ddcb_queue()
1073 queue->ddcb_act = 0; in setup_ddcb_queue()
1074 queue->ddcb_next = 0; /* queue is empty */ in setup_ddcb_queue()
1076 spin_lock_init(&queue->ddcb_lock); in setup_ddcb_queue()
1077 init_waitqueue_head(&queue->busy_waitq); in setup_ddcb_queue()
1079 val64 = ((u64)(queue->ddcb_max - 1) << 8); /* lastptr */ in setup_ddcb_queue()
1080 __genwqe_writeq(cd, queue->IO_QUEUE_CONFIG, 0x07); /* iCRC/vCRC */ in setup_ddcb_queue()
1081 __genwqe_writeq(cd, queue->IO_QUEUE_SEGMENT, queue->ddcb_daddr); in setup_ddcb_queue()
1082 __genwqe_writeq(cd, queue->IO_QUEUE_INITSQN, queue->ddcb_seq); in setup_ddcb_queue()
1083 __genwqe_writeq(cd, queue->IO_QUEUE_WRAP, val64); in setup_ddcb_queue()
1087 kfree(queue->ddcb_req); in setup_ddcb_queue()
1088 queue->ddcb_req = NULL; in setup_ddcb_queue()
1090 __genwqe_free_consistent(cd, queue_size, queue->ddcb_vaddr, in setup_ddcb_queue()
1091 queue->ddcb_daddr); in setup_ddcb_queue()
1092 queue->ddcb_vaddr = NULL; in setup_ddcb_queue()
1093 queue->ddcb_daddr = 0ull; in setup_ddcb_queue()
1098 static int ddcb_queue_initialized(struct ddcb_queue *queue) in ddcb_queue_initialized() argument
1100 return queue->ddcb_vaddr != NULL; in ddcb_queue_initialized()
1103 static void free_ddcb_queue(struct genwqe_dev *cd, struct ddcb_queue *queue) in free_ddcb_queue() argument
1107 queue_size = roundup(queue->ddcb_max * sizeof(struct ddcb), PAGE_SIZE); in free_ddcb_queue()
1109 kfree(queue->ddcb_req); in free_ddcb_queue()
1110 queue->ddcb_req = NULL; in free_ddcb_queue()
1112 if (queue->ddcb_vaddr) { in free_ddcb_queue()
1113 __genwqe_free_consistent(cd, queue_size, queue->ddcb_vaddr, in free_ddcb_queue()
1114 queue->ddcb_daddr); in free_ddcb_queue()
1115 queue->ddcb_vaddr = NULL; in free_ddcb_queue()
1116 queue->ddcb_daddr = 0ull; in free_ddcb_queue()
1195 genwqe_check_ddcb_queue(cd, &cd->queue); in genwqe_card_thread()
1231 struct ddcb_queue *queue; in genwqe_setup_service_layer() local
1244 queue = &cd->queue; in genwqe_setup_service_layer()
1245 queue->IO_QUEUE_CONFIG = IO_SLC_QUEUE_CONFIG; in genwqe_setup_service_layer()
1246 queue->IO_QUEUE_STATUS = IO_SLC_QUEUE_STATUS; in genwqe_setup_service_layer()
1247 queue->IO_QUEUE_SEGMENT = IO_SLC_QUEUE_SEGMENT; in genwqe_setup_service_layer()
1248 queue->IO_QUEUE_INITSQN = IO_SLC_QUEUE_INITSQN; in genwqe_setup_service_layer()
1249 queue->IO_QUEUE_OFFSET = IO_SLC_QUEUE_OFFSET; in genwqe_setup_service_layer()
1250 queue->IO_QUEUE_WRAP = IO_SLC_QUEUE_WRAP; in genwqe_setup_service_layer()
1251 queue->IO_QUEUE_WTIME = IO_SLC_QUEUE_WTIME; in genwqe_setup_service_layer()
1252 queue->IO_QUEUE_ERRCNTS = IO_SLC_QUEUE_ERRCNTS; in genwqe_setup_service_layer()
1253 queue->IO_QUEUE_LRW = IO_SLC_QUEUE_LRW; in genwqe_setup_service_layer()
1255 rc = setup_ddcb_queue(cd, queue); in genwqe_setup_service_layer()
1303 free_ddcb_queue(cd, queue); in genwqe_setup_service_layer()
1320 struct ddcb_queue *queue = &cd->queue; in queue_wake_up_all() local
1322 spin_lock_irqsave(&queue->ddcb_lock, flags); in queue_wake_up_all()
1324 for (i = 0; i < queue->ddcb_max; i++) in queue_wake_up_all()
1325 wake_up_interruptible(&queue->ddcb_waitqs[queue->ddcb_act]); in queue_wake_up_all()
1327 wake_up_interruptible(&queue->busy_waitq); in queue_wake_up_all()
1328 spin_unlock_irqrestore(&queue->ddcb_lock, flags); in queue_wake_up_all()
1347 struct ddcb_queue *queue = &cd->queue; in genwqe_finish_queue() local
1349 if (!ddcb_queue_initialized(queue)) in genwqe_finish_queue()
1398 if (!ddcb_queue_initialized(&cd->queue)) in genwqe_release_service_layer()
1409 free_ddcb_queue(cd, &cd->queue); in genwqe_release_service_layer()