Lines Matching defs:ser
14 #include "ser.h"
54 void (*st_func)(struct rtw89_ser *ser, u8 event);
62 static char *ser_ev_name(struct rtw89_ser *ser, u8 event)
65 return ser->ev_tbl[event].name;
70 static char *ser_st_name(struct rtw89_ser *ser)
72 if (ser->state < SER_ST_MAX_ST)
73 return ser->st_tbl[ser->state].name;
152 static void ser_state_run(struct rtw89_ser *ser, u8 evt)
154 struct rtw89_dev *rtwdev = container_of(ser, struct rtw89_dev, ser);
156 rtw89_debug(rtwdev, RTW89_DBG_SER, "ser: %s receive %s\n",
157 ser_st_name(ser), ser_ev_name(ser, evt));
163 ser->st_tbl[ser->state].st_func(ser, evt);
166 static void ser_state_goto(struct rtw89_ser *ser, u8 new_state)
168 struct rtw89_dev *rtwdev = container_of(ser, struct rtw89_dev, ser);
170 if (ser->state == new_state || new_state >= SER_ST_MAX_ST)
172 ser_state_run(ser, SER_EV_STATE_OUT);
174 rtw89_debug(rtwdev, RTW89_DBG_SER, "ser: %s goto -> %s\n",
175 ser_st_name(ser), ser->st_tbl[new_state].name);
177 ser->state = new_state;
178 ser_state_run(ser, SER_EV_STATE_IN);
181 static struct ser_msg *__rtw89_ser_dequeue_msg(struct rtw89_ser *ser)
185 spin_lock_irq(&ser->msg_q_lock);
186 msg = list_first_entry_or_null(&ser->msg_q, struct ser_msg, list);
189 spin_unlock_irq(&ser->msg_q_lock);
197 struct rtw89_ser *ser = container_of(work, struct rtw89_ser,
200 while ((msg = __rtw89_ser_dequeue_msg(ser))) {
201 ser_state_run(ser, msg->event);
206 static int ser_send_msg(struct rtw89_ser *ser, u8 event)
208 struct rtw89_dev *rtwdev = container_of(ser, struct rtw89_dev, ser);
211 if (test_bit(RTW89_SER_DRV_STOP_RUN, ser->flags))
220 spin_lock_irq(&ser->msg_q_lock);
221 list_add(&msg->list, &ser->msg_q);
222 spin_unlock_irq(&ser->msg_q_lock);
224 ieee80211_queue_work(rtwdev->hw, &ser->ser_hdl_work);
230 struct rtw89_ser *ser = container_of(work, struct rtw89_ser,
233 ser_send_msg(ser, ser->alarm_event);
234 ser->alarm_event = SER_EV_NONE;
237 static void ser_set_alarm(struct rtw89_ser *ser, u32 ms, u8 event)
239 struct rtw89_dev *rtwdev = container_of(ser, struct rtw89_dev, ser);
241 if (test_bit(RTW89_SER_DRV_STOP_RUN, ser->flags))
244 ser->alarm_event = event;
245 ieee80211_queue_delayed_work(rtwdev->hw, &ser->ser_alarm_work,
249 static void ser_del_alarm(struct rtw89_ser *ser)
251 cancel_delayed_work(&ser->ser_alarm_work);
252 ser->alarm_event = SER_EV_NONE;
256 static void drv_stop_tx(struct rtw89_ser *ser)
258 struct rtw89_dev *rtwdev = container_of(ser, struct rtw89_dev, ser);
261 set_bit(RTW89_SER_DRV_STOP_TX, ser->flags);
264 static void drv_stop_rx(struct rtw89_ser *ser)
266 struct rtw89_dev *rtwdev = container_of(ser, struct rtw89_dev, ser);
269 set_bit(RTW89_SER_DRV_STOP_RX, ser->flags);
272 static void drv_trx_reset(struct rtw89_ser *ser)
274 struct rtw89_dev *rtwdev = container_of(ser, struct rtw89_dev, ser);
279 static void drv_resume_tx(struct rtw89_ser *ser)
281 struct rtw89_dev *rtwdev = container_of(ser, struct rtw89_dev, ser);
283 if (!test_bit(RTW89_SER_DRV_STOP_TX, ser->flags))
287 clear_bit(RTW89_SER_DRV_STOP_TX, ser->flags);
290 static void drv_resume_rx(struct rtw89_ser *ser)
292 struct rtw89_dev *rtwdev = container_of(ser, struct rtw89_dev, ser);
294 if (!test_bit(RTW89_SER_DRV_STOP_RX, ser->flags))
298 clear_bit(RTW89_SER_DRV_STOP_RX, ser->flags);
354 static int hal_enable_dma(struct rtw89_ser *ser)
356 struct rtw89_dev *rtwdev = container_of(ser, struct rtw89_dev, ser);
359 if (!test_bit(RTW89_SER_HAL_STOP_DMA, ser->flags))
367 clear_bit(RTW89_SER_HAL_STOP_DMA, ser->flags);
375 static int hal_stop_dma(struct rtw89_ser *ser)
377 struct rtw89_dev *rtwdev = container_of(ser, struct rtw89_dev, ser);
385 set_bit(RTW89_SER_HAL_STOP_DMA, ser->flags);
393 static void hal_send_post_m0_event(struct rtw89_ser *ser)
395 struct rtw89_dev *rtwdev = container_of(ser, struct rtw89_dev, ser);
400 static void hal_send_m2_event(struct rtw89_ser *ser)
402 struct rtw89_dev *rtwdev = container_of(ser, struct rtw89_dev, ser);
407 static void hal_send_m4_event(struct rtw89_ser *ser)
409 struct rtw89_dev *rtwdev = container_of(ser, struct rtw89_dev, ser);
415 static void ser_idle_st_hdl(struct rtw89_ser *ser, u8 evt)
417 struct rtw89_dev *rtwdev = container_of(ser, struct rtw89_dev, ser);
426 ser_state_goto(ser, SER_L1_RESET_PRE_ST);
429 ser_state_goto(ser, SER_RESET_TRX_ST);
432 ser_state_goto(ser, SER_L2_RESET_ST);
443 static void ser_l1_reset_pre_st_hdl(struct rtw89_ser *ser, u8 evt)
447 ser->prehandle_l1 = true;
448 hal_send_post_m0_event(ser);
449 ser_set_alarm(ser, 1000, SER_EV_M1_TIMEOUT);
452 ser_state_goto(ser, SER_RESET_TRX_ST);
455 ser_state_goto(ser, SER_L2_RESET_ST);
458 ser_del_alarm(ser);
465 static void ser_reset_trx_st_hdl(struct rtw89_ser *ser, u8 evt)
467 struct rtw89_dev *rtwdev = container_of(ser, struct rtw89_dev, ser);
472 drv_stop_tx(ser);
474 if (hal_stop_dma(ser)) {
475 ser_state_goto(ser, SER_L2_RESET_ST);
479 drv_stop_rx(ser);
480 drv_trx_reset(ser);
483 hal_send_m2_event(ser);
486 ser_set_alarm(ser, 1000, SER_EV_M3_TIMEOUT);
490 ser_state_goto(ser, SER_DO_HCI_ST);
494 ser_state_goto(ser, SER_L2_RESET_ST);
498 ser_del_alarm(ser);
499 hal_enable_dma(ser);
500 drv_resume_rx(ser);
501 drv_resume_tx(ser);
511 static void ser_do_hci_st_hdl(struct rtw89_ser *ser, u8 evt)
516 hal_send_m4_event(ser);
519 ser_set_alarm(ser, 1000, SER_EV_FW_M5_TIMEOUT);
523 ser_state_goto(ser, SER_L2_RESET_ST);
527 ser_state_goto(ser, SER_IDLE_ST);
531 ser_del_alarm(ser);
659 static void ser_l2_reset_st_pre_hdl(struct rtw89_ser *ser)
661 struct rtw89_dev *rtwdev = container_of(ser, struct rtw89_dev, ser);
691 static void ser_l2_reset_st_hdl(struct rtw89_ser *ser, u8 evt)
693 struct rtw89_dev *rtwdev = container_of(ser, struct rtw89_dev, ser);
698 ser_l2_reset_st_pre_hdl(ser);
702 ser_set_alarm(ser, SER_RECFG_TIMEOUT, SER_EV_L2_RECFG_TIMEOUT);
706 rtw89_info(rtwdev, "Err: ser L2 re-config timeout\n");
709 ser_state_goto(ser, SER_IDLE_ST);
713 ser_del_alarm(ser);
749 struct rtw89_ser *ser = &rtwdev->ser;
751 memset(ser, 0, sizeof(*ser));
752 INIT_LIST_HEAD(&ser->msg_q);
753 ser->state = SER_IDLE_ST;
754 ser->st_tbl = ser_st_tbl;
755 ser->ev_tbl = ser_ev_tbl;
757 bitmap_zero(ser->flags, RTW89_NUM_OF_SER_FLAGS);
758 spin_lock_init(&ser->msg_q_lock);
759 INIT_WORK(&ser->ser_hdl_work, rtw89_ser_hdl_work);
760 INIT_DELAYED_WORK(&ser->ser_alarm_work, rtw89_ser_alarm_work);
766 struct rtw89_ser *ser = (struct rtw89_ser *)&rtwdev->ser;
768 set_bit(RTW89_SER_DRV_STOP_RUN, ser->flags);
769 cancel_delayed_work_sync(&ser->ser_alarm_work);
770 cancel_work_sync(&ser->ser_hdl_work);
771 clear_bit(RTW89_SER_DRV_STOP_RUN, ser->flags);
777 ser_send_msg(&rtwdev->ser, SER_EV_L2_RECFG_DONE);
818 ser_send_msg(&rtwdev->ser, event);