xref: /linux/drivers/net/wireless/nxp/nxpwifi/11n.h (revision 91ec2035134982b98fab0609a9fd8480e8217dc1)
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /*
3  * nxpwifi: 802.11n support
4  *
5  * Copyright 2011-2024 NXP
6  */
7 
8 #ifndef _NXPWIFI_11N_H_
9 #define _NXPWIFI_11N_H_
10 
11 #include "11n_aggr.h"
12 #include "11n_rxreorder.h"
13 #include "wmm.h"
14 
15 int nxpwifi_ret_11n_delba(struct nxpwifi_private *priv,
16 			  struct host_cmd_ds_command *resp);
17 int nxpwifi_ret_11n_addba_req(struct nxpwifi_private *priv,
18 			      struct host_cmd_ds_command *resp);
19 int nxpwifi_cmd_11n_cfg(struct nxpwifi_private *priv,
20 			struct host_cmd_ds_command *cmd, u16 cmd_action,
21 			struct nxpwifi_ds_11n_tx_cfg *txcfg);
22 int nxpwifi_cmd_append_11n_tlv(struct nxpwifi_private *priv,
23 			       struct nxpwifi_bssdescriptor *bss_desc,
24 			       u8 **buffer);
25 int nxpwifi_fill_cap_info(struct nxpwifi_private *priv, u8 radio_type,
26 			  struct ieee80211_ht_cap *ht_cap);
27 int nxpwifi_set_get_11n_htcap_cfg(struct nxpwifi_private *priv,
28 				  u16 action, int *htcap_cfg);
29 void nxpwifi_11n_delete_tx_ba_stream_tbl_entry(struct nxpwifi_private *priv,
30 					       struct nxpwifi_tx_ba_stream_tbl
31 					       *tx_tbl);
32 void nxpwifi_11n_delete_all_tx_ba_stream_tbl(struct nxpwifi_private *priv);
33 struct nxpwifi_tx_ba_stream_tbl *nxpwifi_get_ba_tbl(struct nxpwifi_private
34 						    *priv, int tid, u8 *ra);
35 void nxpwifi_create_ba_tbl(struct nxpwifi_private *priv, u8 *ra, int tid,
36 			   enum nxpwifi_ba_status ba_status);
37 int nxpwifi_send_addba(struct nxpwifi_private *priv, int tid, u8 *peer_mac);
38 int nxpwifi_send_delba(struct nxpwifi_private *priv, int tid, u8 *peer_mac,
39 		       int initiator);
40 void nxpwifi_11n_delete_ba_stream(struct nxpwifi_private *priv, u8 *del_ba);
41 int nxpwifi_get_rx_reorder_tbl(struct nxpwifi_private *priv,
42 			       struct nxpwifi_ds_rx_reorder_tbl *buf);
43 int nxpwifi_get_tx_ba_stream_tbl(struct nxpwifi_private *priv,
44 				 struct nxpwifi_ds_tx_ba_stream_tbl *buf);
45 int nxpwifi_cmd_recfg_tx_buf(struct nxpwifi_private *priv,
46 			     struct host_cmd_ds_command *cmd,
47 			     int cmd_action, u16 *buf_size);
48 int nxpwifi_cmd_amsdu_aggr_ctrl(struct host_cmd_ds_command *cmd,
49 				int cmd_action,
50 				struct nxpwifi_ds_11n_amsdu_aggr_ctrl *aa_ctrl);
51 void nxpwifi_del_tx_ba_stream_tbl_by_ra(struct nxpwifi_private *priv, u8 *ra);
52 u8 nxpwifi_get_sec_chan_offset(int chan);
53 
54 static inline bool
nxpwifi_is_station_ampdu_allowed(struct nxpwifi_private * priv,struct nxpwifi_ra_list_tbl * ptr,int tid)55 nxpwifi_is_station_ampdu_allowed(struct nxpwifi_private *priv,
56 				 struct nxpwifi_ra_list_tbl *ptr, int tid)
57 {
58 	struct nxpwifi_sta_node *node;
59 
60 	guard(rcu)();
61 	node = nxpwifi_get_sta_entry(priv, ptr->ra);
62 	if (unlikely(!node))
63 		return false;
64 
65 	if (node->ampdu_sta[tid] == BA_STREAM_NOT_ALLOWED)
66 		return false;
67 
68 	return true;
69 }
70 
71 /* Check if AMPDU is allowed for the given TID. */
72 static inline bool
nxpwifi_is_ampdu_allowed(struct nxpwifi_private * priv,struct nxpwifi_ra_list_tbl * ptr,int tid)73 nxpwifi_is_ampdu_allowed(struct nxpwifi_private *priv,
74 			 struct nxpwifi_ra_list_tbl *ptr, int tid)
75 {
76 	if (is_broadcast_ether_addr(ptr->ra))
77 		return false;
78 
79 	if (GET_BSS_ROLE(priv) == NXPWIFI_BSS_ROLE_UAP)
80 		return nxpwifi_is_station_ampdu_allowed(priv, ptr, tid);
81 
82 	return priv->aggr_prio_tbl[tid].ampdu_ap != BA_STREAM_NOT_ALLOWED;
83 }
84 
85 /* Check if AMSDU is allowed for the given TID. */
86 static inline bool
nxpwifi_is_amsdu_allowed(struct nxpwifi_private * priv,int tid)87 nxpwifi_is_amsdu_allowed(struct nxpwifi_private *priv, int tid)
88 {
89 	bool amsdu_enabled = priv->aggr_prio_tbl[tid].amsdu != BA_STREAM_NOT_ALLOWED;
90 	bool rate_ok = priv->is_data_rate_auto || !(priv->bitmap_rates[2] & 0x03);
91 
92 	return amsdu_enabled && rate_ok;
93 }
94 
95 /* Check if there is available space for a new BA stream. */
96 static inline bool
nxpwifi_space_avail_for_new_ba_stream(struct nxpwifi_adapter * adapter)97 nxpwifi_space_avail_for_new_ba_stream(struct nxpwifi_adapter *adapter)
98 {
99 	struct nxpwifi_private *priv;
100 	u8 i, j;
101 	size_t ba_stream_num = 0;
102 	size_t ba_stream_max = NXPWIFI_MAX_TX_BASTREAM_SUPPORTED;
103 
104 	if (adapter->fw_api_ver == NXPWIFI_FW_V15) {
105 		ba_stream_max = GETSUPP_TXBASTREAMS(adapter->hw_dot_11n_dev_cap);
106 		if (!ba_stream_max)
107 			ba_stream_max = NXPWIFI_MAX_TX_BASTREAM_SUPPORTED;
108 	}
109 
110 	for (i = 0; i < adapter->priv_num; i++) {
111 		priv = adapter->priv[i];
112 		for (j = 0; j < MAX_NUM_TID; j++)
113 			ba_stream_num += list_count_nodes(&priv->tx_ba_stream_tbl_ptr[j]);
114 	}
115 
116 	return ba_stream_num < ba_stream_max;
117 }
118 
119 /* Find the Tx BA stream to delete and return its TID and RA. */
120 static inline bool
nxpwifi_find_stream_to_delete(struct nxpwifi_private * priv,int ptr_tid,int * ptid,u8 * ra)121 nxpwifi_find_stream_to_delete(struct nxpwifi_private *priv, int ptr_tid,
122 			      int *ptid, u8 *ra)
123 {
124 	int search_tid = priv->aggr_prio_tbl[ptr_tid].ampdu_user;
125 	bool found = false;
126 	struct nxpwifi_tx_ba_stream_tbl *tx_tbl;
127 	int candidate_tid;
128 
129 	spin_lock_bh(&priv->tx_ba_stream_tbl_lock[ptr_tid]);
130 
131 	list_for_each_entry(tx_tbl, &priv->tx_ba_stream_tbl_ptr[ptr_tid], list) {
132 		candidate_tid = priv->aggr_prio_tbl[tx_tbl->tid].ampdu_user;
133 
134 		if (search_tid > candidate_tid) {
135 			search_tid = candidate_tid;
136 			*ptid = tx_tbl->tid;
137 			memcpy(ra, tx_tbl->ra, ETH_ALEN);
138 			found = true;
139 		}
140 	}
141 
142 	spin_unlock_bh(&priv->tx_ba_stream_tbl_lock[ptr_tid]);
143 
144 	return found;
145 }
146 
147 /* Check whether the associated station is 11n enabled. */
nxpwifi_is_sta_11n_enabled(struct nxpwifi_private * priv,struct nxpwifi_sta_node * node)148 static inline int nxpwifi_is_sta_11n_enabled(struct nxpwifi_private *priv,
149 					     struct nxpwifi_sta_node *node)
150 {
151 	if (!node || (priv->bss_role == NXPWIFI_BSS_ROLE_UAP &&
152 		      !priv->ap_11n_enabled))
153 		return 0;
154 
155 	return node->is_11n_enabled;
156 }
157 
158 #endif /* !_NXPWIFI_11N_H_ */
159