hc
2024-01-03 2f7c68cb55ecb7331f2381deb497c27155f32faf
kernel/drivers/net/wireless/intel/iwlwifi/mvm/phy-ctxt.c
....@@ -7,8 +7,8 @@
77 *
88 * Copyright(c) 2012 - 2014 Intel Corporation. All rights reserved.
99 * Copyright(c) 2013 - 2014 Intel Mobile Communications GmbH
10
- * Copyright(c) 2017 Intel Deutschland GmbH
11
- * Copyright(c) 2018 Intel Corporation
10
+ * Copyright(c) 2017 Intel Deutschland GmbH
11
+ * Copyright(c) 2018 - 2020 Intel Corporation
1212 *
1313 * This program is free software; you can redistribute it and/or modify
1414 * it under the terms of version 2 of the GNU General Public License as
....@@ -30,7 +30,7 @@
3030 *
3131 * Copyright(c) 2012 - 2014 Intel Corporation. All rights reserved.
3232 * Copyright(c) 2013 - 2014 Intel Mobile Communications GmbH
33
- * Copyright(c) 2018 Intel Corporation
33
+ * Copyright(c) 2018 - 2020 Intel Corporation
3434 * All rights reserved.
3535 *
3636 * Redistribution and use in source and binary forms, with or without
....@@ -109,6 +109,7 @@
109109 return PHY_VHT_CTRL_POS_4_ABOVE;
110110 default:
111111 WARN(1, "Invalid channel definition");
112
+ /* fall through */
112113 case 0:
113114 /*
114115 * The FW is expected to check the control channel position only
....@@ -124,33 +125,19 @@
124125 */
125126 static void iwl_mvm_phy_ctxt_cmd_hdr(struct iwl_mvm_phy_ctxt *ctxt,
126127 struct iwl_phy_context_cmd *cmd,
127
- u32 action, u32 apply_time)
128
+ u32 action)
128129 {
129
- memset(cmd, 0, sizeof(struct iwl_phy_context_cmd));
130
-
131130 cmd->id_and_color = cpu_to_le32(FW_CMD_ID_AND_COLOR(ctxt->id,
132131 ctxt->color));
133132 cmd->action = cpu_to_le32(action);
134
- cmd->apply_time = cpu_to_le32(apply_time);
135133 }
136134
137
-/*
138
- * Add the phy configuration to the PHY context command
139
- */
140
-static void iwl_mvm_phy_ctxt_cmd_data(struct iwl_mvm *mvm,
141
- struct iwl_phy_context_cmd *cmd,
142
- struct cfg80211_chan_def *chandef,
143
- u8 chains_static, u8 chains_dynamic)
135
+static void iwl_mvm_phy_ctxt_set_rxchain(struct iwl_mvm *mvm,
136
+ __le32 *rxchain_info,
137
+ u8 chains_static,
138
+ u8 chains_dynamic)
144139 {
145140 u8 active_cnt, idle_cnt;
146
-
147
- /* Set the channel info data */
148
- cmd->ci.band = (chandef->chan->band == NL80211_BAND_2GHZ ?
149
- PHY_BAND_24 : PHY_BAND_5);
150
-
151
- cmd->ci.channel = chandef->chan->hw_value;
152
- cmd->ci.width = iwl_mvm_get_channel_width(chandef);
153
- cmd->ci.ctrl_pos = iwl_mvm_get_ctrl_pos(chandef);
154141
155142 /* Set rx the chains */
156143 idle_cnt = chains_static;
....@@ -168,17 +155,53 @@
168155 active_cnt = 2;
169156 }
170157
171
- cmd->rxchain_info = cpu_to_le32(iwl_mvm_get_valid_rx_ant(mvm) <<
158
+ *rxchain_info = cpu_to_le32(iwl_mvm_get_valid_rx_ant(mvm) <<
172159 PHY_RX_CHAIN_VALID_POS);
173
- cmd->rxchain_info |= cpu_to_le32(idle_cnt << PHY_RX_CHAIN_CNT_POS);
174
- cmd->rxchain_info |= cpu_to_le32(active_cnt <<
160
+ *rxchain_info |= cpu_to_le32(idle_cnt << PHY_RX_CHAIN_CNT_POS);
161
+ *rxchain_info |= cpu_to_le32(active_cnt <<
175162 PHY_RX_CHAIN_MIMO_CNT_POS);
176163 #ifdef CONFIG_IWLWIFI_DEBUGFS
177164 if (unlikely(mvm->dbgfs_rx_phyinfo))
178
- cmd->rxchain_info = cpu_to_le32(mvm->dbgfs_rx_phyinfo);
165
+ *rxchain_info = cpu_to_le32(mvm->dbgfs_rx_phyinfo);
179166 #endif
167
+}
180168
181
- cmd->txchain_info = cpu_to_le32(iwl_mvm_get_valid_tx_ant(mvm));
169
+/*
170
+ * Add the phy configuration to the PHY context command
171
+ */
172
+static void iwl_mvm_phy_ctxt_cmd_data_v1(struct iwl_mvm *mvm,
173
+ struct iwl_phy_context_cmd_v1 *cmd,
174
+ struct cfg80211_chan_def *chandef,
175
+ u8 chains_static, u8 chains_dynamic)
176
+{
177
+ struct iwl_phy_context_cmd_tail *tail =
178
+ iwl_mvm_chan_info_cmd_tail(mvm, &cmd->ci);
179
+
180
+ /* Set the channel info data */
181
+ iwl_mvm_set_chan_info_chandef(mvm, &cmd->ci, chandef);
182
+
183
+ iwl_mvm_phy_ctxt_set_rxchain(mvm, &tail->rxchain_info,
184
+ chains_static, chains_dynamic);
185
+
186
+ tail->txchain_info = cpu_to_le32(iwl_mvm_get_valid_tx_ant(mvm));
187
+}
188
+
189
+/*
190
+ * Add the phy configuration to the PHY context command
191
+ */
192
+static void iwl_mvm_phy_ctxt_cmd_data(struct iwl_mvm *mvm,
193
+ struct iwl_phy_context_cmd *cmd,
194
+ struct cfg80211_chan_def *chandef,
195
+ u8 chains_static, u8 chains_dynamic)
196
+{
197
+ cmd->lmac_id = cpu_to_le32(iwl_mvm_get_lmac_id(mvm->fw,
198
+ chandef->chan->band));
199
+
200
+ /* Set the channel info data */
201
+ iwl_mvm_set_chan_info_chandef(mvm, &cmd->ci, chandef);
202
+
203
+ iwl_mvm_phy_ctxt_set_rxchain(mvm, &cmd->rxchain_info,
204
+ chains_static, chains_dynamic);
182205 }
183206
184207 /*
....@@ -191,21 +214,46 @@
191214 struct iwl_mvm_phy_ctxt *ctxt,
192215 struct cfg80211_chan_def *chandef,
193216 u8 chains_static, u8 chains_dynamic,
194
- u32 action, u32 apply_time)
217
+ u32 action)
195218 {
196
- struct iwl_phy_context_cmd cmd;
197219 int ret;
220
+ int ver = iwl_fw_lookup_cmd_ver(mvm->fw, IWL_ALWAYS_LONG_GROUP,
221
+ PHY_CONTEXT_CMD, 1);
198222
199
- /* Set the command header fields */
200
- iwl_mvm_phy_ctxt_cmd_hdr(ctxt, &cmd, action, apply_time);
223
+ if (ver == 3) {
224
+ struct iwl_phy_context_cmd cmd = {};
201225
202
- /* Set the command data */
203
- iwl_mvm_phy_ctxt_cmd_data(mvm, &cmd, chandef,
204
- chains_static, chains_dynamic);
226
+ /* Set the command header fields */
227
+ iwl_mvm_phy_ctxt_cmd_hdr(ctxt, &cmd, action);
205228
206
- ret = iwl_mvm_send_cmd_pdu(mvm, PHY_CONTEXT_CMD, 0,
207
- sizeof(struct iwl_phy_context_cmd),
208
- &cmd);
229
+ /* Set the command data */
230
+ iwl_mvm_phy_ctxt_cmd_data(mvm, &cmd, chandef,
231
+ chains_static,
232
+ chains_dynamic);
233
+
234
+ ret = iwl_mvm_send_cmd_pdu(mvm, PHY_CONTEXT_CMD,
235
+ 0, sizeof(cmd), &cmd);
236
+ } else if (ver < 3) {
237
+ struct iwl_phy_context_cmd_v1 cmd = {};
238
+ u16 len = sizeof(cmd) - iwl_mvm_chan_info_padding(mvm);
239
+
240
+ /* Set the command header fields */
241
+ iwl_mvm_phy_ctxt_cmd_hdr(ctxt,
242
+ (struct iwl_phy_context_cmd *)&cmd,
243
+ action);
244
+
245
+ /* Set the command data */
246
+ iwl_mvm_phy_ctxt_cmd_data_v1(mvm, &cmd, chandef,
247
+ chains_static,
248
+ chains_dynamic);
249
+ ret = iwl_mvm_send_cmd_pdu(mvm, PHY_CONTEXT_CMD,
250
+ 0, len, &cmd);
251
+ } else {
252
+ IWL_ERR(mvm, "PHY ctxt cmd error ver %d not supported\n", ver);
253
+ return -EOPNOTSUPP;
254
+ }
255
+
256
+
209257 if (ret)
210258 IWL_ERR(mvm, "PHY ctxt cmd error. ret=%d\n", ret);
211259 return ret;
....@@ -226,7 +274,7 @@
226274
227275 return iwl_mvm_phy_ctxt_apply(mvm, ctxt, chandef,
228276 chains_static, chains_dynamic,
229
- FW_CTXT_ACTION_ADD, 0);
277
+ FW_CTXT_ACTION_ADD);
230278 }
231279
232280 /*
....@@ -260,7 +308,7 @@
260308 /* ... remove it here ...*/
261309 ret = iwl_mvm_phy_ctxt_apply(mvm, ctxt, chandef,
262310 chains_static, chains_dynamic,
263
- FW_CTXT_ACTION_REMOVE, 0);
311
+ FW_CTXT_ACTION_REMOVE);
264312 if (ret)
265313 return ret;
266314
....@@ -272,7 +320,7 @@
272320 ctxt->width = chandef->width;
273321 return iwl_mvm_phy_ctxt_apply(mvm, ctxt, chandef,
274322 chains_static, chains_dynamic,
275
- action, 0);
323
+ action);
276324 }
277325
278326 void iwl_mvm_phy_ctxt_unref(struct iwl_mvm *mvm, struct iwl_mvm_phy_ctxt *ctxt)
....@@ -292,8 +340,17 @@
292340 if (ctxt->ref == 0) {
293341 struct ieee80211_channel *chan;
294342 struct cfg80211_chan_def chandef;
343
+ struct ieee80211_supported_band *sband = NULL;
344
+ enum nl80211_band band = NL80211_BAND_2GHZ;
295345
296
- chan = &mvm->hw->wiphy->bands[NL80211_BAND_2GHZ]->channels[0];
346
+ while (!sband && band < NUM_NL80211_BANDS)
347
+ sband = mvm->hw->wiphy->bands[band++];
348
+
349
+ if (WARN_ON(!sband))
350
+ return;
351
+
352
+ chan = &sband->channels[0];
353
+
297354 cfg80211_chandef_create(&chandef, chan, NL80211_CHAN_NO_HT);
298355 iwl_mvm_phy_ctxt_changed(mvm, ctxt, &chandef, 1, 1);
299356 }