Lines Matching +full:sync +full:- +full:mode
1 // SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause
2 /* Copyright(c) 2020-2022 Realtek Corporation
78 offset = (primary_freq - center_freq - 10) / 20; in rtw89_get_primary_chan_idx()
81 offset = (center_freq - primary_freq - 10) / 20; in rtw89_get_primary_chan_idx()
100 return (prisb_cal_ofst[bw] + pri_ch - central_ch) / 4; in rtw89_get_primary_sb_idx()
110 chan->channel = center_chan; in rtw89_chan_create()
111 chan->primary_channel = primary_chan; in rtw89_chan_create()
112 chan->band_type = band; in rtw89_chan_create()
113 chan->band_width = bandwidth; in rtw89_chan_create()
118 chan->freq = center_freq; in rtw89_chan_create()
119 chan->subband_type = rtw89_get_subband_type(band, center_chan); in rtw89_chan_create()
120 chan->pri_ch_idx = rtw89_get_primary_chan_idx(bandwidth, center_freq, in rtw89_chan_create()
122 chan->pri_sb_idx = rtw89_get_primary_sb_idx(center_chan, primary_chan, in rtw89_chan_create()
130 struct rtw89_hal *hal = &rtwdev->hal; in rtw89_assign_entity_chan()
131 struct rtw89_chan *chan = &hal->chanctx[idx].chan; in rtw89_assign_entity_chan()
132 struct rtw89_chan_rcd *rcd = &hal->chanctx[idx].rcd; in rtw89_assign_entity_chan()
135 rcd->prev_primary_channel = chan->primary_channel; in rtw89_assign_entity_chan()
136 rcd->prev_band_type = chan->band_type; in rtw89_assign_entity_chan()
137 band_changed = new->band_type != chan->band_type; in rtw89_assign_entity_chan()
138 rcd->band_changed = band_changed; in rtw89_assign_entity_chan()
149 struct rtw89_hal *hal = &rtwdev->hal; in rtw89_iterate_entity_chan()
154 lockdep_assert_held(&rtwdev->mutex); in rtw89_iterate_entity_chan()
156 for_each_set_bit(idx, hal->entity_map, NUM_OF_RTW89_CHANCTX) { in rtw89_iterate_entity_chan()
171 struct rtw89_hal *hal = &rtwdev->hal; in __rtw89_config_entity_chandef()
173 hal->chanctx[idx].chandef = *chandef; in __rtw89_config_entity_chandef()
176 set_bit(idx, hal->entity_map); in __rtw89_config_entity_chandef()
190 struct rtw89_hal *hal = &rtwdev->hal; in rtw89_config_roc_chandef()
194 cur = atomic_cmpxchg(&hal->roc_chanctx_idx, in rtw89_config_roc_chandef()
202 hal->roc_chandef = *chandef; in rtw89_config_roc_chandef()
204 cur = atomic_cmpxchg(&hal->roc_chanctx_idx, idx, in rtw89_config_roc_chandef()
228 struct rtw89_hal *hal = &rtwdev->hal; in rtw89_entity_init()
230 hal->entity_pause = false; in rtw89_entity_init()
231 bitmap_zero(hal->entity_map, NUM_OF_RTW89_CHANCTX); in rtw89_entity_init()
232 bitmap_zero(hal->changes, NUM_OF_RTW89_CHANCTX_CHANGES); in rtw89_entity_init()
233 atomic_set(&hal->roc_chanctx_idx, RTW89_CHANCTX_IDLE); in rtw89_entity_init()
240 struct rtw89_hal *hal = &rtwdev->hal; in rtw89_entity_calculate_weight()
245 for_each_set_bit(idx, hal->entity_map, NUM_OF_RTW89_CHANCTX) { in rtw89_entity_calculate_weight()
246 cfg = hal->chanctx[idx].cfg; in rtw89_entity_calculate_weight()
249 w->active_chanctxs = 1; in rtw89_entity_calculate_weight()
253 if (cfg->ref_count > 0) in rtw89_entity_calculate_weight()
254 w->active_chanctxs++; in rtw89_entity_calculate_weight()
258 if (rtwvif->chanctx_assigned) in rtw89_entity_calculate_weight()
259 w->active_roles++; in rtw89_entity_calculate_weight()
266 struct rtw89_hal *hal = &rtwdev->hal; in rtw89_entity_recalc()
269 enum rtw89_entity_mode mode; in rtw89_entity_recalc() local
273 lockdep_assert_held(&rtwdev->mutex); in rtw89_entity_recalc()
275 bitmap_copy(recalc_map, hal->entity_map, NUM_OF_RTW89_CHANCTX); in rtw89_entity_recalc()
289 mode = RTW89_ENTITY_MODE_SCC; in rtw89_entity_recalc()
299 mode = rtw89_get_entity_mode(rtwdev); in rtw89_entity_recalc()
300 if (mode == RTW89_ENTITY_MODE_MCC) in rtw89_entity_recalc()
303 mode = RTW89_ENTITY_MODE_MCC_PREPARE; in rtw89_entity_recalc()
318 if (hal->entity_pause) in rtw89_entity_recalc()
321 rtw89_set_entity_mode(rtwdev, mode); in rtw89_entity_recalc()
322 return mode; in rtw89_entity_recalc()
328 const struct rtw89_chip_info *chip = rtwdev->chip; in rtw89_chanctx_notify()
329 const struct rtw89_chanctx_listener *listener = chip->chanctx_listener; in rtw89_chanctx_notify()
336 if (!listener->callbacks[i]) in rtw89_chanctx_notify()
343 listener->callbacks[i](rtwdev, state); in rtw89_chanctx_notify()
349 enum rtw89_chip_gen chip_gen = rtwdev->chip->chip_gen; in rtw89_concurrent_via_mrc()
358 * immediately as long as iterator returns a non-zero value.
368 struct rtw89_mcc_info *mcc = &rtwdev->mcc; in rtw89_iterate_mcc_roles()
370 &mcc->role_ref, in rtw89_iterate_mcc_roles()
371 &mcc->role_aux, in rtw89_iterate_mcc_roles()
390 struct rtw89_vif *rtwvif = role->rtwvif; in rtw89_mcc_get_tbtt_ofst()
391 u32 bcn_intvl_us = ieee80211_tu_to_usec(role->beacon_interval); in rtw89_mcc_get_tbtt_ofst()
392 u64 sync_tsf = READ_ONCE(rtwvif->sync_bcn_tsf); in rtw89_mcc_get_tbtt_ofst()
401 div_u64_rem(tsf - sync_tsf, bcn_intvl_us, &remainder); in rtw89_mcc_get_tbtt_ofst()
408 struct rtw89_mcc_info *mcc = &rtwdev->mcc; in __mcc_fw_req_tsf()
409 struct rtw89_mcc_role *ref = &mcc->role_ref; in __mcc_fw_req_tsf()
410 struct rtw89_mcc_role *aux = &mcc->role_aux; in __mcc_fw_req_tsf()
415 req.group = mcc->group; in __mcc_fw_req_tsf()
416 req.macid_x = ref->rtwvif->mac_id; in __mcc_fw_req_tsf()
417 req.macid_y = aux->rtwvif->mac_id; in __mcc_fw_req_tsf()
433 struct rtw89_mcc_info *mcc = &rtwdev->mcc; in __mrc_fw_req_tsf()
434 struct rtw89_mcc_role *ref = &mcc->role_ref; in __mrc_fw_req_tsf()
435 struct rtw89_mcc_role *aux = &mcc->role_aux; in __mrc_fw_req_tsf()
443 arg.infos[0].band = ref->rtwvif->mac_idx; in __mrc_fw_req_tsf()
444 arg.infos[0].port = ref->rtwvif->port; in __mrc_fw_req_tsf()
445 arg.infos[1].band = aux->rtwvif->mac_idx; in __mrc_fw_req_tsf()
446 arg.infos[1].port = aux->rtwvif->port; in __mrc_fw_req_tsf()
463 struct rtw89_mcc_info *mcc = &rtwdev->mcc; in rtw89_mcc_get_bcn_ofst()
464 struct rtw89_mcc_role *ref = &mcc->role_ref; in rtw89_mcc_get_bcn_ofst()
465 struct rtw89_mcc_role *aux = &mcc->role_aux; in rtw89_mcc_get_bcn_ofst()
466 u32 bcn_intvl_ref_us = ieee80211_tu_to_usec(ref->beacon_interval); in rtw89_mcc_get_bcn_ofst()
485 return (tbtt_ofst_ref - tbtt_ofst_aux) / 1024; in rtw89_mcc_get_bcn_ofst()
495 if (idx >= ARRAY_SIZE(mcc_role->macid_bitmap)) in rtw89_mcc_role_fw_macid_bitmap_set_bit()
498 mcc_role->macid_bitmap[idx] |= BIT(pos); in rtw89_mcc_role_fw_macid_bitmap_set_bit()
508 for (i = 0; i < ARRAY_SIZE(mcc_role->macid_bitmap); i++) { in rtw89_mcc_role_fw_macid_bitmap_to_u32()
514 if (mcc_role->macid_bitmap[i] & BIT(j)) in rtw89_mcc_role_fw_macid_bitmap_to_u32()
525 struct rtw89_sta *rtwsta = (struct rtw89_sta *)sta->drv_priv; in rtw89_mcc_role_macid_sta_iter()
526 struct rtw89_vif *rtwvif = rtwsta->rtwvif; in rtw89_mcc_role_macid_sta_iter()
528 struct rtw89_vif *target = mcc_role->rtwvif; in rtw89_mcc_role_macid_sta_iter()
533 rtw89_mcc_role_fw_macid_bitmap_set_bit(mcc_role, rtwsta->mac_id); in rtw89_mcc_role_macid_sta_iter()
539 struct rtw89_vif *rtwvif = mcc_role->rtwvif; in rtw89_mcc_fill_role_macid_bitmap()
541 rtw89_mcc_role_fw_macid_bitmap_set_bit(mcc_role, rtwvif->mac_id); in rtw89_mcc_fill_role_macid_bitmap()
542 ieee80211_iterate_stations_atomic(rtwdev->hw, in rtw89_mcc_fill_role_macid_bitmap()
550 struct rtw89_mcc_policy *policy = &mcc_role->policy; in rtw89_mcc_fill_role_policy()
552 policy->c2h_rpt = RTW89_FW_MCC_C2H_RPT_ALL; in rtw89_mcc_fill_role_policy()
553 policy->tx_null_early = RTW89_MCC_DFLT_TX_NULL_EARLY; in rtw89_mcc_fill_role_policy()
554 policy->in_curr_ch = false; in rtw89_mcc_fill_role_policy()
555 policy->dis_sw_retry = true; in rtw89_mcc_fill_role_policy()
556 policy->sw_retry_count = false; in rtw89_mcc_fill_role_policy()
558 if (mcc_role->is_go) in rtw89_mcc_fill_role_policy()
559 policy->dis_tx_null = true; in rtw89_mcc_fill_role_policy()
561 policy->dis_tx_null = false; in rtw89_mcc_fill_role_policy()
567 struct ieee80211_vif *vif = rtwvif_to_vif(mcc_role->rtwvif); in rtw89_mcc_fill_role_limit()
569 u32 bcn_intvl_us = ieee80211_tu_to_usec(mcc_role->beacon_interval); in rtw89_mcc_fill_role_limit()
576 if (!mcc_role->is_go && !mcc_role->is_gc) in rtw89_mcc_fill_role_limit()
581 noa_desc = &vif->bss_conf.p2p_noa_attr.desc[i]; in rtw89_mcc_fill_role_limit()
582 if (noa_desc->count == 255) in rtw89_mcc_fill_role_limit()
589 start_time = le32_to_cpu(noa_desc->start_time); in rtw89_mcc_fill_role_limit()
590 interval = le32_to_cpu(noa_desc->interval); in rtw89_mcc_fill_role_limit()
591 duration = le32_to_cpu(noa_desc->duration); in rtw89_mcc_fill_role_limit()
600 ret = rtw89_mac_port_get_tsf(rtwdev, mcc_role->rtwvif, &tsf); in rtw89_mcc_fill_role_limit()
608 max_dur_us = interval - duration; in rtw89_mcc_fill_role_limit()
609 max_tob_us = max_dur_us - max_toa_us; in rtw89_mcc_fill_role_limit()
623 mcc_role->limit.max_toa = max_toa_us / 1024; in rtw89_mcc_fill_role_limit()
624 mcc_role->limit.max_tob = max_tob_us / 1024; in rtw89_mcc_fill_role_limit()
625 mcc_role->limit.max_dur = max_dur_us / 1024; in rtw89_mcc_fill_role_limit()
626 mcc_role->limit.enable = true; in rtw89_mcc_fill_role_limit()
630 mcc_role->limit.max_toa, mcc_role->limit.max_tob, in rtw89_mcc_fill_role_limit()
631 mcc_role->limit.max_dur); in rtw89_mcc_fill_role_limit()
642 role->rtwvif = rtwvif; in rtw89_mcc_fill_role()
643 role->beacon_interval = vif->bss_conf.beacon_int; in rtw89_mcc_fill_role()
645 if (!role->beacon_interval) { in rtw89_mcc_fill_role()
648 return -EINVAL; in rtw89_mcc_fill_role()
651 role->duration = role->beacon_interval / 2; in rtw89_mcc_fill_role()
653 chan = rtw89_chan_get(rtwdev, rtwvif->chanctx_idx); in rtw89_mcc_fill_role()
654 role->is_2ghz = chan->band_type == RTW89_BAND_2G; in rtw89_mcc_fill_role()
655 role->is_go = rtwvif->wifi_role == RTW89_WIFI_ROLE_P2P_GO; in rtw89_mcc_fill_role()
656 role->is_gc = rtwvif->wifi_role == RTW89_WIFI_ROLE_P2P_CLIENT; in rtw89_mcc_fill_role()
664 role->beacon_interval, role->is_2ghz, role->is_go, role->is_gc); in rtw89_mcc_fill_role()
670 struct rtw89_mcc_info *mcc = &rtwdev->mcc; in rtw89_mcc_fill_bt_role()
671 struct rtw89_mcc_bt_role *bt_role = &mcc->bt_role; in rtw89_mcc_fill_bt_role()
674 bt_role->duration = rtw89_coex_query_bt_req_len(rtwdev, RTW89_PHY_0); in rtw89_mcc_fill_bt_role()
677 bt_role->duration); in rtw89_mcc_fill_bt_role()
692 struct rtw89_vif *role_vif = sel->bind_vif[ordered_idx]; in rtw89_mcc_fill_role_iterator()
698 return -EINVAL; in rtw89_mcc_fill_role_iterator()
703 ordered_idx, role_vif->mac_id); in rtw89_mcc_fill_role_iterator()
719 if (!rtwvif->chanctx_assigned) in rtw89_mcc_fill_all_roles()
722 if (sel.bind_vif[rtwvif->chanctx_idx]) { in rtw89_mcc_fill_all_roles()
725 rtwvif->mac_id, rtwvif->chanctx_idx); in rtw89_mcc_fill_all_roles()
729 sel.bind_vif[rtwvif->chanctx_idx] = rtwvif; in rtw89_mcc_fill_all_roles()
743 struct rtw89_mcc_info *mcc = &rtwdev->mcc; in rtw89_mcc_assign_pattern()
744 struct rtw89_mcc_role *ref = &mcc->role_ref; in rtw89_mcc_assign_pattern()
745 struct rtw89_mcc_role *aux = &mcc->role_aux; in rtw89_mcc_assign_pattern()
746 struct rtw89_mcc_config *config = &mcc->config; in rtw89_mcc_assign_pattern()
747 struct rtw89_mcc_pattern *pattern = &config->pattern; in rtw89_mcc_assign_pattern()
751 new->tob_ref, new->toa_ref, new->tob_aux, new->toa_aux); in rtw89_mcc_assign_pattern()
754 memset(&pattern->courtesy, 0, sizeof(pattern->courtesy)); in rtw89_mcc_assign_pattern()
756 if (pattern->tob_aux <= 0 || pattern->toa_aux <= 0) { in rtw89_mcc_assign_pattern()
757 pattern->courtesy.macid_tgt = aux->rtwvif->mac_id; in rtw89_mcc_assign_pattern()
758 pattern->courtesy.macid_src = ref->rtwvif->mac_id; in rtw89_mcc_assign_pattern()
759 pattern->courtesy.slot_num = RTW89_MCC_DFLT_COURTESY_SLOT; in rtw89_mcc_assign_pattern()
760 pattern->courtesy.enable = true; in rtw89_mcc_assign_pattern()
761 } else if (pattern->tob_ref <= 0 || pattern->toa_ref <= 0) { in rtw89_mcc_assign_pattern()
762 pattern->courtesy.macid_tgt = ref->rtwvif->mac_id; in rtw89_mcc_assign_pattern()
763 pattern->courtesy.macid_src = aux->rtwvif->mac_id; in rtw89_mcc_assign_pattern()
764 pattern->courtesy.slot_num = RTW89_MCC_DFLT_COURTESY_SLOT; in rtw89_mcc_assign_pattern()
765 pattern->courtesy.enable = true; in rtw89_mcc_assign_pattern()
770 pattern->plan, pattern->courtesy.enable); in rtw89_mcc_assign_pattern()
772 if (!pattern->courtesy.enable) in rtw89_mcc_assign_pattern()
777 pattern->courtesy.macid_tgt, pattern->courtesy.macid_src, in rtw89_mcc_assign_pattern()
778 pattern->courtesy.slot_num); in rtw89_mcc_assign_pattern()
781 /* The follow-up roughly shows the relationship between the parameters
799 struct rtw89_mcc_info *mcc = &rtwdev->mcc; in __rtw89_mcc_calc_pattern_loose()
800 struct rtw89_mcc_role *ref = &mcc->role_ref; in __rtw89_mcc_calc_pattern_loose()
801 struct rtw89_mcc_role *aux = &mcc->role_aux; in __rtw89_mcc_calc_pattern_loose()
802 struct rtw89_mcc_config *config = &mcc->config; in __rtw89_mcc_calc_pattern_loose()
803 u16 bcn_ofst = config->beacon_offset; in __rtw89_mcc_calc_pattern_loose()
816 max_bcn_ofst = ref->duration + aux->duration; in __rtw89_mcc_calc_pattern_loose()
817 if (ref->limit.enable) in __rtw89_mcc_calc_pattern_loose()
819 ref->limit.max_toa + aux->duration); in __rtw89_mcc_calc_pattern_loose()
820 else if (aux->limit.enable) in __rtw89_mcc_calc_pattern_loose()
822 ref->duration + aux->limit.max_tob); in __rtw89_mcc_calc_pattern_loose()
824 if (bcn_ofst > max_bcn_ofst && bcn_ofst >= mcc->bt_role.duration) { in __rtw89_mcc_calc_pattern_loose()
825 bt_dur_in_mid = mcc->bt_role.duration; in __rtw89_mcc_calc_pattern_loose()
826 ptrn->plan = RTW89_MCC_PLAN_MID_BT; in __rtw89_mcc_calc_pattern_loose()
832 ptrn->plan, bcn_ofst); in __rtw89_mcc_calc_pattern_loose()
834 res = bcn_ofst - bt_dur_in_mid; in __rtw89_mcc_calc_pattern_loose()
835 upper = min_t(s16, ref->duration, res); in __rtw89_mcc_calc_pattern_loose()
838 if (ref->limit.enable) { in __rtw89_mcc_calc_pattern_loose()
839 upper = min_t(s16, upper, ref->limit.max_toa); in __rtw89_mcc_calc_pattern_loose()
840 lower = max_t(s16, lower, ref->duration - ref->limit.max_tob); in __rtw89_mcc_calc_pattern_loose()
841 } else if (aux->limit.enable) { in __rtw89_mcc_calc_pattern_loose()
843 res - (aux->duration - aux->limit.max_toa)); in __rtw89_mcc_calc_pattern_loose()
844 lower = max_t(s16, lower, res - aux->limit.max_tob); in __rtw89_mcc_calc_pattern_loose()
848 ptrn->toa_ref = (upper + lower) / 2; in __rtw89_mcc_calc_pattern_loose()
850 ptrn->toa_ref = lower; in __rtw89_mcc_calc_pattern_loose()
852 ptrn->tob_ref = ref->duration - ptrn->toa_ref; in __rtw89_mcc_calc_pattern_loose()
853 ptrn->tob_aux = res - ptrn->toa_ref; in __rtw89_mcc_calc_pattern_loose()
854 ptrn->toa_aux = aux->duration - ptrn->tob_aux; in __rtw89_mcc_calc_pattern_loose()
863 struct rtw89_mcc_info *mcc = &rtwdev->mcc; in __rtw89_mcc_calc_pattern_strict()
864 struct rtw89_mcc_role *ref = &mcc->role_ref; in __rtw89_mcc_calc_pattern_strict()
865 struct rtw89_mcc_role *aux = &mcc->role_aux; in __rtw89_mcc_calc_pattern_strict()
866 struct rtw89_mcc_config *config = &mcc->config; in __rtw89_mcc_calc_pattern_strict()
869 u16 bcn_ofst = config->beacon_offset; in __rtw89_mcc_calc_pattern_strict()
877 ptrn->plan, bcn_ofst); in __rtw89_mcc_calc_pattern_strict()
879 if (ptrn->plan == RTW89_MCC_PLAN_MID_BT) in __rtw89_mcc_calc_pattern_strict()
880 bt_dur_in_mid = mcc->bt_role.duration; in __rtw89_mcc_calc_pattern_strict()
884 if (ref->duration < min_tob + min_toa) { in __rtw89_mcc_calc_pattern_strict()
887 return -EINVAL; in __rtw89_mcc_calc_pattern_strict()
890 if (aux->duration < min_tob + min_toa) { in __rtw89_mcc_calc_pattern_strict()
893 return -EINVAL; in __rtw89_mcc_calc_pattern_strict()
896 res = bcn_ofst - min_toa - min_tob - bt_dur_in_mid; in __rtw89_mcc_calc_pattern_strict()
900 return -EINVAL; in __rtw89_mcc_calc_pattern_strict()
903 upper_toa_ref = min_t(s16, min_toa + res, ref->duration - min_tob); in __rtw89_mcc_calc_pattern_strict()
905 upper_tob_aux = min_t(s16, min_tob + res, aux->duration - min_toa); in __rtw89_mcc_calc_pattern_strict()
908 if (ref->limit.enable) { in __rtw89_mcc_calc_pattern_strict()
909 if (min_tob > ref->limit.max_tob || min_toa > ref->limit.max_toa) { in __rtw89_mcc_calc_pattern_strict()
912 return -EINVAL; in __rtw89_mcc_calc_pattern_strict()
915 upper_toa_ref = min_t(s16, upper_toa_ref, ref->limit.max_toa); in __rtw89_mcc_calc_pattern_strict()
917 ref->duration - ref->limit.max_tob); in __rtw89_mcc_calc_pattern_strict()
918 } else if (aux->limit.enable) { in __rtw89_mcc_calc_pattern_strict()
919 if (min_tob > aux->limit.max_tob || min_toa > aux->limit.max_toa) { in __rtw89_mcc_calc_pattern_strict()
922 return -EINVAL; in __rtw89_mcc_calc_pattern_strict()
925 upper_tob_aux = min_t(s16, upper_tob_aux, aux->limit.max_tob); in __rtw89_mcc_calc_pattern_strict()
927 aux->duration - aux->limit.max_toa); in __rtw89_mcc_calc_pattern_strict()
931 bcn_ofst - bt_dur_in_mid - lower_tob_aux); in __rtw89_mcc_calc_pattern_strict()
933 bcn_ofst - bt_dur_in_mid - upper_tob_aux); in __rtw89_mcc_calc_pattern_strict()
937 return -EINVAL; in __rtw89_mcc_calc_pattern_strict()
940 ptrn->toa_ref = (upper_toa_ref + lower_toa_ref) / 2; in __rtw89_mcc_calc_pattern_strict()
941 ptrn->tob_ref = ref->duration - ptrn->toa_ref; in __rtw89_mcc_calc_pattern_strict()
942 ptrn->tob_aux = bcn_ofst - ptrn->toa_ref - bt_dur_in_mid; in __rtw89_mcc_calc_pattern_strict()
943 ptrn->toa_aux = aux->duration - ptrn->tob_aux; in __rtw89_mcc_calc_pattern_strict()
949 struct rtw89_mcc_info *mcc = &rtwdev->mcc; in rtw89_mcc_calc_pattern()
950 struct rtw89_mcc_role *ref = &mcc->role_ref; in rtw89_mcc_calc_pattern()
951 struct rtw89_mcc_role *aux = &mcc->role_aux; in rtw89_mcc_calc_pattern()
957 if (ref->limit.enable && aux->limit.enable) { in rtw89_mcc_calc_pattern()
960 return -EINVAL; in rtw89_mcc_calc_pattern()
963 if (ref->limit.enable && in rtw89_mcc_calc_pattern()
964 ref->duration > ref->limit.max_tob + ref->limit.max_toa) { in rtw89_mcc_calc_pattern()
967 return -EINVAL; in rtw89_mcc_calc_pattern()
970 if (aux->limit.enable && in rtw89_mcc_calc_pattern()
971 aux->duration > aux->limit.max_tob + aux->limit.max_toa) { in rtw89_mcc_calc_pattern()
974 return -EINVAL; in rtw89_mcc_calc_pattern()
1009 struct rtw89_mcc_info *mcc = &rtwdev->mcc; in rtw89_mcc_set_default_pattern()
1010 struct rtw89_mcc_role *ref = &mcc->role_ref; in rtw89_mcc_set_default_pattern()
1011 struct rtw89_mcc_role *aux = &mcc->role_aux; in rtw89_mcc_set_default_pattern()
1018 tmp.tob_ref = ref->duration / 2; in rtw89_mcc_set_default_pattern()
1019 tmp.toa_ref = ref->duration - tmp.tob_ref; in rtw89_mcc_set_default_pattern()
1020 tmp.tob_aux = aux->duration / 2; in rtw89_mcc_set_default_pattern()
1021 tmp.toa_aux = aux->duration - tmp.tob_aux; in rtw89_mcc_set_default_pattern()
1030 struct rtw89_mcc_info *mcc = &rtwdev->mcc; in rtw89_mcc_set_duration_go_sta()
1031 struct rtw89_mcc_config *config = &mcc->config; in rtw89_mcc_set_duration_go_sta()
1032 u16 mcc_intvl = config->mcc_interval; in rtw89_mcc_set_duration_go_sta()
1035 dur_go = clamp_t(u16, role_go->duration, RTW89_MCC_MIN_GO_DURATION, in rtw89_mcc_set_duration_go_sta()
1036 mcc_intvl - RTW89_MCC_MIN_STA_DURATION); in rtw89_mcc_set_duration_go_sta()
1037 if (role_go->limit.enable) in rtw89_mcc_set_duration_go_sta()
1038 dur_go = min(dur_go, role_go->limit.max_dur); in rtw89_mcc_set_duration_go_sta()
1039 dur_sta = mcc_intvl - dur_go; in rtw89_mcc_set_duration_go_sta()
1042 "MCC set dur: (go, sta) {%d, %d} -> {%d, %d}\n", in rtw89_mcc_set_duration_go_sta()
1043 role_go->duration, role_sta->duration, dur_go, dur_sta); in rtw89_mcc_set_duration_go_sta()
1045 role_go->duration = dur_go; in rtw89_mcc_set_duration_go_sta()
1046 role_sta->duration = dur_sta; in rtw89_mcc_set_duration_go_sta()
1051 struct rtw89_mcc_info *mcc = &rtwdev->mcc; in rtw89_mcc_set_duration_gc_sta()
1052 struct rtw89_mcc_role *ref = &mcc->role_ref; in rtw89_mcc_set_duration_gc_sta()
1053 struct rtw89_mcc_role *aux = &mcc->role_aux; in rtw89_mcc_set_duration_gc_sta()
1054 struct rtw89_mcc_config *config = &mcc->config; in rtw89_mcc_set_duration_gc_sta()
1055 u16 mcc_intvl = config->mcc_interval; in rtw89_mcc_set_duration_gc_sta()
1058 if (ref->duration < RTW89_MCC_MIN_STA_DURATION) { in rtw89_mcc_set_duration_gc_sta()
1060 dur_aux = mcc_intvl - dur_ref; in rtw89_mcc_set_duration_gc_sta()
1061 } else if (aux->duration < RTW89_MCC_MIN_STA_DURATION) { in rtw89_mcc_set_duration_gc_sta()
1063 dur_ref = mcc_intvl - dur_aux; in rtw89_mcc_set_duration_gc_sta()
1065 dur_ref = ref->duration; in rtw89_mcc_set_duration_gc_sta()
1066 dur_aux = mcc_intvl - dur_ref; in rtw89_mcc_set_duration_gc_sta()
1069 if (ref->limit.enable) { in rtw89_mcc_set_duration_gc_sta()
1070 dur_ref = min(dur_ref, ref->limit.max_dur); in rtw89_mcc_set_duration_gc_sta()
1071 dur_aux = mcc_intvl - dur_ref; in rtw89_mcc_set_duration_gc_sta()
1072 } else if (aux->limit.enable) { in rtw89_mcc_set_duration_gc_sta()
1073 dur_aux = min(dur_aux, aux->limit.max_dur); in rtw89_mcc_set_duration_gc_sta()
1074 dur_ref = mcc_intvl - dur_aux; in rtw89_mcc_set_duration_gc_sta()
1078 "MCC set dur: (ref, aux) {%d ~ %d} -> {%d ~ %d}\n", in rtw89_mcc_set_duration_gc_sta()
1079 ref->duration, aux->duration, dur_ref, dur_aux); in rtw89_mcc_set_duration_gc_sta()
1081 ref->duration = dur_ref; in rtw89_mcc_set_duration_gc_sta()
1082 aux->duration = dur_aux; in rtw89_mcc_set_duration_gc_sta()
1101 p->parm[ordered_idx].dur = mcc_role->duration; in rtw89_mcc_mod_dur_get_iterator()
1103 if (mcc_role->is_go) in rtw89_mcc_mod_dur_get_iterator()
1108 p->parm[ordered_idx].room = max_t(s32, p->parm[ordered_idx].dur - min, 0); in rtw89_mcc_mod_dur_get_iterator()
1112 ordered_idx, p->parm[ordered_idx].dur, min, in rtw89_mcc_mod_dur_get_iterator()
1113 p->parm[ordered_idx].room); in rtw89_mcc_mod_dur_get_iterator()
1115 p->available += p->parm[ordered_idx].room; in rtw89_mcc_mod_dur_get_iterator()
1126 mcc_role->duration = p->parm[ordered_idx].dur; in rtw89_mcc_mod_dur_put_iterator()
1130 ordered_idx, p->parm[ordered_idx].dur); in rtw89_mcc_mod_dur_put_iterator()
1136 struct rtw89_mcc_info *mcc = &rtwdev->mcc; in rtw89_mcc_mod_duration_dual_2ghz_with_bt()
1137 struct rtw89_mcc_config *config = &mcc->config; in rtw89_mcc_mod_duration_dual_2ghz_with_bt()
1139 u16 mcc_intvl = config->mcc_interval; in rtw89_mcc_mod_duration_dual_2ghz_with_bt()
1140 u16 bt_dur = mcc->bt_role.duration; in rtw89_mcc_mod_duration_dual_2ghz_with_bt()
1150 wifi_dur = mcc_intvl - bt_dur; in rtw89_mcc_mod_duration_dual_2ghz_with_bt()
1153 data.parm[0].dur -= min_t(u16, bt_dur / 2, data.parm[0].room); in rtw89_mcc_mod_duration_dual_2ghz_with_bt()
1154 data.parm[1].dur = wifi_dur - data.parm[0].dur; in rtw89_mcc_mod_duration_dual_2ghz_with_bt()
1156 data.parm[1].dur -= min_t(u16, bt_dur / 2, data.parm[1].room); in rtw89_mcc_mod_duration_dual_2ghz_with_bt()
1157 data.parm[0].dur = wifi_dur - data.parm[1].dur; in rtw89_mcc_mod_duration_dual_2ghz_with_bt()
1163 mcc->bt_role.duration = bt_dur; in rtw89_mcc_mod_duration_dual_2ghz_with_bt()
1171 struct rtw89_mcc_info *mcc = &rtwdev->mcc; in rtw89_mcc_mod_duration_diff_band_with_bt()
1172 struct rtw89_mcc_config *config = &mcc->config; in rtw89_mcc_mod_duration_diff_band_with_bt()
1176 dur_2ghz = role_2ghz->duration; in rtw89_mcc_mod_duration_diff_band_with_bt()
1177 dur_non_2ghz = role_non_2ghz->duration; in rtw89_mcc_mod_duration_diff_band_with_bt()
1178 mcc_intvl = config->mcc_interval; in rtw89_mcc_mod_duration_diff_band_with_bt()
1179 bt_dur = mcc->bt_role.duration; in rtw89_mcc_mod_duration_diff_band_with_bt()
1196 dur_2ghz = mcc_intvl - dur_non_2ghz; in rtw89_mcc_mod_duration_diff_band_with_bt()
1198 if (role_non_2ghz->limit.enable) { in rtw89_mcc_mod_duration_diff_band_with_bt()
1201 role_non_2ghz->limit.max_dur); in rtw89_mcc_mod_duration_diff_band_with_bt()
1203 dur_non_2ghz = min(dur_non_2ghz, role_non_2ghz->limit.max_dur); in rtw89_mcc_mod_duration_diff_band_with_bt()
1204 dur_2ghz = mcc_intvl - dur_non_2ghz; in rtw89_mcc_mod_duration_diff_band_with_bt()
1211 role_2ghz->duration = dur_2ghz; in rtw89_mcc_mod_duration_diff_band_with_bt()
1212 role_non_2ghz->duration = dur_non_2ghz; in rtw89_mcc_mod_duration_diff_band_with_bt()
1217 struct rtw89_mcc_info *mcc = &rtwdev->mcc; in rtw89_mcc_duration_decision_on_bt()
1218 struct rtw89_mcc_role *ref = &mcc->role_ref; in rtw89_mcc_duration_decision_on_bt()
1219 struct rtw89_mcc_role *aux = &mcc->role_aux; in rtw89_mcc_duration_decision_on_bt()
1220 struct rtw89_mcc_bt_role *bt_role = &mcc->bt_role; in rtw89_mcc_duration_decision_on_bt()
1222 if (!bt_role->duration) in rtw89_mcc_duration_decision_on_bt()
1225 if (ref->is_2ghz && aux->is_2ghz) { in rtw89_mcc_duration_decision_on_bt()
1233 if (!ref->is_2ghz && !aux->is_2ghz) { in rtw89_mcc_duration_decision_on_bt()
1242 if (ref->is_2ghz) in rtw89_mcc_duration_decision_on_bt()
1255 struct rtw89_mcc_info *mcc = &rtwdev->mcc; in rtw89_mcc_sync_tbtt()
1256 struct rtw89_mcc_config *config = &mcc->config; in rtw89_mcc_sync_tbtt()
1257 u16 beacon_offset_us = ieee80211_tu_to_usec(config->beacon_offset); in rtw89_mcc_sync_tbtt()
1258 u32 bcn_intvl_src_us = ieee80211_tu_to_usec(src->beacon_interval); in rtw89_mcc_sync_tbtt()
1266 ret = rtw89_mac_port_get_tsf(rtwdev, src->rtwvif, &tsf_src); in rtw89_mcc_sync_tbtt()
1275 tbtt_tgt = tsf_src - cur_tbtt_ofst_src + beacon_offset_us; in rtw89_mcc_sync_tbtt()
1277 tbtt_tgt = tsf_src - cur_tbtt_ofst_src + in rtw89_mcc_sync_tbtt()
1278 (bcn_intvl_src_us - beacon_offset_us); in rtw89_mcc_sync_tbtt()
1281 tsf_ofst_tgt = bcn_intvl_src_us - remainder; in rtw89_mcc_sync_tbtt()
1283 config->sync.macid_tgt = tgt->rtwvif->mac_id; in rtw89_mcc_sync_tbtt()
1284 config->sync.band_tgt = tgt->rtwvif->mac_idx; in rtw89_mcc_sync_tbtt()
1285 config->sync.port_tgt = tgt->rtwvif->port; in rtw89_mcc_sync_tbtt()
1286 config->sync.macid_src = src->rtwvif->mac_id; in rtw89_mcc_sync_tbtt()
1287 config->sync.band_src = src->rtwvif->mac_idx; in rtw89_mcc_sync_tbtt()
1288 config->sync.port_src = src->rtwvif->port; in rtw89_mcc_sync_tbtt()
1289 config->sync.offset = tsf_ofst_tgt / 1024; in rtw89_mcc_sync_tbtt()
1290 config->sync.enable = true; in rtw89_mcc_sync_tbtt()
1293 "MCC sync tbtt: tgt %d, src %d, offset %d\n", in rtw89_mcc_sync_tbtt()
1294 config->sync.macid_tgt, config->sync.macid_src, in rtw89_mcc_sync_tbtt()
1295 config->sync.offset); in rtw89_mcc_sync_tbtt()
1297 rtw89_mac_port_tsf_sync(rtwdev, tgt->rtwvif, src->rtwvif, in rtw89_mcc_sync_tbtt()
1298 config->sync.offset); in rtw89_mcc_sync_tbtt()
1303 struct rtw89_mcc_info *mcc = &rtwdev->mcc; in rtw89_mcc_fill_start_tsf()
1304 struct rtw89_mcc_role *ref = &mcc->role_ref; in rtw89_mcc_fill_start_tsf()
1305 struct rtw89_mcc_config *config = &mcc->config; in rtw89_mcc_fill_start_tsf()
1306 u32 bcn_intvl_ref_us = ieee80211_tu_to_usec(ref->beacon_interval); in rtw89_mcc_fill_start_tsf()
1307 u32 tob_ref_us = ieee80211_tu_to_usec(config->pattern.tob_ref); in rtw89_mcc_fill_start_tsf()
1308 struct rtw89_vif *rtwvif = ref->rtwvif; in rtw89_mcc_fill_start_tsf()
1321 if (ref->is_go) in rtw89_mcc_fill_start_tsf()
1327 start_tsf = tsf - cur_tbtt_ofst + bcn_intvl_ref_us - tob_ref_us; in rtw89_mcc_fill_start_tsf()
1331 config->start_tsf = start_tsf; in rtw89_mcc_fill_start_tsf()
1337 struct rtw89_mcc_info *mcc = &rtwdev->mcc; in rtw89_mcc_fill_config()
1338 struct rtw89_mcc_role *ref = &mcc->role_ref; in rtw89_mcc_fill_config()
1339 struct rtw89_mcc_role *aux = &mcc->role_aux; in rtw89_mcc_fill_config()
1340 struct rtw89_mcc_config *config = &mcc->config; in rtw89_mcc_fill_config()
1346 switch (mcc->mode) { in rtw89_mcc_fill_config()
1348 config->beacon_offset = RTW89_MCC_DFLT_BCN_OFST_TIME; in rtw89_mcc_fill_config()
1349 if (ref->is_go) { in rtw89_mcc_fill_config()
1351 config->mcc_interval = ref->beacon_interval; in rtw89_mcc_fill_config()
1355 config->mcc_interval = aux->beacon_interval; in rtw89_mcc_fill_config()
1360 config->beacon_offset = rtw89_mcc_get_bcn_ofst(rtwdev); in rtw89_mcc_fill_config()
1361 config->mcc_interval = ref->beacon_interval; in rtw89_mcc_fill_config()
1365 rtw89_warn(rtwdev, "MCC unknown mode: %d\n", mcc->mode); in rtw89_mcc_fill_config()
1366 return -EFAULT; in rtw89_mcc_fill_config()
1384 struct rtw89_mcc_info *mcc = &rtwdev->mcc; in __mcc_fw_add_role()
1385 struct rtw89_mcc_config *config = &mcc->config; in __mcc_fw_add_role()
1386 struct rtw89_mcc_pattern *pattern = &config->pattern; in __mcc_fw_add_role()
1387 struct rtw89_mcc_courtesy *courtesy = &pattern->courtesy; in __mcc_fw_add_role()
1388 struct rtw89_mcc_policy *policy = &role->policy; in __mcc_fw_add_role()
1393 chan = rtw89_chan_get(rtwdev, role->rtwvif->chanctx_idx); in __mcc_fw_add_role()
1394 req.central_ch_seg0 = chan->channel; in __mcc_fw_add_role()
1395 req.primary_ch = chan->primary_channel; in __mcc_fw_add_role()
1396 req.bandwidth = chan->band_width; in __mcc_fw_add_role()
1397 req.ch_band_type = chan->band_type; in __mcc_fw_add_role()
1399 req.macid = role->rtwvif->mac_id; in __mcc_fw_add_role()
1400 req.group = mcc->group; in __mcc_fw_add_role()
1401 req.c2h_rpt = policy->c2h_rpt; in __mcc_fw_add_role()
1402 req.tx_null_early = policy->tx_null_early; in __mcc_fw_add_role()
1403 req.dis_tx_null = policy->dis_tx_null; in __mcc_fw_add_role()
1404 req.in_curr_ch = policy->in_curr_ch; in __mcc_fw_add_role()
1405 req.sw_retry_count = policy->sw_retry_count; in __mcc_fw_add_role()
1406 req.dis_sw_retry = policy->dis_sw_retry; in __mcc_fw_add_role()
1407 req.duration = role->duration; in __mcc_fw_add_role()
1410 if (courtesy->enable && courtesy->macid_src == req.macid) { in __mcc_fw_add_role()
1411 req.courtesy_target = courtesy->macid_tgt; in __mcc_fw_add_role()
1412 req.courtesy_num = courtesy->slot_num; in __mcc_fw_add_role()
1423 ret = rtw89_fw_h2c_mcc_macid_bitmap(rtwdev, mcc->group, in __mcc_fw_add_role()
1424 role->rtwvif->mac_id, in __mcc_fw_add_role()
1425 role->macid_bitmap); in __mcc_fw_add_role()
1439 struct rtw89_mcc_info *mcc = &rtwdev->mcc; in __mrc_fw_add_role()
1440 struct rtw89_mcc_role *ref = &mcc->role_ref; in __mrc_fw_add_role()
1441 struct rtw89_mcc_policy *policy = &role->policy; in __mrc_fw_add_role()
1445 slot_arg = &arg->slots[slot_idx]; in __mrc_fw_add_role()
1446 role->slot_idx = slot_idx; in __mrc_fw_add_role()
1448 slot_arg->duration = role->duration; in __mrc_fw_add_role()
1449 slot_arg->role_num = 1; in __mrc_fw_add_role()
1451 chan = rtw89_chan_get(rtwdev, role->rtwvif->chanctx_idx); in __mrc_fw_add_role()
1453 slot_arg->roles[0].role_type = RTW89_H2C_MRC_ROLE_WIFI; in __mrc_fw_add_role()
1454 slot_arg->roles[0].is_master = role == ref; in __mrc_fw_add_role()
1455 slot_arg->roles[0].band = chan->band_type; in __mrc_fw_add_role()
1456 slot_arg->roles[0].bw = chan->band_width; in __mrc_fw_add_role()
1457 slot_arg->roles[0].central_ch = chan->channel; in __mrc_fw_add_role()
1458 slot_arg->roles[0].primary_ch = chan->primary_channel; in __mrc_fw_add_role()
1459 slot_arg->roles[0].en_tx_null = !policy->dis_tx_null; in __mrc_fw_add_role()
1460 slot_arg->roles[0].null_early = policy->tx_null_early; in __mrc_fw_add_role()
1461 slot_arg->roles[0].macid = role->rtwvif->mac_id; in __mrc_fw_add_role()
1462 slot_arg->roles[0].macid_main_bitmap = in __mrc_fw_add_role()
1468 struct rtw89_mcc_info *mcc = &rtwdev->mcc; in __mcc_fw_add_bt_role()
1469 struct rtw89_mcc_bt_role *bt_role = &mcc->bt_role; in __mcc_fw_add_bt_role()
1473 req.group = mcc->group; in __mcc_fw_add_bt_role()
1474 req.duration = bt_role->duration; in __mcc_fw_add_bt_role()
1491 struct rtw89_mcc_info *mcc = &rtwdev->mcc; in __mrc_fw_add_bt_role()
1492 struct rtw89_mcc_bt_role *bt_role = &mcc->bt_role; in __mrc_fw_add_bt_role()
1493 struct rtw89_fw_mrc_add_slot_arg *slot_arg = &arg->slots[slot_idx]; in __mrc_fw_add_bt_role()
1495 slot_arg->duration = bt_role->duration; in __mrc_fw_add_bt_role()
1496 slot_arg->role_num = 1; in __mrc_fw_add_bt_role()
1498 slot_arg->roles[0].role_type = RTW89_H2C_MRC_ROLE_BT; in __mrc_fw_add_bt_role()
1503 struct rtw89_mcc_info *mcc = &rtwdev->mcc; in __mcc_fw_start()
1504 struct rtw89_mcc_role *ref = &mcc->role_ref; in __mcc_fw_start()
1505 struct rtw89_mcc_role *aux = &mcc->role_aux; in __mcc_fw_start()
1506 struct rtw89_mcc_config *config = &mcc->config; in __mcc_fw_start()
1507 struct rtw89_mcc_pattern *pattern = &config->pattern; in __mcc_fw_start()
1508 struct rtw89_mcc_sync *sync = &config->sync; in __mcc_fw_start() local
1513 req.old_group = mcc->group; in __mcc_fw_start()
1515 mcc->group = RTW89_MCC_NEXT_GROUP(mcc->group); in __mcc_fw_start()
1518 req.group = mcc->group; in __mcc_fw_start()
1520 switch (pattern->plan) { in __mcc_fw_start()
1558 rtw89_warn(rtwdev, "MCC unknown plan: %d\n", pattern->plan); in __mcc_fw_start()
1559 return -EFAULT; in __mcc_fw_start()
1562 if (sync->enable) { in __mcc_fw_start()
1563 ret = rtw89_fw_h2c_mcc_sync(rtwdev, req.group, sync->macid_src, in __mcc_fw_start()
1564 sync->macid_tgt, sync->offset); in __mcc_fw_start()
1567 "MCC h2c failed to trigger sync: %d\n", ret); in __mcc_fw_start()
1572 req.macid = ref->rtwvif->mac_id; in __mcc_fw_start()
1573 req.tsf_high = config->start_tsf >> 32; in __mcc_fw_start()
1574 req.tsf_low = config->start_tsf; in __mcc_fw_start()
1589 struct rtw89_mcc_info *mcc = &rtwdev->mcc; in __mrc_fw_add_courtesy()
1590 struct rtw89_mcc_role *ref = &mcc->role_ref; in __mrc_fw_add_courtesy()
1591 struct rtw89_mcc_role *aux = &mcc->role_aux; in __mrc_fw_add_courtesy()
1592 struct rtw89_mcc_config *config = &mcc->config; in __mrc_fw_add_courtesy()
1593 struct rtw89_mcc_pattern *pattern = &config->pattern; in __mrc_fw_add_courtesy()
1594 struct rtw89_mcc_courtesy *courtesy = &pattern->courtesy; in __mrc_fw_add_courtesy()
1598 if (!courtesy->enable) in __mrc_fw_add_courtesy()
1601 if (courtesy->macid_src == ref->rtwvif->mac_id) { in __mrc_fw_add_courtesy()
1602 slot_arg_src = &arg->slots[ref->slot_idx]; in __mrc_fw_add_courtesy()
1603 slot_idx_tgt = aux->slot_idx; in __mrc_fw_add_courtesy()
1605 slot_arg_src = &arg->slots[aux->slot_idx]; in __mrc_fw_add_courtesy()
1606 slot_idx_tgt = ref->slot_idx; in __mrc_fw_add_courtesy()
1609 slot_arg_src->courtesy_target = slot_idx_tgt; in __mrc_fw_add_courtesy()
1610 slot_arg_src->courtesy_period = courtesy->slot_num; in __mrc_fw_add_courtesy()
1611 slot_arg_src->courtesy_en = true; in __mrc_fw_add_courtesy()
1616 struct rtw89_mcc_info *mcc = &rtwdev->mcc; in __mrc_fw_start()
1617 struct rtw89_mcc_role *ref = &mcc->role_ref; in __mrc_fw_start()
1618 struct rtw89_mcc_role *aux = &mcc->role_aux; in __mrc_fw_start()
1619 struct rtw89_mcc_config *config = &mcc->config; in __mrc_fw_start()
1620 struct rtw89_mcc_pattern *pattern = &config->pattern; in __mrc_fw_start()
1621 struct rtw89_mcc_sync *sync = &config->sync; in __mrc_fw_start() local
1630 start_arg.old_sch_idx = mcc->group; in __mrc_fw_start()
1632 mcc->group = RTW89_MCC_NEXT_GROUP(mcc->group); in __mrc_fw_start()
1635 add_arg.sch_idx = mcc->group; in __mrc_fw_start()
1638 switch (pattern->plan) { in __mrc_fw_start()
1663 rtw89_warn(rtwdev, "MCC unknown plan: %d\n", pattern->plan); in __mrc_fw_start()
1664 return -EFAULT; in __mrc_fw_start()
1676 if (sync->enable) { in __mrc_fw_start()
1678 .offset = sync->offset, in __mrc_fw_start()
1680 .band = sync->band_src, in __mrc_fw_start()
1681 .port = sync->port_src, in __mrc_fw_start()
1684 .band = sync->band_tgt, in __mrc_fw_start()
1685 .port = sync->port_tgt, in __mrc_fw_start()
1692 "MRC h2c failed to trigger sync: %d\n", ret); in __mrc_fw_start()
1697 start_arg.sch_idx = mcc->group; in __mrc_fw_start()
1698 start_arg.start_tsf = config->start_tsf; in __mrc_fw_start()
1712 struct rtw89_mcc_info *mcc = &rtwdev->mcc; in __mcc_fw_set_duration_no_bt()
1713 struct rtw89_mcc_config *config = &mcc->config; in __mcc_fw_set_duration_no_bt()
1714 struct rtw89_mcc_sync *sync = &config->sync; in __mcc_fw_set_duration_no_bt() local
1715 struct rtw89_mcc_role *ref = &mcc->role_ref; in __mcc_fw_set_duration_no_bt()
1716 struct rtw89_mcc_role *aux = &mcc->role_aux; in __mcc_fw_set_duration_no_bt()
1718 .group = mcc->group, in __mcc_fw_set_duration_no_bt()
1720 .start_macid = ref->rtwvif->mac_id, in __mcc_fw_set_duration_no_bt()
1721 .macid_x = ref->rtwvif->mac_id, in __mcc_fw_set_duration_no_bt()
1722 .macid_y = aux->rtwvif->mac_id, in __mcc_fw_set_duration_no_bt()
1723 .duration_x = ref->duration, in __mcc_fw_set_duration_no_bt()
1724 .duration_y = aux->duration, in __mcc_fw_set_duration_no_bt()
1725 .start_tsf_high = config->start_tsf >> 32, in __mcc_fw_set_duration_no_bt()
1726 .start_tsf_low = config->start_tsf, in __mcc_fw_set_duration_no_bt()
1737 if (!sync->enable || !sync_changed) in __mcc_fw_set_duration_no_bt()
1740 ret = rtw89_fw_h2c_mcc_sync(rtwdev, mcc->group, sync->macid_src, in __mcc_fw_set_duration_no_bt()
1741 sync->macid_tgt, sync->offset); in __mcc_fw_set_duration_no_bt()
1744 "MCC h2c failed to trigger sync: %d\n", ret); in __mcc_fw_set_duration_no_bt()
1753 struct rtw89_mcc_info *mcc = &rtwdev->mcc; in __mrc_fw_set_duration_no_bt()
1754 struct rtw89_mcc_config *config = &mcc->config; in __mrc_fw_set_duration_no_bt()
1755 struct rtw89_mcc_sync *sync = &config->sync; in __mrc_fw_set_duration_no_bt() local
1756 struct rtw89_mcc_role *ref = &mcc->role_ref; in __mrc_fw_set_duration_no_bt()
1757 struct rtw89_mcc_role *aux = &mcc->role_aux; in __mrc_fw_set_duration_no_bt()
1759 .sch_idx = mcc->group, in __mrc_fw_set_duration_no_bt()
1760 .start_tsf = config->start_tsf, in __mrc_fw_set_duration_no_bt()
1763 .slot_idx = ref->slot_idx, in __mrc_fw_set_duration_no_bt()
1764 .duration = ref->duration, in __mrc_fw_set_duration_no_bt()
1767 .slot_idx = aux->slot_idx, in __mrc_fw_set_duration_no_bt()
1768 .duration = aux->duration, in __mrc_fw_set_duration_no_bt()
1772 .offset = sync->offset, in __mrc_fw_set_duration_no_bt()
1774 .band = sync->band_src, in __mrc_fw_set_duration_no_bt()
1775 .port = sync->port_src, in __mrc_fw_set_duration_no_bt()
1778 .band = sync->band_tgt, in __mrc_fw_set_duration_no_bt()
1779 .port = sync->port_tgt, in __mrc_fw_set_duration_no_bt()
1792 if (!sync->enable || !sync_changed) in __mrc_fw_set_duration_no_bt()
1798 "MRC h2c failed to trigger sync: %d\n", ret); in __mrc_fw_set_duration_no_bt()
1807 struct rtw89_mcc_info *mcc = &rtwdev->mcc; in rtw89_mcc_handle_beacon_noa()
1808 struct rtw89_mcc_role *ref = &mcc->role_ref; in rtw89_mcc_handle_beacon_noa()
1809 struct rtw89_mcc_role *aux = &mcc->role_aux; in rtw89_mcc_handle_beacon_noa()
1810 struct rtw89_mcc_config *config = &mcc->config; in rtw89_mcc_handle_beacon_noa()
1811 struct rtw89_mcc_pattern *pattern = &config->pattern; in rtw89_mcc_handle_beacon_noa()
1812 struct rtw89_mcc_sync *sync = &config->sync; in rtw89_mcc_handle_beacon_noa() local
1814 u64 start_time = config->start_tsf; in rtw89_mcc_handle_beacon_noa()
1815 u32 interval = config->mcc_interval; in rtw89_mcc_handle_beacon_noa()
1819 if (mcc->mode != RTW89_MCC_MODE_GO_STA) in rtw89_mcc_handle_beacon_noa()
1822 if (ref->is_go) { in rtw89_mcc_handle_beacon_noa()
1823 rtwvif_go = ref->rtwvif; in rtw89_mcc_handle_beacon_noa()
1824 start_time += ieee80211_tu_to_usec(ref->duration); in rtw89_mcc_handle_beacon_noa()
1825 duration = config->mcc_interval - ref->duration; in rtw89_mcc_handle_beacon_noa()
1826 } else if (aux->is_go) { in rtw89_mcc_handle_beacon_noa()
1827 rtwvif_go = aux->rtwvif; in rtw89_mcc_handle_beacon_noa()
1828 start_time += ieee80211_tu_to_usec(pattern->tob_ref) + in rtw89_mcc_handle_beacon_noa()
1829 ieee80211_tu_to_usec(config->beacon_offset) + in rtw89_mcc_handle_beacon_noa()
1830 ieee80211_tu_to_usec(pattern->toa_aux); in rtw89_mcc_handle_beacon_noa()
1831 duration = config->mcc_interval - aux->duration; in rtw89_mcc_handle_beacon_noa()
1834 start_time += ieee80211_tu_to_usec(sync->offset); in rtw89_mcc_handle_beacon_noa()
1852 if (!rtwvif_go->chanctx_assigned) in rtw89_mcc_handle_beacon_noa()
1860 struct rtw89_mcc_info *mcc = &rtwdev->mcc; in rtw89_mcc_start_beacon_noa()
1861 struct rtw89_mcc_role *ref = &mcc->role_ref; in rtw89_mcc_start_beacon_noa()
1862 struct rtw89_mcc_role *aux = &mcc->role_aux; in rtw89_mcc_start_beacon_noa()
1864 if (mcc->mode != RTW89_MCC_MODE_GO_STA) in rtw89_mcc_start_beacon_noa()
1867 if (ref->is_go) in rtw89_mcc_start_beacon_noa()
1868 rtw89_fw_h2c_tsf32_toggle(rtwdev, ref->rtwvif, true); in rtw89_mcc_start_beacon_noa()
1869 else if (aux->is_go) in rtw89_mcc_start_beacon_noa()
1870 rtw89_fw_h2c_tsf32_toggle(rtwdev, aux->rtwvif, true); in rtw89_mcc_start_beacon_noa()
1877 struct rtw89_mcc_info *mcc = &rtwdev->mcc; in rtw89_mcc_stop_beacon_noa()
1878 struct rtw89_mcc_role *ref = &mcc->role_ref; in rtw89_mcc_stop_beacon_noa()
1879 struct rtw89_mcc_role *aux = &mcc->role_aux; in rtw89_mcc_stop_beacon_noa()
1881 if (mcc->mode != RTW89_MCC_MODE_GO_STA) in rtw89_mcc_stop_beacon_noa()
1884 if (ref->is_go) in rtw89_mcc_stop_beacon_noa()
1885 rtw89_fw_h2c_tsf32_toggle(rtwdev, ref->rtwvif, false); in rtw89_mcc_stop_beacon_noa()
1886 else if (aux->is_go) in rtw89_mcc_stop_beacon_noa()
1887 rtw89_fw_h2c_tsf32_toggle(rtwdev, aux->rtwvif, false); in rtw89_mcc_stop_beacon_noa()
1894 struct rtw89_mcc_info *mcc = &rtwdev->mcc; in rtw89_mcc_start()
1895 struct rtw89_mcc_role *ref = &mcc->role_ref; in rtw89_mcc_start()
1896 struct rtw89_mcc_role *aux = &mcc->role_aux; in rtw89_mcc_start()
1899 if (rtwdev->scanning) in rtw89_mcc_start()
1900 rtw89_hw_scan_abort(rtwdev, rtwdev->scan_info.scanning_vif); in rtw89_mcc_start()
1910 if (ref->is_go || aux->is_go) in rtw89_mcc_start()
1911 mcc->mode = RTW89_MCC_MODE_GO_STA; in rtw89_mcc_start()
1913 mcc->mode = RTW89_MCC_MODE_GC_STA; in rtw89_mcc_start()
1915 rtw89_debug(rtwdev, RTW89_DBG_CHAN, "MCC sel mode: %d\n", mcc->mode); in rtw89_mcc_start()
1917 mcc->group = RTW89_MCC_DFLT_GROUP; in rtw89_mcc_start()
1945 sel->mac_id = mcc_role->rtwvif->mac_id; in rtw89_mcc_stop_sel_fill()
1946 sel->slot_idx = mcc_role->slot_idx; in rtw89_mcc_stop_sel_fill()
1956 if (!mcc_role->rtwvif->chanctx_assigned) in rtw89_mcc_stop_sel_iterator()
1965 struct rtw89_mcc_info *mcc = &rtwdev->mcc; in rtw89_mcc_stop()
1966 struct rtw89_mcc_role *ref = &mcc->role_ref; in rtw89_mcc_stop()
1977 ret = rtw89_fw_h2c_mrc_del(rtwdev, mcc->group, sel.slot_idx); in rtw89_mcc_stop()
1982 ret = rtw89_fw_h2c_stop_mcc(rtwdev, mcc->group, in rtw89_mcc_stop()
1988 ret = rtw89_fw_h2c_del_mcc_group(rtwdev, mcc->group, true); in rtw89_mcc_stop()
2001 struct rtw89_mcc_info *mcc = &rtwdev->mcc; in rtw89_mcc_update()
2002 struct rtw89_mcc_config *config = &mcc->config; in rtw89_mcc_update()
2007 if (rtwdev->scanning) in rtw89_mcc_update()
2008 rtw89_hw_scan_abort(rtwdev, rtwdev->scan_info.scanning_vif); in rtw89_mcc_update()
2017 config->pattern.plan != RTW89_MCC_PLAN_NO_BT) { in rtw89_mcc_update()
2026 if (memcmp(&old_cfg.sync, &config->sync, sizeof(old_cfg.sync)) == 0) in rtw89_mcc_update()
2046 struct rtw89_mcc_info *mcc = &rtwdev->mcc; in rtw89_mcc_track()
2047 struct rtw89_mcc_config *config = &mcc->config; in rtw89_mcc_track()
2048 struct rtw89_mcc_pattern *pattern = &config->pattern; in rtw89_mcc_track()
2053 if (mcc->mode != RTW89_MCC_MODE_GC_STA) in rtw89_mcc_track()
2057 if (bcn_ofst > config->beacon_offset) { in rtw89_mcc_track()
2058 diff = bcn_ofst - config->beacon_offset; in rtw89_mcc_track()
2059 if (pattern->tob_aux < 0) in rtw89_mcc_track()
2060 tolerance = -pattern->tob_aux; in rtw89_mcc_track()
2062 tolerance = pattern->toa_aux; in rtw89_mcc_track()
2064 diff = config->beacon_offset - bcn_ofst; in rtw89_mcc_track()
2065 if (pattern->toa_aux < 0) in rtw89_mcc_track()
2066 tolerance = -pattern->toa_aux; in rtw89_mcc_track()
2068 tolerance = pattern->tob_aux; in rtw89_mcc_track()
2080 struct rtw89_mcc_info *mcc = &rtwdev->mcc; in __mcc_fw_upd_macid_bitmap()
2083 ret = rtw89_fw_h2c_mcc_macid_bitmap(rtwdev, mcc->group, in __mcc_fw_upd_macid_bitmap()
2084 upd->rtwvif->mac_id, in __mcc_fw_upd_macid_bitmap()
2085 upd->macid_bitmap); in __mcc_fw_upd_macid_bitmap()
2099 struct rtw89_mcc_info *mcc = &rtwdev->mcc; in __mrc_fw_upd_macid_bitmap()
2108 arg.sch_idx = mcc->group; in __mrc_fw_upd_macid_bitmap()
2109 arg.macid = upd->rtwvif->mac_id; in __mrc_fw_upd_macid_bitmap()
2147 .rtwvif = mcc_role->rtwvif, in rtw89_mcc_upd_map_iterator()
2151 if (!mcc_role->is_go) in rtw89_mcc_upd_map_iterator()
2155 if (memcmp(mcc_role->macid_bitmap, upd.macid_bitmap, in rtw89_mcc_upd_map_iterator()
2156 sizeof(mcc_role->macid_bitmap)) == 0) in rtw89_mcc_upd_map_iterator()
2167 memcpy(mcc_role->macid_bitmap, upd.macid_bitmap, in rtw89_mcc_upd_map_iterator()
2168 sizeof(mcc_role->macid_bitmap)); in rtw89_mcc_upd_map_iterator()
2174 struct rtw89_mcc_info *mcc = &rtwdev->mcc; in rtw89_mcc_update_macid_bitmap()
2176 if (mcc->mode != RTW89_MCC_MODE_GO_STA) in rtw89_mcc_update_macid_bitmap()
2187 memset(&mcc_role->limit, 0, sizeof(mcc_role->limit)); in rtw89_mcc_upd_lmt_iterator()
2194 struct rtw89_mcc_info *mcc = &rtwdev->mcc; in rtw89_mcc_update_limit()
2196 if (mcc->mode != RTW89_MCC_MODE_GC_STA) in rtw89_mcc_update_limit()
2206 struct rtw89_hal *hal = &rtwdev->hal; in rtw89_chanctx_work()
2208 enum rtw89_entity_mode mode; in rtw89_chanctx_work() local
2213 mutex_lock(&rtwdev->mutex); in rtw89_chanctx_work()
2215 if (hal->entity_pause) { in rtw89_chanctx_work()
2216 mutex_unlock(&rtwdev->mutex); in rtw89_chanctx_work()
2221 if (test_and_clear_bit(i, hal->changes)) in rtw89_chanctx_work()
2225 mode = rtw89_get_entity_mode(rtwdev); in rtw89_chanctx_work()
2226 switch (mode) { in rtw89_chanctx_work()
2258 mutex_unlock(&rtwdev->mutex); in rtw89_chanctx_work()
2264 struct rtw89_hal *hal = &rtwdev->hal; in rtw89_queue_chanctx_change()
2265 enum rtw89_entity_mode mode; in rtw89_queue_chanctx_change() local
2268 mode = rtw89_get_entity_mode(rtwdev); in rtw89_queue_chanctx_change()
2269 switch (mode) { in rtw89_queue_chanctx_change()
2283 set_bit(change, hal->changes); in rtw89_queue_chanctx_change()
2287 "queue chanctx work for mode %d with delay %d us\n", in rtw89_queue_chanctx_change()
2288 mode, delay); in rtw89_queue_chanctx_change()
2289 ieee80211_queue_delayed_work(rtwdev->hw, &rtwdev->chanctx_work, in rtw89_queue_chanctx_change()
2300 struct rtw89_hal *hal = &rtwdev->hal; in rtw89_chanctx_track()
2301 enum rtw89_entity_mode mode; in rtw89_chanctx_track() local
2303 lockdep_assert_held(&rtwdev->mutex); in rtw89_chanctx_track()
2305 if (hal->entity_pause) in rtw89_chanctx_track()
2308 mode = rtw89_get_entity_mode(rtwdev); in rtw89_chanctx_track()
2309 switch (mode) { in rtw89_chanctx_track()
2321 struct rtw89_hal *hal = &rtwdev->hal; in rtw89_chanctx_pause()
2322 enum rtw89_entity_mode mode; in rtw89_chanctx_pause() local
2324 lockdep_assert_held(&rtwdev->mutex); in rtw89_chanctx_pause()
2326 if (hal->entity_pause) in rtw89_chanctx_pause()
2331 mode = rtw89_get_entity_mode(rtwdev); in rtw89_chanctx_pause()
2332 switch (mode) { in rtw89_chanctx_pause()
2340 hal->entity_pause = true; in rtw89_chanctx_pause()
2345 struct rtw89_hal *hal = &rtwdev->hal; in rtw89_chanctx_proceed()
2346 enum rtw89_entity_mode mode; in rtw89_chanctx_proceed() local
2349 lockdep_assert_held(&rtwdev->mutex); in rtw89_chanctx_proceed()
2351 if (!hal->entity_pause) in rtw89_chanctx_proceed()
2356 hal->entity_pause = false; in rtw89_chanctx_proceed()
2359 mode = rtw89_get_entity_mode(rtwdev); in rtw89_chanctx_proceed()
2360 switch (mode) { in rtw89_chanctx_proceed()
2377 struct rtw89_hal *hal = &rtwdev->hal; in rtw89_swap_chanctx()
2384 hal->chanctx[idx1].cfg->idx = idx2; in rtw89_swap_chanctx()
2385 hal->chanctx[idx2].cfg->idx = idx1; in rtw89_swap_chanctx()
2387 swap(hal->chanctx[idx1], hal->chanctx[idx2]); in rtw89_swap_chanctx()
2390 if (!rtwvif->chanctx_assigned) in rtw89_swap_chanctx()
2392 if (rtwvif->chanctx_idx == idx1) in rtw89_swap_chanctx()
2393 rtwvif->chanctx_idx = idx2; in rtw89_swap_chanctx()
2394 else if (rtwvif->chanctx_idx == idx2) in rtw89_swap_chanctx()
2395 rtwvif->chanctx_idx = idx1; in rtw89_swap_chanctx()
2398 cur = atomic_read(&hal->roc_chanctx_idx); in rtw89_swap_chanctx()
2400 atomic_set(&hal->roc_chanctx_idx, idx2); in rtw89_swap_chanctx()
2402 atomic_set(&hal->roc_chanctx_idx, idx1); in rtw89_swap_chanctx()
2408 struct rtw89_hal *hal = &rtwdev->hal; in rtw89_chanctx_ops_add()
2409 struct rtw89_chanctx_cfg *cfg = (struct rtw89_chanctx_cfg *)ctx->drv_priv; in rtw89_chanctx_ops_add()
2410 const struct rtw89_chip_info *chip = rtwdev->chip; in rtw89_chanctx_ops_add()
2413 idx = find_first_zero_bit(hal->entity_map, NUM_OF_RTW89_CHANCTX); in rtw89_chanctx_ops_add()
2414 if (idx >= chip->support_chanctx_num) in rtw89_chanctx_ops_add()
2415 return -ENOENT; in rtw89_chanctx_ops_add()
2417 rtw89_config_entity_chandef(rtwdev, idx, &ctx->def); in rtw89_chanctx_ops_add()
2418 cfg->idx = idx; in rtw89_chanctx_ops_add()
2419 cfg->ref_count = 0; in rtw89_chanctx_ops_add()
2420 hal->chanctx[idx].cfg = cfg; in rtw89_chanctx_ops_add()
2427 struct rtw89_hal *hal = &rtwdev->hal; in rtw89_chanctx_ops_remove()
2428 struct rtw89_chanctx_cfg *cfg = (struct rtw89_chanctx_cfg *)ctx->drv_priv; in rtw89_chanctx_ops_remove()
2430 clear_bit(cfg->idx, hal->entity_map); in rtw89_chanctx_ops_remove()
2437 struct rtw89_chanctx_cfg *cfg = (struct rtw89_chanctx_cfg *)ctx->drv_priv; in rtw89_chanctx_ops_change()
2438 u8 idx = cfg->idx; in rtw89_chanctx_ops_change()
2441 rtw89_config_entity_chandef(rtwdev, idx, &ctx->def); in rtw89_chanctx_ops_change()
2450 struct rtw89_chanctx_cfg *cfg = (struct rtw89_chanctx_cfg *)ctx->drv_priv; in rtw89_chanctx_ops_assign_vif()
2453 rtwvif->chanctx_idx = cfg->idx; in rtw89_chanctx_ops_assign_vif()
2454 rtwvif->chanctx_assigned = true; in rtw89_chanctx_ops_assign_vif()
2455 cfg->ref_count++; in rtw89_chanctx_ops_assign_vif()
2457 if (cfg->idx == RTW89_CHANCTX_0) in rtw89_chanctx_ops_assign_vif()
2465 rtw89_swap_chanctx(rtwdev, cfg->idx, RTW89_CHANCTX_0); in rtw89_chanctx_ops_assign_vif()
2475 struct rtw89_chanctx_cfg *cfg = (struct rtw89_chanctx_cfg *)ctx->drv_priv; in rtw89_chanctx_ops_unassign_vif()
2476 struct rtw89_hal *hal = &rtwdev->hal; in rtw89_chanctx_ops_unassign_vif()
2482 rtwvif->chanctx_idx = RTW89_CHANCTX_0; in rtw89_chanctx_ops_unassign_vif()
2483 rtwvif->chanctx_assigned = false; in rtw89_chanctx_ops_unassign_vif()
2484 cfg->ref_count--; in rtw89_chanctx_ops_unassign_vif()
2486 if (cfg->ref_count != 0) in rtw89_chanctx_ops_unassign_vif()
2489 if (cfg->idx != RTW89_CHANCTX_0) in rtw89_chanctx_ops_unassign_vif()
2492 roll = find_next_bit(hal->entity_map, NUM_OF_RTW89_CHANCTX, in rtw89_chanctx_ops_unassign_vif()
2493 cfg->idx + 1); in rtw89_chanctx_ops_unassign_vif()
2501 rtw89_swap_chanctx(rtwdev, cfg->idx, roll); in rtw89_chanctx_ops_unassign_vif()
2504 if (!hal->entity_pause) { in rtw89_chanctx_ops_unassign_vif()
2519 if (hal->entity_pause) in rtw89_chanctx_ops_unassign_vif()
2525 /* re-plan MCC for chanctx changes. */ in rtw89_chanctx_ops_unassign_vif()