Lines Matching refs:card
18 typedef void (*creg_cmd_cb)(struct rsxx_cardinfo *card,
47 static int copy_to_creg_data(struct rsxx_cardinfo *card, in copy_to_creg_data() argument
55 if (unlikely(card->eeh_state)) in copy_to_creg_data()
64 iowrite32be(data[i], card->regmap + CREG_DATA(i)); in copy_to_creg_data()
66 iowrite32(data[i], card->regmap + CREG_DATA(i)); in copy_to_creg_data()
73 static int copy_from_creg_data(struct rsxx_cardinfo *card, in copy_from_creg_data() argument
81 if (unlikely(card->eeh_state)) in copy_from_creg_data()
90 data[i] = ioread32be(card->regmap + CREG_DATA(i)); in copy_from_creg_data()
92 data[i] = ioread32(card->regmap + CREG_DATA(i)); in copy_from_creg_data()
98 static void creg_issue_cmd(struct rsxx_cardinfo *card, struct creg_cmd *cmd) in creg_issue_cmd() argument
102 if (unlikely(card->eeh_state)) in creg_issue_cmd()
105 iowrite32(cmd->addr, card->regmap + CREG_ADD); in creg_issue_cmd()
106 iowrite32(cmd->cnt8, card->regmap + CREG_CNT); in creg_issue_cmd()
110 st = copy_to_creg_data(card, cmd->cnt8, in creg_issue_cmd()
117 if (unlikely(card->eeh_state)) in creg_issue_cmd()
121 iowrite32(cmd->op, card->regmap + CREG_CMD); in creg_issue_cmd()
124 static void creg_kick_queue(struct rsxx_cardinfo *card) in creg_kick_queue() argument
126 if (card->creg_ctrl.active || list_empty(&card->creg_ctrl.queue)) in creg_kick_queue()
129 card->creg_ctrl.active = 1; in creg_kick_queue()
130 card->creg_ctrl.active_cmd = list_first_entry(&card->creg_ctrl.queue, in creg_kick_queue()
132 list_del(&card->creg_ctrl.active_cmd->list); in creg_kick_queue()
133 card->creg_ctrl.q_depth--; in creg_kick_queue()
141 mod_timer(&card->creg_ctrl.cmd_timer, in creg_kick_queue()
144 creg_issue_cmd(card, card->creg_ctrl.active_cmd); in creg_kick_queue()
147 static int creg_queue_cmd(struct rsxx_cardinfo *card, in creg_queue_cmd() argument
159 if (unlikely(card->halt)) in creg_queue_cmd()
162 if (card->creg_ctrl.reset) in creg_queue_cmd()
183 spin_lock_bh(&card->creg_ctrl.lock); in creg_queue_cmd()
184 list_add_tail(&cmd->list, &card->creg_ctrl.queue); in creg_queue_cmd()
185 card->creg_ctrl.q_depth++; in creg_queue_cmd()
186 creg_kick_queue(card); in creg_queue_cmd()
187 spin_unlock_bh(&card->creg_ctrl.lock); in creg_queue_cmd()
194 struct rsxx_cardinfo *card = from_timer(card, t, creg_ctrl.cmd_timer); in creg_cmd_timed_out() local
197 spin_lock(&card->creg_ctrl.lock); in creg_cmd_timed_out()
198 cmd = card->creg_ctrl.active_cmd; in creg_cmd_timed_out()
199 card->creg_ctrl.active_cmd = NULL; in creg_cmd_timed_out()
200 spin_unlock(&card->creg_ctrl.lock); in creg_cmd_timed_out()
203 card->creg_ctrl.creg_stats.creg_timeout++; in creg_cmd_timed_out()
204 dev_warn(CARD_TO_DEV(card), in creg_cmd_timed_out()
210 cmd->cb(card, cmd, -ETIMEDOUT); in creg_cmd_timed_out()
215 spin_lock(&card->creg_ctrl.lock); in creg_cmd_timed_out()
216 card->creg_ctrl.active = 0; in creg_cmd_timed_out()
217 creg_kick_queue(card); in creg_cmd_timed_out()
218 spin_unlock(&card->creg_ctrl.lock); in creg_cmd_timed_out()
224 struct rsxx_cardinfo *card; in creg_cmd_done() local
228 card = container_of(work, struct rsxx_cardinfo, in creg_cmd_done()
235 if (del_timer_sync(&card->creg_ctrl.cmd_timer) == 0) in creg_cmd_done()
236 card->creg_ctrl.creg_stats.failed_cancel_timer++; in creg_cmd_done()
238 spin_lock_bh(&card->creg_ctrl.lock); in creg_cmd_done()
239 cmd = card->creg_ctrl.active_cmd; in creg_cmd_done()
240 card->creg_ctrl.active_cmd = NULL; in creg_cmd_done()
241 spin_unlock_bh(&card->creg_ctrl.lock); in creg_cmd_done()
244 dev_err(CARD_TO_DEV(card), in creg_cmd_done()
249 card->creg_ctrl.creg_stats.stat = ioread32(card->regmap + CREG_STAT); in creg_cmd_done()
250 cmd->status = card->creg_ctrl.creg_stats.stat; in creg_cmd_done()
252 dev_err(CARD_TO_DEV(card), in creg_cmd_done()
266 unsigned int cnt8 = ioread32(card->regmap + CREG_CNT); in creg_cmd_done()
270 dev_err(CARD_TO_DEV(card), in creg_cmd_done()
276 dev_err(CARD_TO_DEV(card), in creg_cmd_done()
282 st = copy_from_creg_data(card, cnt8, cmd->buf, cmd->stream); in creg_cmd_done()
287 cmd->cb(card, cmd, st); in creg_cmd_done()
291 spin_lock_bh(&card->creg_ctrl.lock); in creg_cmd_done()
292 card->creg_ctrl.active = 0; in creg_cmd_done()
293 creg_kick_queue(card); in creg_cmd_done()
294 spin_unlock_bh(&card->creg_ctrl.lock); in creg_cmd_done()
297 static void creg_reset(struct rsxx_cardinfo *card) in creg_reset() argument
307 if (!mutex_trylock(&card->creg_ctrl.reset_lock)) in creg_reset()
310 card->creg_ctrl.reset = 1; in creg_reset()
311 spin_lock_irqsave(&card->irq_lock, flags); in creg_reset()
312 rsxx_disable_ier_and_isr(card, CR_INTR_CREG | CR_INTR_EVENT); in creg_reset()
313 spin_unlock_irqrestore(&card->irq_lock, flags); in creg_reset()
315 dev_warn(CARD_TO_DEV(card), in creg_reset()
319 spin_lock_bh(&card->creg_ctrl.lock); in creg_reset()
320 list_for_each_entry_safe(cmd, tmp, &card->creg_ctrl.queue, list) { in creg_reset()
322 card->creg_ctrl.q_depth--; in creg_reset()
324 cmd->cb(card, cmd, -ECANCELED); in creg_reset()
328 cmd = card->creg_ctrl.active_cmd; in creg_reset()
329 card->creg_ctrl.active_cmd = NULL; in creg_reset()
331 if (timer_pending(&card->creg_ctrl.cmd_timer)) in creg_reset()
332 del_timer_sync(&card->creg_ctrl.cmd_timer); in creg_reset()
335 cmd->cb(card, cmd, -ECANCELED); in creg_reset()
338 card->creg_ctrl.active = 0; in creg_reset()
340 spin_unlock_bh(&card->creg_ctrl.lock); in creg_reset()
342 card->creg_ctrl.reset = 0; in creg_reset()
343 spin_lock_irqsave(&card->irq_lock, flags); in creg_reset()
344 rsxx_enable_ier_and_isr(card, CR_INTR_CREG | CR_INTR_EVENT); in creg_reset()
345 spin_unlock_irqrestore(&card->irq_lock, flags); in creg_reset()
347 mutex_unlock(&card->creg_ctrl.reset_lock); in creg_reset()
357 static void creg_cmd_done_cb(struct rsxx_cardinfo *card, in creg_cmd_done_cb() argument
371 static int __issue_creg_rw(struct rsxx_cardinfo *card, in __issue_creg_rw() argument
388 st = creg_queue_cmd(card, op, addr, cnt8, buf, stream, creg_cmd_done_cb, in __issue_creg_rw()
399 card->creg_ctrl.q_depth + 20000); in __issue_creg_rw()
411 dev_crit(CARD_TO_DEV(card), in __issue_creg_rw()
413 creg_reset(card); in __issue_creg_rw()
427 ioread32(card->regmap + SCRATCH); in __issue_creg_rw()
429 dev_warn(CARD_TO_DEV(card), in __issue_creg_rw()
438 static int issue_creg_rw(struct rsxx_cardinfo *card, in issue_creg_rw() argument
455 st = __issue_creg_rw(card, op, addr, xfer, in issue_creg_rw()
469 int rsxx_creg_write(struct rsxx_cardinfo *card, in rsxx_creg_write() argument
475 return issue_creg_rw(card, addr, size8, data, byte_stream, 0); in rsxx_creg_write()
478 int rsxx_creg_read(struct rsxx_cardinfo *card, in rsxx_creg_read() argument
484 return issue_creg_rw(card, addr, size8, data, byte_stream, 1); in rsxx_creg_read()
487 int rsxx_get_card_state(struct rsxx_cardinfo *card, unsigned int *state) in rsxx_get_card_state() argument
489 return rsxx_creg_read(card, CREG_ADD_CARD_STATE, in rsxx_get_card_state()
493 int rsxx_get_card_size8(struct rsxx_cardinfo *card, u64 *size8) in rsxx_get_card_size8() argument
498 st = rsxx_creg_read(card, CREG_ADD_CARD_SIZE, in rsxx_get_card_size8()
507 int rsxx_get_num_targets(struct rsxx_cardinfo *card, in rsxx_get_num_targets() argument
510 return rsxx_creg_read(card, CREG_ADD_NUM_TARGETS, in rsxx_get_num_targets()
514 int rsxx_get_card_capabilities(struct rsxx_cardinfo *card, in rsxx_get_card_capabilities() argument
517 return rsxx_creg_read(card, CREG_ADD_CAPABILITIES, in rsxx_get_card_capabilities()
521 int rsxx_issue_card_cmd(struct rsxx_cardinfo *card, u32 cmd) in rsxx_issue_card_cmd() argument
523 return rsxx_creg_write(card, CREG_ADD_CARD_CMD, in rsxx_issue_card_cmd()
529 static void hw_log_msg(struct rsxx_cardinfo *card, const char *str, int len) in hw_log_msg() argument
545 dev_emerg(CARD_TO_DEV(card), "HW: %.*s", len, str); in hw_log_msg()
548 dev_alert(CARD_TO_DEV(card), "HW: %.*s", len, str); in hw_log_msg()
551 dev_crit(CARD_TO_DEV(card), "HW: %.*s", len, str); in hw_log_msg()
554 dev_err(CARD_TO_DEV(card), "HW: %.*s", len, str); in hw_log_msg()
557 dev_warn(CARD_TO_DEV(card), "HW: %.*s", len, str); in hw_log_msg()
560 dev_notice(CARD_TO_DEV(card), "HW: %.*s", len, str); in hw_log_msg()
563 dev_info(CARD_TO_DEV(card), "HW: %.*s", len, str); in hw_log_msg()
566 dev_dbg(CARD_TO_DEV(card), "HW: %.*s", len, str); in hw_log_msg()
569 dev_info(CARD_TO_DEV(card), "HW: %.*s", len, str); in hw_log_msg()
595 static void read_hw_log_done(struct rsxx_cardinfo *card, in read_hw_log_done() argument
613 log_str = &card->log.buf[card->log.buf_len]; in read_hw_log_done()
614 cnt = min(cmd->cnt8 - off, LOG_BUF_SIZE8 - card->log.buf_len); in read_hw_log_done()
618 card->log.buf_len += len; in read_hw_log_done()
625 (card->log.buf_len == LOG_BUF_SIZE8)) { in read_hw_log_done()
626 if (card->log.buf_len != 1) /* Don't log blank lines. */ in read_hw_log_done()
627 hw_log_msg(card, card->log.buf, in read_hw_log_done()
628 card->log.buf_len); in read_hw_log_done()
629 card->log.buf_len = 0; in read_hw_log_done()
635 rsxx_read_hw_log(card); in read_hw_log_done()
638 int rsxx_read_hw_log(struct rsxx_cardinfo *card) in rsxx_read_hw_log() argument
642 st = creg_queue_cmd(card, CREG_OP_READ, CREG_ADD_LOG, in rsxx_read_hw_log()
643 sizeof(card->log.tmp), card->log.tmp, in rsxx_read_hw_log()
646 dev_err(CARD_TO_DEV(card), in rsxx_read_hw_log()
653 static int issue_reg_cmd(struct rsxx_cardinfo *card, in issue_reg_cmd() argument
659 return __issue_creg_rw(card, op, cmd->addr, cmd->cnt, cmd->data, in issue_reg_cmd()
663 int rsxx_reg_access(struct rsxx_cardinfo *card, in rsxx_reg_access() argument
677 st = issue_reg_cmd(card, &cmd, read); in rsxx_reg_access()
694 void rsxx_eeh_save_issued_creg(struct rsxx_cardinfo *card) in rsxx_eeh_save_issued_creg() argument
698 cmd = card->creg_ctrl.active_cmd; in rsxx_eeh_save_issued_creg()
699 card->creg_ctrl.active_cmd = NULL; in rsxx_eeh_save_issued_creg()
702 del_timer_sync(&card->creg_ctrl.cmd_timer); in rsxx_eeh_save_issued_creg()
704 spin_lock_bh(&card->creg_ctrl.lock); in rsxx_eeh_save_issued_creg()
705 list_add(&cmd->list, &card->creg_ctrl.queue); in rsxx_eeh_save_issued_creg()
706 card->creg_ctrl.q_depth++; in rsxx_eeh_save_issued_creg()
707 card->creg_ctrl.active = 0; in rsxx_eeh_save_issued_creg()
708 spin_unlock_bh(&card->creg_ctrl.lock); in rsxx_eeh_save_issued_creg()
712 void rsxx_kick_creg_queue(struct rsxx_cardinfo *card) in rsxx_kick_creg_queue() argument
714 spin_lock_bh(&card->creg_ctrl.lock); in rsxx_kick_creg_queue()
715 if (!list_empty(&card->creg_ctrl.queue)) in rsxx_kick_creg_queue()
716 creg_kick_queue(card); in rsxx_kick_creg_queue()
717 spin_unlock_bh(&card->creg_ctrl.lock); in rsxx_kick_creg_queue()
721 int rsxx_creg_setup(struct rsxx_cardinfo *card) in rsxx_creg_setup() argument
723 card->creg_ctrl.active_cmd = NULL; in rsxx_creg_setup()
725 card->creg_ctrl.creg_wq = in rsxx_creg_setup()
727 if (!card->creg_ctrl.creg_wq) in rsxx_creg_setup()
730 INIT_WORK(&card->creg_ctrl.done_work, creg_cmd_done); in rsxx_creg_setup()
731 mutex_init(&card->creg_ctrl.reset_lock); in rsxx_creg_setup()
732 INIT_LIST_HEAD(&card->creg_ctrl.queue); in rsxx_creg_setup()
733 spin_lock_init(&card->creg_ctrl.lock); in rsxx_creg_setup()
734 timer_setup(&card->creg_ctrl.cmd_timer, creg_cmd_timed_out, 0); in rsxx_creg_setup()
739 void rsxx_creg_destroy(struct rsxx_cardinfo *card) in rsxx_creg_destroy() argument
746 spin_lock_bh(&card->creg_ctrl.lock); in rsxx_creg_destroy()
747 list_for_each_entry_safe(cmd, tmp, &card->creg_ctrl.queue, list) { in rsxx_creg_destroy()
750 cmd->cb(card, cmd, -ECANCELED); in rsxx_creg_destroy()
756 dev_info(CARD_TO_DEV(card), in rsxx_creg_destroy()
759 cmd = card->creg_ctrl.active_cmd; in rsxx_creg_destroy()
760 card->creg_ctrl.active_cmd = NULL; in rsxx_creg_destroy()
762 if (timer_pending(&card->creg_ctrl.cmd_timer)) in rsxx_creg_destroy()
763 del_timer_sync(&card->creg_ctrl.cmd_timer); in rsxx_creg_destroy()
766 cmd->cb(card, cmd, -ECANCELED); in rsxx_creg_destroy()
767 dev_info(CARD_TO_DEV(card), in rsxx_creg_destroy()
771 spin_unlock_bh(&card->creg_ctrl.lock); in rsxx_creg_destroy()
773 cancel_work_sync(&card->creg_ctrl.done_work); in rsxx_creg_destroy()