Lines Matching full:ctl
59 struct t7xx_fsm_ctl *ctl = md->fsm_ctl; in t7xx_fsm_notifier_register() local
62 spin_lock_irqsave(&ctl->notifier_lock, flags); in t7xx_fsm_notifier_register()
63 list_add_tail(¬ifier->entry, &ctl->notifier_list); in t7xx_fsm_notifier_register()
64 spin_unlock_irqrestore(&ctl->notifier_lock, flags); in t7xx_fsm_notifier_register()
70 struct t7xx_fsm_ctl *ctl = md->fsm_ctl; in t7xx_fsm_notifier_unregister() local
73 spin_lock_irqsave(&ctl->notifier_lock, flags); in t7xx_fsm_notifier_unregister()
74 list_for_each_entry_safe(notifier_cur, notifier_next, &ctl->notifier_list, entry) { in t7xx_fsm_notifier_unregister()
78 spin_unlock_irqrestore(&ctl->notifier_lock, flags); in t7xx_fsm_notifier_unregister()
83 struct t7xx_fsm_ctl *ctl = md->fsm_ctl; in fsm_state_notify() local
87 spin_lock_irqsave(&ctl->notifier_lock, flags); in fsm_state_notify()
88 list_for_each_entry(notifier, &ctl->notifier_list, entry) { in fsm_state_notify()
89 spin_unlock_irqrestore(&ctl->notifier_lock, flags); in fsm_state_notify()
93 spin_lock_irqsave(&ctl->notifier_lock, flags); in fsm_state_notify()
95 spin_unlock_irqrestore(&ctl->notifier_lock, flags); in fsm_state_notify()
98 void t7xx_fsm_broadcast_state(struct t7xx_fsm_ctl *ctl, enum md_state state) in t7xx_fsm_broadcast_state() argument
100 ctl->md_state = state; in t7xx_fsm_broadcast_state()
103 t7xx_port_proxy_md_status_notify(ctl->md->port_prox, state); in t7xx_fsm_broadcast_state()
104 fsm_state_notify(ctl->md, state); in t7xx_fsm_broadcast_state()
114 static void fsm_finish_command(struct t7xx_fsm_ctl *ctl, struct t7xx_fsm_command *cmd, int result) in fsm_finish_command() argument
130 static void fsm_flush_event_cmd_qs(struct t7xx_fsm_ctl *ctl) in fsm_flush_event_cmd_qs() argument
132 struct device *dev = &ctl->md->t7xx_dev->pdev->dev; in fsm_flush_event_cmd_qs()
137 spin_lock_irqsave(&ctl->command_lock, flags); in fsm_flush_event_cmd_qs()
138 list_for_each_entry_safe(cmd, cmd_next, &ctl->command_queue, entry) { in fsm_flush_event_cmd_qs()
141 fsm_finish_command(ctl, cmd, -EINVAL); in fsm_flush_event_cmd_qs()
143 spin_unlock_irqrestore(&ctl->command_lock, flags); in fsm_flush_event_cmd_qs()
145 spin_lock_irqsave(&ctl->event_lock, flags); in fsm_flush_event_cmd_qs()
146 list_for_each_entry_safe(event, evt_next, &ctl->event_queue, entry) { in fsm_flush_event_cmd_qs()
150 spin_unlock_irqrestore(&ctl->event_lock, flags); in fsm_flush_event_cmd_qs()
153 static void fsm_wait_for_event(struct t7xx_fsm_ctl *ctl, enum t7xx_fsm_event_state event_expected, in fsm_wait_for_event() argument
167 spin_lock_irqsave(&ctl->event_lock, flags); in fsm_wait_for_event()
168 event = list_first_entry_or_null(&ctl->event_queue, struct t7xx_fsm_event, entry); in fsm_wait_for_event()
176 spin_unlock_irqrestore(&ctl->event_lock, flags); in fsm_wait_for_event()
183 static void fsm_routine_exception(struct t7xx_fsm_ctl *ctl, struct t7xx_fsm_command *cmd, in fsm_routine_exception() argument
186 struct device *dev = &ctl->md->t7xx_dev->pdev->dev; in fsm_routine_exception()
188 if (ctl->curr_state != FSM_STATE_READY && ctl->curr_state != FSM_STATE_STARTING) { in fsm_routine_exception()
190 fsm_finish_command(ctl, cmd, -EINVAL); in fsm_routine_exception()
195 ctl->curr_state = FSM_STATE_EXCEPTION; in fsm_routine_exception()
204 t7xx_fsm_broadcast_state(ctl, MD_STATE_EXCEPTION); in fsm_routine_exception()
205 t7xx_pci_pm_exp_detected(ctl->md->t7xx_dev); in fsm_routine_exception()
206 t7xx_md_exception_handshake(ctl->md); in fsm_routine_exception()
208 fsm_wait_for_event(ctl, FSM_EVENT_MD_EX_REC_OK, FSM_EVENT_MD_EX, in fsm_routine_exception()
210 fsm_wait_for_event(ctl, FSM_EVENT_MD_EX_PASS, FSM_EVENT_INVALID, in fsm_routine_exception()
220 fsm_finish_command(ctl, cmd, 0); in fsm_routine_exception()
223 static void t7xx_lk_stage_event_handling(struct t7xx_fsm_ctl *ctl, unsigned int status) in t7xx_lk_stage_event_handling() argument
225 struct t7xx_modem *md = ctl->md; in t7xx_lk_stage_event_handling()
245 port = &ctl->md->port_prox->ports[0]; in t7xx_lk_stage_event_handling()
262 static int fsm_stopped_handler(struct t7xx_fsm_ctl *ctl) in fsm_stopped_handler() argument
266 ctl->curr_state = FSM_STATE_STOPPED; in fsm_stopped_handler()
268 mode = READ_ONCE(ctl->md->t7xx_dev->mode); in fsm_stopped_handler()
272 t7xx_fsm_broadcast_state(ctl, MD_STATE_STOPPED); in fsm_stopped_handler()
273 return t7xx_md_reset(ctl->md->t7xx_dev); in fsm_stopped_handler()
276 static void fsm_routine_stopped(struct t7xx_fsm_ctl *ctl, struct t7xx_fsm_command *cmd) in fsm_routine_stopped() argument
278 if (ctl->curr_state == FSM_STATE_STOPPED) { in fsm_routine_stopped()
279 fsm_finish_command(ctl, cmd, -EINVAL); in fsm_routine_stopped()
283 fsm_finish_command(ctl, cmd, fsm_stopped_handler(ctl)); in fsm_routine_stopped()
286 static void fsm_routine_stopping(struct t7xx_fsm_ctl *ctl, struct t7xx_fsm_command *cmd) in fsm_routine_stopping() argument
288 struct cldma_ctrl *md_ctrl = ctl->md->md_ctrl[CLDMA_ID_MD]; in fsm_routine_stopping()
289 struct t7xx_pci_dev *t7xx_dev = ctl->md->t7xx_dev; in fsm_routine_stopping()
291 if (ctl->curr_state == FSM_STATE_STOPPED || ctl->curr_state == FSM_STATE_STOPPING) { in fsm_routine_stopping()
292 fsm_finish_command(ctl, cmd, -EINVAL); in fsm_routine_stopping()
296 ctl->curr_state = FSM_STATE_STOPPING; in fsm_routine_stopping()
297 t7xx_fsm_broadcast_state(ctl, MD_STATE_WAITING_TO_STOP); in fsm_routine_stopping()
304 fsm_finish_command(ctl, cmd, fsm_stopped_handler(ctl)); in fsm_routine_stopping()
307 static void t7xx_fsm_broadcast_ready_state(struct t7xx_fsm_ctl *ctl) in t7xx_fsm_broadcast_ready_state() argument
309 if (ctl->md_state != MD_STATE_WAITING_FOR_HS2) in t7xx_fsm_broadcast_ready_state()
312 ctl->md_state = MD_STATE_READY; in t7xx_fsm_broadcast_ready_state()
314 fsm_state_notify(ctl->md, MD_STATE_READY); in t7xx_fsm_broadcast_ready_state()
315 t7xx_port_proxy_md_status_notify(ctl->md->port_prox, MD_STATE_READY); in t7xx_fsm_broadcast_ready_state()
318 static void fsm_routine_ready(struct t7xx_fsm_ctl *ctl) in fsm_routine_ready() argument
320 struct t7xx_modem *md = ctl->md; in fsm_routine_ready()
322 ctl->curr_state = FSM_STATE_READY; in fsm_routine_ready()
323 t7xx_fsm_broadcast_ready_state(ctl); in fsm_routine_ready()
328 static int fsm_routine_starting(struct t7xx_fsm_ctl *ctl) in fsm_routine_starting() argument
330 struct t7xx_modem *md = ctl->md; in fsm_routine_starting()
333 ctl->curr_state = FSM_STATE_STARTING; in fsm_routine_starting()
335 t7xx_fsm_broadcast_state(ctl, MD_STATE_WAITING_FOR_HS1); in fsm_routine_starting()
338 wait_event_interruptible_timeout(ctl->async_hk_wq, in fsm_routine_starting()
340 ctl->exp_flg, HZ * 60); in fsm_routine_starting()
343 if (ctl->exp_flg) in fsm_routine_starting()
349 t7xx_fsm_append_event(ctl, FSM_EVENT_MD_HS2_EXIT, NULL, 0); in fsm_routine_starting()
351 fsm_routine_exception(ctl, NULL, EXCEPTION_HS_TIMEOUT); in fsm_routine_starting()
356 t7xx_fsm_append_event(ctl, FSM_EVENT_AP_HS2_EXIT, NULL, 0); in fsm_routine_starting()
358 fsm_routine_exception(ctl, NULL, EXCEPTION_HS_TIMEOUT); in fsm_routine_starting()
363 fsm_routine_ready(ctl); in fsm_routine_starting()
367 static void fsm_routine_start(struct t7xx_fsm_ctl *ctl, struct t7xx_fsm_command *cmd) in fsm_routine_start() argument
369 struct t7xx_modem *md = ctl->md; in fsm_routine_start()
377 if (ctl->curr_state != FSM_STATE_INIT && ctl->curr_state != FSM_STATE_PRE_START && in fsm_routine_start()
378 ctl->curr_state != FSM_STATE_STOPPED) { in fsm_routine_start()
379 fsm_finish_command(ctl, cmd, -EINVAL); in fsm_routine_start()
384 ctl->curr_state = FSM_STATE_PRE_START; in fsm_routine_start()
394 if (status != ctl->status || cmd->flag != 0) { in fsm_routine_start()
402 ret = t7xx_fsm_append_cmd(ctl, FSM_CMD_START, 0); in fsm_routine_start()
408 t7xx_lk_stage_event_handling(ctl, status); in fsm_routine_start()
421 ret = fsm_routine_starting(ctl); in fsm_routine_start()
427 ctl->status = status; in fsm_routine_start()
434 fsm_finish_command(ctl, cmd, ret); in fsm_routine_start()
439 struct t7xx_fsm_ctl *ctl = data; in fsm_main_thread() local
444 if (wait_event_interruptible(ctl->command_wq, !list_empty(&ctl->command_queue) || in fsm_main_thread()
451 spin_lock_irqsave(&ctl->command_lock, flags); in fsm_main_thread()
452 cmd = list_first_entry(&ctl->command_queue, struct t7xx_fsm_command, entry); in fsm_main_thread()
454 spin_unlock_irqrestore(&ctl->command_lock, flags); in fsm_main_thread()
458 fsm_routine_start(ctl, cmd); in fsm_main_thread()
462 fsm_routine_exception(ctl, cmd, FIELD_GET(FSM_CMD_EX_REASON, cmd->flag)); in fsm_main_thread()
466 fsm_routine_stopping(ctl, cmd); in fsm_main_thread()
470 fsm_routine_stopped(ctl, cmd); in fsm_main_thread()
474 fsm_finish_command(ctl, cmd, -EINVAL); in fsm_main_thread()
475 fsm_flush_event_cmd_qs(ctl); in fsm_main_thread()
483 int t7xx_fsm_append_cmd(struct t7xx_fsm_ctl *ctl, enum t7xx_fsm_cmd_state cmd_id, unsigned int flag) in t7xx_fsm_append_cmd() argument
503 spin_lock_irqsave(&ctl->command_lock, flags); in t7xx_fsm_append_cmd()
504 list_add_tail(&cmd->entry, &ctl->command_queue); in t7xx_fsm_append_cmd()
505 spin_unlock_irqrestore(&ctl->command_lock, flags); in t7xx_fsm_append_cmd()
507 wake_up(&ctl->command_wq); in t7xx_fsm_append_cmd()
523 int t7xx_fsm_append_event(struct t7xx_fsm_ctl *ctl, enum t7xx_fsm_event_state event_id, in t7xx_fsm_append_event() argument
526 struct device *dev = &ctl->md->t7xx_dev->pdev->dev; in t7xx_fsm_append_event()
547 spin_lock_irqsave(&ctl->event_lock, flags); in t7xx_fsm_append_event()
548 list_add_tail(&event->entry, &ctl->event_queue); in t7xx_fsm_append_event()
549 spin_unlock_irqrestore(&ctl->event_lock, flags); in t7xx_fsm_append_event()
551 wake_up_all(&ctl->event_wq); in t7xx_fsm_append_event()
555 void t7xx_fsm_clr_event(struct t7xx_fsm_ctl *ctl, enum t7xx_fsm_event_state event_id) in t7xx_fsm_clr_event() argument
560 spin_lock_irqsave(&ctl->event_lock, flags); in t7xx_fsm_clr_event()
561 list_for_each_entry_safe(event, evt_next, &ctl->event_queue, entry) { in t7xx_fsm_clr_event()
565 spin_unlock_irqrestore(&ctl->event_lock, flags); in t7xx_fsm_clr_event()
568 enum md_state t7xx_fsm_get_md_state(struct t7xx_fsm_ctl *ctl) in t7xx_fsm_get_md_state() argument
570 if (ctl) in t7xx_fsm_get_md_state()
571 return ctl->md_state; in t7xx_fsm_get_md_state()
576 unsigned int t7xx_fsm_get_ctl_state(struct t7xx_fsm_ctl *ctl) in t7xx_fsm_get_ctl_state() argument
578 if (ctl) in t7xx_fsm_get_ctl_state()
579 return ctl->curr_state; in t7xx_fsm_get_ctl_state()
584 int t7xx_fsm_recv_md_intr(struct t7xx_fsm_ctl *ctl, enum t7xx_md_irq_type type) in t7xx_fsm_recv_md_intr() argument
589 return t7xx_fsm_append_cmd(ctl, FSM_CMD_START, cmd_flags); in t7xx_fsm_recv_md_intr()
591 ctl->exp_flg = true; in t7xx_fsm_recv_md_intr()
592 wake_up(&ctl->async_hk_wq); in t7xx_fsm_recv_md_intr()
594 return t7xx_fsm_append_cmd(ctl, FSM_CMD_EXCEPTION, cmd_flags); in t7xx_fsm_recv_md_intr()
602 struct t7xx_fsm_ctl *ctl = md->fsm_ctl; in t7xx_fsm_reset() local
604 fsm_flush_event_cmd_qs(ctl); in t7xx_fsm_reset()
605 ctl->curr_state = FSM_STATE_STOPPED; in t7xx_fsm_reset()
606 ctl->exp_flg = false; in t7xx_fsm_reset()
607 ctl->status = T7XX_DEV_STAGE_INIT; in t7xx_fsm_reset()
613 struct t7xx_fsm_ctl *ctl; in t7xx_fsm_init() local
615 ctl = devm_kzalloc(dev, sizeof(*ctl), GFP_KERNEL); in t7xx_fsm_init()
616 if (!ctl) in t7xx_fsm_init()
619 md->fsm_ctl = ctl; in t7xx_fsm_init()
620 ctl->md = md; in t7xx_fsm_init()
621 ctl->curr_state = FSM_STATE_INIT; in t7xx_fsm_init()
622 INIT_LIST_HEAD(&ctl->command_queue); in t7xx_fsm_init()
623 INIT_LIST_HEAD(&ctl->event_queue); in t7xx_fsm_init()
624 init_waitqueue_head(&ctl->async_hk_wq); in t7xx_fsm_init()
625 init_waitqueue_head(&ctl->event_wq); in t7xx_fsm_init()
626 INIT_LIST_HEAD(&ctl->notifier_list); in t7xx_fsm_init()
627 init_waitqueue_head(&ctl->command_wq); in t7xx_fsm_init()
628 spin_lock_init(&ctl->event_lock); in t7xx_fsm_init()
629 spin_lock_init(&ctl->command_lock); in t7xx_fsm_init()
630 ctl->exp_flg = false; in t7xx_fsm_init()
631 spin_lock_init(&ctl->notifier_lock); in t7xx_fsm_init()
633 ctl->fsm_thread = kthread_run(fsm_main_thread, ctl, "t7xx_fsm"); in t7xx_fsm_init()
634 return PTR_ERR_OR_ZERO(ctl->fsm_thread); in t7xx_fsm_init()
639 struct t7xx_fsm_ctl *ctl = md->fsm_ctl; in t7xx_fsm_uninit() local
641 if (!ctl) in t7xx_fsm_uninit()
644 if (ctl->fsm_thread) in t7xx_fsm_uninit()
645 kthread_stop(ctl->fsm_thread); in t7xx_fsm_uninit()
647 fsm_flush_event_cmd_qs(ctl); in t7xx_fsm_uninit()