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()
107 static void fsm_finish_command(struct t7xx_fsm_ctl *ctl, struct t7xx_fsm_command *cmd, int result) in fsm_finish_command() argument
123 static void fsm_flush_event_cmd_qs(struct t7xx_fsm_ctl *ctl) in fsm_flush_event_cmd_qs() argument
125 struct device *dev = &ctl->md->t7xx_dev->pdev->dev; in fsm_flush_event_cmd_qs()
130 spin_lock_irqsave(&ctl->command_lock, flags); in fsm_flush_event_cmd_qs()
131 list_for_each_entry_safe(cmd, cmd_next, &ctl->command_queue, entry) { in fsm_flush_event_cmd_qs()
134 fsm_finish_command(ctl, cmd, -EINVAL); in fsm_flush_event_cmd_qs()
136 spin_unlock_irqrestore(&ctl->command_lock, flags); in fsm_flush_event_cmd_qs()
138 spin_lock_irqsave(&ctl->event_lock, flags); in fsm_flush_event_cmd_qs()
139 list_for_each_entry_safe(event, evt_next, &ctl->event_queue, entry) { in fsm_flush_event_cmd_qs()
143 spin_unlock_irqrestore(&ctl->event_lock, flags); in fsm_flush_event_cmd_qs()
146 static void fsm_wait_for_event(struct t7xx_fsm_ctl *ctl, enum t7xx_fsm_event_state event_expected, in fsm_wait_for_event() argument
160 spin_lock_irqsave(&ctl->event_lock, flags); in fsm_wait_for_event()
161 event = list_first_entry_or_null(&ctl->event_queue, struct t7xx_fsm_event, entry); in fsm_wait_for_event()
169 spin_unlock_irqrestore(&ctl->event_lock, flags); in fsm_wait_for_event()
176 static void fsm_routine_exception(struct t7xx_fsm_ctl *ctl, struct t7xx_fsm_command *cmd, in fsm_routine_exception() argument
179 struct device *dev = &ctl->md->t7xx_dev->pdev->dev; in fsm_routine_exception()
181 if (ctl->curr_state != FSM_STATE_READY && ctl->curr_state != FSM_STATE_STARTING) { in fsm_routine_exception()
183 fsm_finish_command(ctl, cmd, -EINVAL); in fsm_routine_exception()
188 ctl->curr_state = FSM_STATE_EXCEPTION; in fsm_routine_exception()
197 t7xx_fsm_broadcast_state(ctl, MD_STATE_EXCEPTION); in fsm_routine_exception()
198 t7xx_pci_pm_exp_detected(ctl->md->t7xx_dev); in fsm_routine_exception()
199 t7xx_md_exception_handshake(ctl->md); in fsm_routine_exception()
201 fsm_wait_for_event(ctl, FSM_EVENT_MD_EX_REC_OK, FSM_EVENT_MD_EX, in fsm_routine_exception()
203 fsm_wait_for_event(ctl, FSM_EVENT_MD_EX_PASS, FSM_EVENT_INVALID, in fsm_routine_exception()
213 fsm_finish_command(ctl, cmd, 0); in fsm_routine_exception()
216 static void t7xx_lk_stage_event_handling(struct t7xx_fsm_ctl *ctl, unsigned int status) in t7xx_lk_stage_event_handling() argument
218 struct t7xx_modem *md = ctl->md; in t7xx_lk_stage_event_handling()
238 port = &ctl->md->port_prox->ports[0]; in t7xx_lk_stage_event_handling()
255 static int fsm_stopped_handler(struct t7xx_fsm_ctl *ctl) in fsm_stopped_handler() argument
259 ctl->curr_state = FSM_STATE_STOPPED; in fsm_stopped_handler()
261 mode = READ_ONCE(ctl->md->t7xx_dev->mode); in fsm_stopped_handler()
265 t7xx_fsm_broadcast_state(ctl, MD_STATE_STOPPED); in fsm_stopped_handler()
266 return t7xx_md_reset(ctl->md->t7xx_dev); in fsm_stopped_handler()
269 static void fsm_routine_stopped(struct t7xx_fsm_ctl *ctl, struct t7xx_fsm_command *cmd) in fsm_routine_stopped() argument
271 if (ctl->curr_state == FSM_STATE_STOPPED) { in fsm_routine_stopped()
272 fsm_finish_command(ctl, cmd, -EINVAL); in fsm_routine_stopped()
276 fsm_finish_command(ctl, cmd, fsm_stopped_handler(ctl)); in fsm_routine_stopped()
279 static void fsm_routine_stopping(struct t7xx_fsm_ctl *ctl, struct t7xx_fsm_command *cmd) in fsm_routine_stopping() argument
281 struct cldma_ctrl *md_ctrl = ctl->md->md_ctrl[CLDMA_ID_MD]; in fsm_routine_stopping()
282 struct t7xx_pci_dev *t7xx_dev = ctl->md->t7xx_dev; in fsm_routine_stopping()
284 if (ctl->curr_state == FSM_STATE_STOPPED || ctl->curr_state == FSM_STATE_STOPPING) { in fsm_routine_stopping()
285 fsm_finish_command(ctl, cmd, -EINVAL); in fsm_routine_stopping()
289 ctl->curr_state = FSM_STATE_STOPPING; in fsm_routine_stopping()
290 t7xx_fsm_broadcast_state(ctl, MD_STATE_WAITING_TO_STOP); in fsm_routine_stopping()
297 fsm_finish_command(ctl, cmd, fsm_stopped_handler(ctl)); in fsm_routine_stopping()
300 static void t7xx_fsm_broadcast_ready_state(struct t7xx_fsm_ctl *ctl) in t7xx_fsm_broadcast_ready_state() argument
302 if (ctl->md_state != MD_STATE_WAITING_FOR_HS2) in t7xx_fsm_broadcast_ready_state()
305 ctl->md_state = MD_STATE_READY; in t7xx_fsm_broadcast_ready_state()
307 fsm_state_notify(ctl->md, MD_STATE_READY); in t7xx_fsm_broadcast_ready_state()
308 t7xx_port_proxy_md_status_notify(ctl->md->port_prox, MD_STATE_READY); in t7xx_fsm_broadcast_ready_state()
311 static void fsm_routine_ready(struct t7xx_fsm_ctl *ctl) in fsm_routine_ready() argument
313 struct t7xx_modem *md = ctl->md; in fsm_routine_ready()
315 ctl->curr_state = FSM_STATE_READY; in fsm_routine_ready()
316 t7xx_fsm_broadcast_ready_state(ctl); in fsm_routine_ready()
321 static int fsm_routine_starting(struct t7xx_fsm_ctl *ctl) in fsm_routine_starting() argument
323 struct t7xx_modem *md = ctl->md; in fsm_routine_starting()
326 ctl->curr_state = FSM_STATE_STARTING; in fsm_routine_starting()
328 t7xx_fsm_broadcast_state(ctl, MD_STATE_WAITING_FOR_HS1); in fsm_routine_starting()
331 wait_event_interruptible_timeout(ctl->async_hk_wq, in fsm_routine_starting()
333 ctl->exp_flg, HZ * 60); in fsm_routine_starting()
336 if (ctl->exp_flg) in fsm_routine_starting()
342 t7xx_fsm_append_event(ctl, FSM_EVENT_MD_HS2_EXIT, NULL, 0); in fsm_routine_starting()
344 fsm_routine_exception(ctl, NULL, EXCEPTION_HS_TIMEOUT); in fsm_routine_starting()
349 t7xx_fsm_append_event(ctl, FSM_EVENT_AP_HS2_EXIT, NULL, 0); in fsm_routine_starting()
351 fsm_routine_exception(ctl, NULL, EXCEPTION_HS_TIMEOUT); in fsm_routine_starting()
356 fsm_routine_ready(ctl); in fsm_routine_starting()
360 static void fsm_routine_start(struct t7xx_fsm_ctl *ctl, struct t7xx_fsm_command *cmd) in fsm_routine_start() argument
362 struct t7xx_modem *md = ctl->md; in fsm_routine_start()
370 if (ctl->curr_state != FSM_STATE_INIT && ctl->curr_state != FSM_STATE_PRE_START && in fsm_routine_start()
371 ctl->curr_state != FSM_STATE_STOPPED) { in fsm_routine_start()
372 fsm_finish_command(ctl, cmd, -EINVAL); in fsm_routine_start()
377 ctl->curr_state = FSM_STATE_PRE_START; in fsm_routine_start()
387 if (status != ctl->status || cmd->flag != 0) { in fsm_routine_start()
395 ret = t7xx_fsm_append_cmd(ctl, FSM_CMD_START, 0); in fsm_routine_start()
401 t7xx_lk_stage_event_handling(ctl, status); in fsm_routine_start()
414 ret = fsm_routine_starting(ctl); in fsm_routine_start()
420 ctl->status = status; in fsm_routine_start()
427 fsm_finish_command(ctl, cmd, ret); in fsm_routine_start()
432 struct t7xx_fsm_ctl *ctl = data; in fsm_main_thread() local
437 if (wait_event_interruptible(ctl->command_wq, !list_empty(&ctl->command_queue) || in fsm_main_thread()
444 spin_lock_irqsave(&ctl->command_lock, flags); in fsm_main_thread()
445 cmd = list_first_entry(&ctl->command_queue, struct t7xx_fsm_command, entry); in fsm_main_thread()
447 spin_unlock_irqrestore(&ctl->command_lock, flags); in fsm_main_thread()
451 fsm_routine_start(ctl, cmd); in fsm_main_thread()
455 fsm_routine_exception(ctl, cmd, FIELD_GET(FSM_CMD_EX_REASON, cmd->flag)); in fsm_main_thread()
459 fsm_routine_stopping(ctl, cmd); in fsm_main_thread()
463 fsm_routine_stopped(ctl, cmd); in fsm_main_thread()
467 fsm_finish_command(ctl, cmd, -EINVAL); in fsm_main_thread()
468 fsm_flush_event_cmd_qs(ctl); in fsm_main_thread()
476 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
495 spin_lock_irqsave(&ctl->command_lock, flags); in t7xx_fsm_append_cmd()
496 list_add_tail(&cmd->entry, &ctl->command_queue); in t7xx_fsm_append_cmd()
497 spin_unlock_irqrestore(&ctl->command_lock, flags); in t7xx_fsm_append_cmd()
499 wake_up(&ctl->command_wq); in t7xx_fsm_append_cmd()
515 int t7xx_fsm_append_event(struct t7xx_fsm_ctl *ctl, enum t7xx_fsm_event_state event_id, in t7xx_fsm_append_event() argument
518 struct device *dev = &ctl->md->t7xx_dev->pdev->dev; in t7xx_fsm_append_event()
539 spin_lock_irqsave(&ctl->event_lock, flags); in t7xx_fsm_append_event()
540 list_add_tail(&event->entry, &ctl->event_queue); in t7xx_fsm_append_event()
541 spin_unlock_irqrestore(&ctl->event_lock, flags); in t7xx_fsm_append_event()
543 wake_up_all(&ctl->event_wq); in t7xx_fsm_append_event()
547 void t7xx_fsm_clr_event(struct t7xx_fsm_ctl *ctl, enum t7xx_fsm_event_state event_id) in t7xx_fsm_clr_event() argument
552 spin_lock_irqsave(&ctl->event_lock, flags); in t7xx_fsm_clr_event()
553 list_for_each_entry_safe(event, evt_next, &ctl->event_queue, entry) { in t7xx_fsm_clr_event()
557 spin_unlock_irqrestore(&ctl->event_lock, flags); in t7xx_fsm_clr_event()
560 enum md_state t7xx_fsm_get_md_state(struct t7xx_fsm_ctl *ctl) in t7xx_fsm_get_md_state() argument
562 if (ctl) in t7xx_fsm_get_md_state()
563 return ctl->md_state; in t7xx_fsm_get_md_state()
568 unsigned int t7xx_fsm_get_ctl_state(struct t7xx_fsm_ctl *ctl) in t7xx_fsm_get_ctl_state() argument
570 if (ctl) in t7xx_fsm_get_ctl_state()
571 return ctl->curr_state; in t7xx_fsm_get_ctl_state()
576 int t7xx_fsm_recv_md_intr(struct t7xx_fsm_ctl *ctl, enum t7xx_md_irq_type type) in t7xx_fsm_recv_md_intr() argument
581 return t7xx_fsm_append_cmd(ctl, FSM_CMD_START, cmd_flags); in t7xx_fsm_recv_md_intr()
583 ctl->exp_flg = true; in t7xx_fsm_recv_md_intr()
584 wake_up(&ctl->async_hk_wq); in t7xx_fsm_recv_md_intr()
586 return t7xx_fsm_append_cmd(ctl, FSM_CMD_EXCEPTION, cmd_flags); in t7xx_fsm_recv_md_intr()
594 struct t7xx_fsm_ctl *ctl = md->fsm_ctl; in t7xx_fsm_reset() local
596 fsm_flush_event_cmd_qs(ctl); in t7xx_fsm_reset()
597 ctl->curr_state = FSM_STATE_STOPPED; in t7xx_fsm_reset()
598 ctl->exp_flg = false; in t7xx_fsm_reset()
599 ctl->status = T7XX_DEV_STAGE_INIT; in t7xx_fsm_reset()
605 struct t7xx_fsm_ctl *ctl; in t7xx_fsm_init() local
607 ctl = devm_kzalloc(dev, sizeof(*ctl), GFP_KERNEL); in t7xx_fsm_init()
608 if (!ctl) in t7xx_fsm_init()
611 md->fsm_ctl = ctl; in t7xx_fsm_init()
612 ctl->md = md; in t7xx_fsm_init()
613 ctl->curr_state = FSM_STATE_INIT; in t7xx_fsm_init()
614 INIT_LIST_HEAD(&ctl->command_queue); in t7xx_fsm_init()
615 INIT_LIST_HEAD(&ctl->event_queue); in t7xx_fsm_init()
616 init_waitqueue_head(&ctl->async_hk_wq); in t7xx_fsm_init()
617 init_waitqueue_head(&ctl->event_wq); in t7xx_fsm_init()
618 INIT_LIST_HEAD(&ctl->notifier_list); in t7xx_fsm_init()
619 init_waitqueue_head(&ctl->command_wq); in t7xx_fsm_init()
620 spin_lock_init(&ctl->event_lock); in t7xx_fsm_init()
621 spin_lock_init(&ctl->command_lock); in t7xx_fsm_init()
622 ctl->exp_flg = false; in t7xx_fsm_init()
623 spin_lock_init(&ctl->notifier_lock); in t7xx_fsm_init()
625 ctl->fsm_thread = kthread_run(fsm_main_thread, ctl, "t7xx_fsm"); in t7xx_fsm_init()
626 return PTR_ERR_OR_ZERO(ctl->fsm_thread); in t7xx_fsm_init()
631 struct t7xx_fsm_ctl *ctl = md->fsm_ctl; in t7xx_fsm_uninit() local
633 if (!ctl) in t7xx_fsm_uninit()
636 if (ctl->fsm_thread) in t7xx_fsm_uninit()
637 kthread_stop(ctl->fsm_thread); in t7xx_fsm_uninit()
639 fsm_flush_event_cmd_qs(ctl); in t7xx_fsm_uninit()