Lines Matching refs:ctrl

198 		q_depth += atomic_read(&card->ctrl[i].stats.hw_q_depth);  in dma_intr_coal_auto_tune()
207 static void rsxx_free_dma(struct rsxx_dma_ctrl *ctrl, struct rsxx_dma *dma) in rsxx_free_dma() argument
210 if (!dma_mapping_error(&ctrl->card->dev->dev, dma->dma_addr)) { in rsxx_free_dma()
211 dma_unmap_page(&ctrl->card->dev->dev, dma->dma_addr, in rsxx_free_dma()
222 static void rsxx_complete_dma(struct rsxx_dma_ctrl *ctrl, in rsxx_complete_dma() argument
227 ctrl->stats.dma_sw_err++; in rsxx_complete_dma()
229 ctrl->stats.dma_hw_fault++; in rsxx_complete_dma()
231 ctrl->stats.dma_cancelled++; in rsxx_complete_dma()
234 dma->cb(ctrl->card, dma->cb_data, status ? 1 : 0); in rsxx_complete_dma()
236 rsxx_free_dma(ctrl, dma); in rsxx_complete_dma()
239 int rsxx_cleanup_dma_queue(struct rsxx_dma_ctrl *ctrl, in rsxx_cleanup_dma_queue() argument
249 rsxx_complete_dma(ctrl, dma, DMA_CANCELLED); in rsxx_cleanup_dma_queue()
251 rsxx_free_dma(ctrl, dma); in rsxx_cleanup_dma_queue()
258 static void rsxx_requeue_dma(struct rsxx_dma_ctrl *ctrl, in rsxx_requeue_dma() argument
265 spin_lock_bh(&ctrl->queue_lock); in rsxx_requeue_dma()
266 ctrl->stats.sw_q_depth++; in rsxx_requeue_dma()
267 list_add(&dma->list, &ctrl->queue); in rsxx_requeue_dma()
268 spin_unlock_bh(&ctrl->queue_lock); in rsxx_requeue_dma()
271 static void rsxx_handle_dma_error(struct rsxx_dma_ctrl *ctrl, in rsxx_handle_dma_error() argument
278 dev_dbg(CARD_TO_DEV(ctrl->card), in rsxx_handle_dma_error()
283 ctrl->stats.crc_errors++; in rsxx_handle_dma_error()
285 ctrl->stats.hard_errors++; in rsxx_handle_dma_error()
287 ctrl->stats.soft_errors++; in rsxx_handle_dma_error()
292 if (ctrl->card->scrub_hard) { in rsxx_handle_dma_error()
295 ctrl->stats.reads_retried++; in rsxx_handle_dma_error()
298 ctrl->stats.reads_failed++; in rsxx_handle_dma_error()
302 ctrl->stats.reads_failed++; in rsxx_handle_dma_error()
310 ctrl->stats.reads_failed++; in rsxx_handle_dma_error()
316 ctrl->stats.writes_failed++; in rsxx_handle_dma_error()
321 ctrl->stats.discards_failed++; in rsxx_handle_dma_error()
325 dev_err(CARD_TO_DEV(ctrl->card), in rsxx_handle_dma_error()
335 rsxx_requeue_dma(ctrl, dma); in rsxx_handle_dma_error()
337 rsxx_complete_dma(ctrl, dma, status); in rsxx_handle_dma_error()
342 struct rsxx_dma_ctrl *ctrl = from_timer(ctrl, t, activity_timer); in dma_engine_stalled() local
345 if (atomic_read(&ctrl->stats.hw_q_depth) == 0 || in dma_engine_stalled()
346 unlikely(ctrl->card->eeh_state)) in dma_engine_stalled()
349 if (ctrl->cmd.idx != ioread32(ctrl->regmap + SW_CMD_IDX)) { in dma_engine_stalled()
354 dev_warn(CARD_TO_DEV(ctrl->card), in dma_engine_stalled()
356 iowrite32(ctrl->cmd.idx, ctrl->regmap + SW_CMD_IDX); in dma_engine_stalled()
357 mod_timer(&ctrl->activity_timer, in dma_engine_stalled()
360 dev_warn(CARD_TO_DEV(ctrl->card), in dma_engine_stalled()
362 ctrl->id); in dma_engine_stalled()
363 ctrl->card->dma_fault = 1; in dma_engine_stalled()
366 spin_lock(&ctrl->queue_lock); in dma_engine_stalled()
367 cnt = rsxx_cleanup_dma_queue(ctrl, &ctrl->queue, COMPLETE_DMA); in dma_engine_stalled()
368 spin_unlock(&ctrl->queue_lock); in dma_engine_stalled()
370 cnt += rsxx_dma_cancel(ctrl); in dma_engine_stalled()
373 dev_info(CARD_TO_DEV(ctrl->card), in dma_engine_stalled()
375 cnt, ctrl->id); in dma_engine_stalled()
379 static void rsxx_issue_dmas(struct rsxx_dma_ctrl *ctrl) in rsxx_issue_dmas() argument
387 hw_cmd_buf = ctrl->cmd.buf; in rsxx_issue_dmas()
389 if (unlikely(ctrl->card->halt) || in rsxx_issue_dmas()
390 unlikely(ctrl->card->eeh_state)) in rsxx_issue_dmas()
394 spin_lock_bh(&ctrl->queue_lock); in rsxx_issue_dmas()
395 if (list_empty(&ctrl->queue)) { in rsxx_issue_dmas()
396 spin_unlock_bh(&ctrl->queue_lock); in rsxx_issue_dmas()
399 spin_unlock_bh(&ctrl->queue_lock); in rsxx_issue_dmas()
401 tag = pop_tracker(ctrl->trackers); in rsxx_issue_dmas()
405 spin_lock_bh(&ctrl->queue_lock); in rsxx_issue_dmas()
406 dma = list_entry(ctrl->queue.next, struct rsxx_dma, list); in rsxx_issue_dmas()
408 ctrl->stats.sw_q_depth--; in rsxx_issue_dmas()
409 spin_unlock_bh(&ctrl->queue_lock); in rsxx_issue_dmas()
416 if (unlikely(ctrl->card->dma_fault)) { in rsxx_issue_dmas()
417 push_tracker(ctrl->trackers, tag); in rsxx_issue_dmas()
418 rsxx_complete_dma(ctrl, dma, DMA_CANCELLED); in rsxx_issue_dmas()
438 dma->dma_addr = dma_map_page(&ctrl->card->dev->dev, dma->page, in rsxx_issue_dmas()
440 if (dma_mapping_error(&ctrl->card->dev->dev, dma->dma_addr)) { in rsxx_issue_dmas()
441 push_tracker(ctrl->trackers, tag); in rsxx_issue_dmas()
442 rsxx_complete_dma(ctrl, dma, DMA_CANCELLED); in rsxx_issue_dmas()
447 set_tracker_dma(ctrl->trackers, tag, dma); in rsxx_issue_dmas()
448 hw_cmd_buf[ctrl->cmd.idx].command = dma->cmd; in rsxx_issue_dmas()
449 hw_cmd_buf[ctrl->cmd.idx].tag = tag; in rsxx_issue_dmas()
450 hw_cmd_buf[ctrl->cmd.idx]._rsvd = 0; in rsxx_issue_dmas()
451 hw_cmd_buf[ctrl->cmd.idx].sub_page = in rsxx_issue_dmas()
455 hw_cmd_buf[ctrl->cmd.idx].device_addr = in rsxx_issue_dmas()
458 hw_cmd_buf[ctrl->cmd.idx].host_addr = in rsxx_issue_dmas()
461 dev_dbg(CARD_TO_DEV(ctrl->card), in rsxx_issue_dmas()
463 ctrl->id, dma->laddr, tag, ctrl->cmd.idx); in rsxx_issue_dmas()
465 ctrl->cmd.idx = (ctrl->cmd.idx + 1) & RSXX_CS_IDX_MASK; in rsxx_issue_dmas()
469 ctrl->stats.writes_issued++; in rsxx_issue_dmas()
471 ctrl->stats.discards_issued++; in rsxx_issue_dmas()
473 ctrl->stats.reads_issued++; in rsxx_issue_dmas()
478 atomic_add(cmds_pending, &ctrl->stats.hw_q_depth); in rsxx_issue_dmas()
479 mod_timer(&ctrl->activity_timer, in rsxx_issue_dmas()
482 if (unlikely(ctrl->card->eeh_state)) { in rsxx_issue_dmas()
483 del_timer_sync(&ctrl->activity_timer); in rsxx_issue_dmas()
487 iowrite32(ctrl->cmd.idx, ctrl->regmap + SW_CMD_IDX); in rsxx_issue_dmas()
491 static void rsxx_dma_done(struct rsxx_dma_ctrl *ctrl) in rsxx_dma_done() argument
500 hw_st_buf = ctrl->status.buf; in rsxx_dma_done()
502 if (unlikely(ctrl->card->halt) || in rsxx_dma_done()
503 unlikely(ctrl->card->dma_fault) || in rsxx_dma_done()
504 unlikely(ctrl->card->eeh_state)) in rsxx_dma_done()
507 count = le16_to_cpu(hw_st_buf[ctrl->status.idx].count); in rsxx_dma_done()
509 while (count == ctrl->e_cnt) { in rsxx_dma_done()
519 status = hw_st_buf[ctrl->status.idx].status; in rsxx_dma_done()
520 tag = hw_st_buf[ctrl->status.idx].tag; in rsxx_dma_done()
522 dma = get_tracker_dma(ctrl->trackers, tag); in rsxx_dma_done()
524 spin_lock_irqsave(&ctrl->card->irq_lock, flags); in rsxx_dma_done()
525 rsxx_disable_ier(ctrl->card, CR_INTR_DMA_ALL); in rsxx_dma_done()
526 spin_unlock_irqrestore(&ctrl->card->irq_lock, flags); in rsxx_dma_done()
528 dev_err(CARD_TO_DEV(ctrl->card), in rsxx_dma_done()
531 tag, ctrl->status.idx, ctrl->id); in rsxx_dma_done()
535 dev_dbg(CARD_TO_DEV(ctrl->card), in rsxx_dma_done()
538 ctrl->id, dma->laddr, tag, status, count, in rsxx_dma_done()
539 ctrl->status.idx); in rsxx_dma_done()
541 atomic_dec(&ctrl->stats.hw_q_depth); in rsxx_dma_done()
543 mod_timer(&ctrl->activity_timer, in rsxx_dma_done()
547 rsxx_handle_dma_error(ctrl, dma, status); in rsxx_dma_done()
549 rsxx_complete_dma(ctrl, dma, 0); in rsxx_dma_done()
551 push_tracker(ctrl->trackers, tag); in rsxx_dma_done()
553 ctrl->status.idx = (ctrl->status.idx + 1) & in rsxx_dma_done()
555 ctrl->e_cnt++; in rsxx_dma_done()
557 count = le16_to_cpu(hw_st_buf[ctrl->status.idx].count); in rsxx_dma_done()
560 dma_intr_coal_auto_tune(ctrl->card); in rsxx_dma_done()
562 if (atomic_read(&ctrl->stats.hw_q_depth) == 0) in rsxx_dma_done()
563 del_timer_sync(&ctrl->activity_timer); in rsxx_dma_done()
565 spin_lock_irqsave(&ctrl->card->irq_lock, flags); in rsxx_dma_done()
566 rsxx_enable_ier(ctrl->card, CR_INTR_DMA(ctrl->id)); in rsxx_dma_done()
567 spin_unlock_irqrestore(&ctrl->card->irq_lock, flags); in rsxx_dma_done()
569 spin_lock_bh(&ctrl->queue_lock); in rsxx_dma_done()
570 if (ctrl->stats.sw_q_depth) in rsxx_dma_done()
571 queue_work(ctrl->issue_wq, &ctrl->issue_dma_work); in rsxx_dma_done()
572 spin_unlock_bh(&ctrl->queue_lock); in rsxx_dma_done()
577 struct rsxx_dma_ctrl *ctrl; in rsxx_schedule_issue() local
579 ctrl = container_of(work, struct rsxx_dma_ctrl, issue_dma_work); in rsxx_schedule_issue()
581 mutex_lock(&ctrl->work_lock); in rsxx_schedule_issue()
582 rsxx_issue_dmas(ctrl); in rsxx_schedule_issue()
583 mutex_unlock(&ctrl->work_lock); in rsxx_schedule_issue()
588 struct rsxx_dma_ctrl *ctrl; in rsxx_schedule_done() local
590 ctrl = container_of(work, struct rsxx_dma_ctrl, dma_done_work); in rsxx_schedule_done()
592 mutex_lock(&ctrl->work_lock); in rsxx_schedule_done()
593 rsxx_dma_done(ctrl); in rsxx_schedule_done()
594 mutex_unlock(&ctrl->work_lock); in rsxx_schedule_done()
739 spin_lock_bh(&card->ctrl[i].queue_lock); in rsxx_dma_queue_bio()
740 card->ctrl[i].stats.sw_q_depth += dma_cnt[i]; in rsxx_dma_queue_bio()
741 list_splice_tail(&dma_list[i], &card->ctrl[i].queue); in rsxx_dma_queue_bio()
742 spin_unlock_bh(&card->ctrl[i].queue_lock); in rsxx_dma_queue_bio()
744 queue_work(card->ctrl[i].issue_wq, in rsxx_dma_queue_bio()
745 &card->ctrl[i].issue_dma_work); in rsxx_dma_queue_bio()
753 rsxx_cleanup_dma_queue(&card->ctrl[i], &dma_list[i], in rsxx_dma_queue_bio()
760 int rsxx_hw_buffers_init(struct pci_dev *dev, struct rsxx_dma_ctrl *ctrl) in rsxx_hw_buffers_init() argument
762 ctrl->status.buf = dma_alloc_coherent(&dev->dev, STATUS_BUFFER_SIZE8, in rsxx_hw_buffers_init()
763 &ctrl->status.dma_addr, GFP_KERNEL); in rsxx_hw_buffers_init()
764 ctrl->cmd.buf = dma_alloc_coherent(&dev->dev, COMMAND_BUFFER_SIZE8, in rsxx_hw_buffers_init()
765 &ctrl->cmd.dma_addr, GFP_KERNEL); in rsxx_hw_buffers_init()
766 if (ctrl->status.buf == NULL || ctrl->cmd.buf == NULL) in rsxx_hw_buffers_init()
769 memset(ctrl->status.buf, 0xac, STATUS_BUFFER_SIZE8); in rsxx_hw_buffers_init()
770 iowrite32(lower_32_bits(ctrl->status.dma_addr), in rsxx_hw_buffers_init()
771 ctrl->regmap + SB_ADD_LO); in rsxx_hw_buffers_init()
772 iowrite32(upper_32_bits(ctrl->status.dma_addr), in rsxx_hw_buffers_init()
773 ctrl->regmap + SB_ADD_HI); in rsxx_hw_buffers_init()
775 memset(ctrl->cmd.buf, 0x83, COMMAND_BUFFER_SIZE8); in rsxx_hw_buffers_init()
776 iowrite32(lower_32_bits(ctrl->cmd.dma_addr), ctrl->regmap + CB_ADD_LO); in rsxx_hw_buffers_init()
777 iowrite32(upper_32_bits(ctrl->cmd.dma_addr), ctrl->regmap + CB_ADD_HI); in rsxx_hw_buffers_init()
779 ctrl->status.idx = ioread32(ctrl->regmap + HW_STATUS_CNT); in rsxx_hw_buffers_init()
780 if (ctrl->status.idx > RSXX_MAX_OUTSTANDING_CMDS) { in rsxx_hw_buffers_init()
782 ctrl->status.idx); in rsxx_hw_buffers_init()
785 iowrite32(ctrl->status.idx, ctrl->regmap + HW_STATUS_CNT); in rsxx_hw_buffers_init()
786 iowrite32(ctrl->status.idx, ctrl->regmap + SW_STATUS_CNT); in rsxx_hw_buffers_init()
788 ctrl->cmd.idx = ioread32(ctrl->regmap + HW_CMD_IDX); in rsxx_hw_buffers_init()
789 if (ctrl->cmd.idx > RSXX_MAX_OUTSTANDING_CMDS) { in rsxx_hw_buffers_init()
791 ctrl->status.idx); in rsxx_hw_buffers_init()
794 iowrite32(ctrl->cmd.idx, ctrl->regmap + HW_CMD_IDX); in rsxx_hw_buffers_init()
795 iowrite32(ctrl->cmd.idx, ctrl->regmap + SW_CMD_IDX); in rsxx_hw_buffers_init()
801 struct rsxx_dma_ctrl *ctrl) in rsxx_dma_ctrl_init() argument
806 memset(&ctrl->stats, 0, sizeof(ctrl->stats)); in rsxx_dma_ctrl_init()
808 ctrl->trackers = vmalloc(struct_size(ctrl->trackers, list, in rsxx_dma_ctrl_init()
810 if (!ctrl->trackers) in rsxx_dma_ctrl_init()
813 ctrl->trackers->head = 0; in rsxx_dma_ctrl_init()
815 ctrl->trackers->list[i].next_tag = i + 1; in rsxx_dma_ctrl_init()
816 ctrl->trackers->list[i].dma = NULL; in rsxx_dma_ctrl_init()
818 ctrl->trackers->list[RSXX_MAX_OUTSTANDING_CMDS-1].next_tag = -1; in rsxx_dma_ctrl_init()
819 spin_lock_init(&ctrl->trackers->lock); in rsxx_dma_ctrl_init()
821 spin_lock_init(&ctrl->queue_lock); in rsxx_dma_ctrl_init()
822 mutex_init(&ctrl->work_lock); in rsxx_dma_ctrl_init()
823 INIT_LIST_HEAD(&ctrl->queue); in rsxx_dma_ctrl_init()
825 timer_setup(&ctrl->activity_timer, dma_engine_stalled, 0); in rsxx_dma_ctrl_init()
827 ctrl->issue_wq = alloc_ordered_workqueue(DRIVER_NAME"_issue", 0); in rsxx_dma_ctrl_init()
828 if (!ctrl->issue_wq) in rsxx_dma_ctrl_init()
831 ctrl->done_wq = alloc_ordered_workqueue(DRIVER_NAME"_done", 0); in rsxx_dma_ctrl_init()
832 if (!ctrl->done_wq) in rsxx_dma_ctrl_init()
835 INIT_WORK(&ctrl->issue_dma_work, rsxx_schedule_issue); in rsxx_dma_ctrl_init()
836 INIT_WORK(&ctrl->dma_done_work, rsxx_schedule_done); in rsxx_dma_ctrl_init()
838 st = rsxx_hw_buffers_init(dev, ctrl); in rsxx_dma_ctrl_init()
900 card->ctrl[i].regmap = card->regmap + (i * 4096); in rsxx_dma_setup()
909 st = rsxx_dma_ctrl_init(card->dev, &card->ctrl[i]); in rsxx_dma_setup()
913 card->ctrl[i].card = card; in rsxx_dma_setup()
914 card->ctrl[i].id = i; in rsxx_dma_setup()
933 struct rsxx_dma_ctrl *ctrl = &card->ctrl[i]; in rsxx_dma_setup() local
935 if (ctrl->issue_wq) { in rsxx_dma_setup()
936 destroy_workqueue(ctrl->issue_wq); in rsxx_dma_setup()
937 ctrl->issue_wq = NULL; in rsxx_dma_setup()
940 if (ctrl->done_wq) { in rsxx_dma_setup()
941 destroy_workqueue(ctrl->done_wq); in rsxx_dma_setup()
942 ctrl->done_wq = NULL; in rsxx_dma_setup()
945 vfree(ctrl->trackers); in rsxx_dma_setup()
947 if (ctrl->status.buf) in rsxx_dma_setup()
949 ctrl->status.buf, in rsxx_dma_setup()
950 ctrl->status.dma_addr); in rsxx_dma_setup()
951 if (ctrl->cmd.buf) in rsxx_dma_setup()
953 ctrl->cmd.buf, ctrl->cmd.dma_addr); in rsxx_dma_setup()
959 int rsxx_dma_cancel(struct rsxx_dma_ctrl *ctrl) in rsxx_dma_cancel() argument
967 dma = get_tracker_dma(ctrl->trackers, i); in rsxx_dma_cancel()
969 atomic_dec(&ctrl->stats.hw_q_depth); in rsxx_dma_cancel()
970 rsxx_complete_dma(ctrl, dma, DMA_CANCELLED); in rsxx_dma_cancel()
971 push_tracker(ctrl->trackers, i); in rsxx_dma_cancel()
981 struct rsxx_dma_ctrl *ctrl; in rsxx_dma_destroy() local
985 ctrl = &card->ctrl[i]; in rsxx_dma_destroy()
987 if (ctrl->issue_wq) { in rsxx_dma_destroy()
988 destroy_workqueue(ctrl->issue_wq); in rsxx_dma_destroy()
989 ctrl->issue_wq = NULL; in rsxx_dma_destroy()
992 if (ctrl->done_wq) { in rsxx_dma_destroy()
993 destroy_workqueue(ctrl->done_wq); in rsxx_dma_destroy()
994 ctrl->done_wq = NULL; in rsxx_dma_destroy()
997 if (timer_pending(&ctrl->activity_timer)) in rsxx_dma_destroy()
998 del_timer_sync(&ctrl->activity_timer); in rsxx_dma_destroy()
1001 spin_lock_bh(&ctrl->queue_lock); in rsxx_dma_destroy()
1002 rsxx_cleanup_dma_queue(ctrl, &ctrl->queue, COMPLETE_DMA); in rsxx_dma_destroy()
1003 spin_unlock_bh(&ctrl->queue_lock); in rsxx_dma_destroy()
1005 rsxx_dma_cancel(ctrl); in rsxx_dma_destroy()
1007 vfree(ctrl->trackers); in rsxx_dma_destroy()
1010 ctrl->status.buf, ctrl->status.dma_addr); in rsxx_dma_destroy()
1012 ctrl->cmd.buf, ctrl->cmd.dma_addr); in rsxx_dma_destroy()
1033 dma = get_tracker_dma(card->ctrl[i].trackers, j); in rsxx_eeh_save_issued_dmas()
1038 card->ctrl[i].stats.writes_issued--; in rsxx_eeh_save_issued_dmas()
1040 card->ctrl[i].stats.discards_issued--; in rsxx_eeh_save_issued_dmas()
1042 card->ctrl[i].stats.reads_issued--; in rsxx_eeh_save_issued_dmas()
1053 push_tracker(card->ctrl[i].trackers, j); in rsxx_eeh_save_issued_dmas()
1057 spin_lock_bh(&card->ctrl[i].queue_lock); in rsxx_eeh_save_issued_dmas()
1058 list_splice(&issued_dmas[i], &card->ctrl[i].queue); in rsxx_eeh_save_issued_dmas()
1060 atomic_sub(cnt, &card->ctrl[i].stats.hw_q_depth); in rsxx_eeh_save_issued_dmas()
1061 card->ctrl[i].stats.sw_q_depth += cnt; in rsxx_eeh_save_issued_dmas()
1062 card->ctrl[i].e_cnt = 0; in rsxx_eeh_save_issued_dmas()
1063 spin_unlock_bh(&card->ctrl[i].queue_lock); in rsxx_eeh_save_issued_dmas()