Commit d6f6b0d8 authored by Gregory Greenman's avatar Gregory Greenman Committed by Johannes Berg
Browse files

wifi: iwlwifi: mvm: add fw link id allocation



Driver uses link_id as an index in the array. FW currently can
support only 2 concurrently active links per vif with the ids in the
range 0-3. Add a mapping of dirver link ids to fw link id and track the
number of active link ids.

Signed-off-by: default avatarGregory Greenman <gregory.greenman@intel.com>
Link: https://lore.kernel.org/r/20230328104949.a53e5df49c33.I02b25648d2d5ca370c0697bf19d0d34724eae8a1@changeid


Signed-off-by: default avatarJohannes Berg <johannes.berg@intel.com>
parent 62e0ccb2
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -483,6 +483,12 @@ struct iwl_link_config_cmd {
	__le32 reserved1[8];
} __packed; /* LINK_CONTEXT_CONFIG_CMD_API_S_VER_1 */

/* Currently FW supports link ids in the range 0-3 and can have
 * at most two active links for each vif.
 */
#define IWL_MVM_FW_MAX_ACTIVE_LINKS_NUM 2
#define IWL_MVM_FW_MAX_LINK_ID 3

/**
 * enum iwl_fw_sta_type - FW station types
 * @STATION_TYPE_PEER: represents a peer - AP in BSS, a TDLS sta, a client in
+5 −1
Original line number Diff line number Diff line
@@ -1442,6 +1442,10 @@ static int _iwl_dbgfs_inject_beacon_ie(struct iwl_mvm *mvm, char *bin, int len)
			cpu_to_le16(iwl_mvm_mac_ctxt_get_beacon_flags(mvm->fw,
								      rate));
		beacon_cmd.byte_cnt = cpu_to_le16((u16)beacon->len);
		if (iwl_fw_lookup_cmd_ver(mvm->fw, BEACON_TEMPLATE_CMD, 0) > 12)
			beacon_cmd.link_id =
				cpu_to_le32(mvmvif->link[link_id]->fw_link_id);
		else
			beacon_cmd.link_id = cpu_to_le32((u32)mvmvif->id);

		iwl_mvm_mac_ctxt_set_tim(mvm, &beacon_cmd.tim_idx,
+2 −0
Original line number Diff line number Diff line
@@ -1573,6 +1573,8 @@ int iwl_mvm_up(struct iwl_mvm *mvm)
	for (i = 0; i < mvm->fw->ucode_capa.num_stations; i++)
		RCU_INIT_POINTER(mvm->fw_id_to_mac_id[i], NULL);

	memset(&mvm->fw_link_ids_map, 0, sizeof(mvm->fw_link_ids_map));

	mvm->tdls_cs.peer.sta_id = IWL_MVM_INVALID_STA;

	/* reset quota debouncing buffer - 0xff will yield invalid data */
+74 −13
Original line number Diff line number Diff line
// SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause
/*
 * Copyright (C) 2022 Intel Corporation
 * Copyright (C) 2022 - 2023 Intel Corporation
 */
#include "mvm.h"

static u32 iwl_mvm_get_free_fw_link_id(struct iwl_mvm *mvm,
				       struct iwl_mvm_vif *mvm_vif)
{
	u32 link_id;

	lockdep_assert_held(&mvm->mutex);

	link_id = ffz(mvm->fw_link_ids_map);

	/* this case can happen if there're deactivated but not removed links */
	if (link_id > IWL_MVM_FW_MAX_LINK_ID)
		return IWL_MVM_FW_LINK_ID_INVALID;

	mvm->fw_link_ids_map |= BIT(link_id);
	return link_id;
}

static void iwl_mvm_release_fw_link_id(struct iwl_mvm *mvm, u32 link_id)
{
	lockdep_assert_held(&mvm->mutex);

	if (!WARN_ON(link_id > IWL_MVM_FW_MAX_LINK_ID))
		mvm->fw_link_ids_map &= ~BIT(link_id);
}

static int iwl_mvm_link_cmd_send(struct iwl_mvm *mvm,
				 struct iwl_link_config_cmd *cmd,
				 enum iwl_ctxt_action action)
@@ -25,11 +50,19 @@ int iwl_mvm_add_link(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
{
	struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
	unsigned int link_id = link_conf->link_id;
	struct iwl_mvm_vif_link_info *link_info = mvmvif->link[link_id];
	struct iwl_link_config_cmd cmd = {};
	struct iwl_mvm_phy_ctxt *phyctxt;

	if (WARN_ON_ONCE(!mvmvif->link[link_id]))
	if (WARN_ON_ONCE(!link_info))
		return -EINVAL;

	if (link_info->fw_link_id == IWL_MVM_FW_LINK_ID_INVALID) {
		link_info->fw_link_id = iwl_mvm_get_free_fw_link_id(mvm,
								    mvmvif);
		if (link_info->fw_link_id == IWL_MVM_FW_LINK_ID_INVALID)
			return -EINVAL;
	}

	/* Update SF - Disable if needed. if this fails, SF might still be on
	 * while many macs are bound, which is forbidden - so fail the binding.
@@ -37,11 +70,10 @@ int iwl_mvm_add_link(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
	if (iwl_mvm_sf_update(mvm, vif, false))
		return -EINVAL;

	/* FIXME: add proper link id allocation */
	cmd.link_id = cpu_to_le32(mvmvif->id);
	cmd.link_id = cpu_to_le32(link_info->fw_link_id);
	cmd.mac_id = cpu_to_le32(mvmvif->id);
	/* P2P-Device already has a valid PHY context during add */
	phyctxt = mvmvif->link[link_id]->phy_ctxt;
	phyctxt = link_info->phy_ctxt;
	if (phyctxt)
		cmd.phy_id = cpu_to_le32(phyctxt->id);
	else
@@ -61,20 +93,27 @@ int iwl_mvm_link_changed(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
{
	struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
	unsigned int link_id = link_conf->link_id;
	struct iwl_mvm_vif_link_info *link_info = mvmvif->link[link_id];
	struct iwl_mvm_phy_ctxt *phyctxt;
	struct iwl_link_config_cmd cmd = {};
	u32 ht_flag, flags = 0, flags_mask = 0;
	int ret;

	if (WARN_ON_ONCE(!link_info ||
			 link_info->fw_link_id == IWL_MVM_FW_LINK_ID_INVALID))
		return -EINVAL;

	if (WARN_ON_ONCE(!mvmvif->link[link_id]))
	/* cannot activate third link */
	if (!link_info->active && active &&
	    mvmvif->fw_active_links_num >= IWL_MVM_FW_MAX_ACTIVE_LINKS_NUM)
		return -EINVAL;

	/* FIXME: add proper link id allocation */
	cmd.link_id = cpu_to_le32(mvmvif->id);
	cmd.link_id = cpu_to_le32(link_info->fw_link_id);

	/* The phy_id, link address and listen_lmac can be modified only until
	 * the link becomes active, otherwise they will be ignored.
	 */
	phyctxt = mvmvif->link[link_id]->phy_ctxt;
	phyctxt = link_info->phy_ctxt;
	if (phyctxt)
		cmd.phy_id = cpu_to_le32(phyctxt->id);
	else
@@ -151,7 +190,7 @@ int iwl_mvm_link_changed(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
	cmd.frame_time_rts_th = cpu_to_le16(link_conf->frame_time_rts_th);

	/* Block 26-tone RU OFDMA transmissions */
	if (mvmvif->deflink.he_ru_2mhz_block) {
	if (link_info->he_ru_2mhz_block) {
		flags |= LINK_FLG_RU_2MHZ_BLOCK;
		flags_mask |= LINK_FLG_RU_2MHZ_BLOCK;
	}
@@ -167,18 +206,40 @@ int iwl_mvm_link_changed(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
	cmd.flags = cpu_to_le32(flags);
	cmd.flags_mask = cpu_to_le32(flags_mask);

	return iwl_mvm_link_cmd_send(mvm, &cmd, FW_CTXT_ACTION_MODIFY);
	ret = iwl_mvm_link_cmd_send(mvm, &cmd, FW_CTXT_ACTION_MODIFY);
	if (!ret) {
		/* the FW is updated, so now it's possible to update the
		 * activation status. If activating a link, it was already
		 * checked above that we didn't reach the FW limit.
		 */
		if (link_info->active && !active)
			mvmvif->fw_active_links_num--;
		else if (!link_info->active && active)
			mvmvif->fw_active_links_num++;

		link_info->active = active;
	}

	return ret;
}

int iwl_mvm_remove_link(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
			struct ieee80211_bss_conf *link_conf)
{
	struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
	unsigned int link_id = link_conf->link_id;
	struct iwl_mvm_vif_link_info *link_info = mvmvif->link[link_id];
	struct iwl_link_config_cmd cmd = {};
	int ret;

	/* FIXME: add proper link id allocation */
	cmd.link_id = cpu_to_le32(mvmvif->id);
	if (WARN_ON(!link_info ||
		    link_info->fw_link_id == IWL_MVM_FW_LINK_ID_INVALID))
		return -EINVAL;

	cmd.link_id = cpu_to_le32(link_info->fw_link_id);
	iwl_mvm_release_fw_link_id(mvm, link_info->fw_link_id);
	link_info->fw_link_id = IWL_MVM_FW_LINK_ID_INVALID;

	ret = iwl_mvm_link_cmd_send(mvm, &cmd, FW_CTXT_ACTION_REMOVE);

	if (!ret)
+5 −1
Original line number Diff line number Diff line
@@ -1078,6 +1078,10 @@ static int iwl_mvm_mac_ctxt_send_beacon_v9(struct iwl_mvm *mvm,

	beacon_cmd.flags = cpu_to_le16(flags);
	beacon_cmd.byte_cnt = cpu_to_le16((u16)beacon->len);
	if (iwl_fw_lookup_cmd_ver(mvm->fw, BEACON_TEMPLATE_CMD, 0) > 12)
		beacon_cmd.link_id =
			cpu_to_le32(mvmvif->link[link_conf->link_id]->fw_link_id);
	else
		beacon_cmd.link_id = cpu_to_le32((u32)mvmvif->id);

	if (vif->type == NL80211_IFTYPE_AP)
Loading