aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/wireless/iwlwifi/mvm/time-event.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/net/wireless/iwlwifi/mvm/time-event.c')
-rw-r--r--drivers/net/wireless/iwlwifi/mvm/time-event.c96
1 files changed, 73 insertions, 23 deletions
diff --git a/drivers/net/wireless/iwlwifi/mvm/time-event.c b/drivers/net/wireless/iwlwifi/mvm/time-event.c
index ad9bbca99213..7ed94a089d5e 100644
--- a/drivers/net/wireless/iwlwifi/mvm/time-event.c
+++ b/drivers/net/wireless/iwlwifi/mvm/time-event.c
@@ -166,7 +166,7 @@ static void iwl_mvm_te_handle_notif(struct iwl_mvm *mvm,
166 WARN_ONCE(!le32_to_cpu(notif->status), 166 WARN_ONCE(!le32_to_cpu(notif->status),
167 "Failed to schedule time event\n"); 167 "Failed to schedule time event\n");
168 168
169 if (le32_to_cpu(notif->action) & TE_NOTIF_HOST_EVENT_END) { 169 if (le32_to_cpu(notif->action) & TE_V2_NOTIF_HOST_EVENT_END) {
170 IWL_DEBUG_TE(mvm, 170 IWL_DEBUG_TE(mvm,
171 "TE ended - current time %lu, estimated end %lu\n", 171 "TE ended - current time %lu, estimated end %lu\n",
172 jiffies, te_data->end_jiffies); 172 jiffies, te_data->end_jiffies);
@@ -189,7 +189,7 @@ static void iwl_mvm_te_handle_notif(struct iwl_mvm *mvm,
189 } 189 }
190 190
191 iwl_mvm_te_clear_data(mvm, te_data); 191 iwl_mvm_te_clear_data(mvm, te_data);
192 } else if (le32_to_cpu(notif->action) & TE_NOTIF_HOST_EVENT_START) { 192 } else if (le32_to_cpu(notif->action) & TE_V2_NOTIF_HOST_EVENT_START) {
193 te_data->running = true; 193 te_data->running = true;
194 te_data->end_jiffies = jiffies + 194 te_data->end_jiffies = jiffies +
195 TU_TO_JIFFIES(te_data->duration); 195 TU_TO_JIFFIES(te_data->duration);
@@ -257,10 +257,67 @@ static bool iwl_mvm_time_event_response(struct iwl_notif_wait_data *notif_wait,
257 return true; 257 return true;
258} 258}
259 259
260/* used to convert from time event API v2 to v1 */
261#define TE_V2_DEP_POLICY_MSK (TE_V2_DEP_OTHER | TE_V2_DEP_TSF |\
262 TE_V2_EVENT_SOCIOPATHIC)
263static inline u16 te_v2_get_notify(__le16 policy)
264{
265 return le16_to_cpu(policy) & TE_V2_NOTIF_MSK;
266}
267
268static inline u16 te_v2_get_dep_policy(__le16 policy)
269{
270 return (le16_to_cpu(policy) & TE_V2_DEP_POLICY_MSK) >>
271 TE_V2_PLACEMENT_POS;
272}
273
274static inline u16 te_v2_get_absence(__le16 policy)
275{
276 return (le16_to_cpu(policy) & TE_V2_ABSENCE) >> TE_V2_ABSENCE_POS;
277}
278
279static void iwl_mvm_te_v2_to_v1(const struct iwl_time_event_cmd_v2 *cmd_v2,
280 struct iwl_time_event_cmd_v1 *cmd_v1)
281{
282 cmd_v1->id_and_color = cmd_v2->id_and_color;
283 cmd_v1->action = cmd_v2->action;
284 cmd_v1->id = cmd_v2->id;
285 cmd_v1->apply_time = cmd_v2->apply_time;
286 cmd_v1->max_delay = cmd_v2->max_delay;
287 cmd_v1->depends_on = cmd_v2->depends_on;
288 cmd_v1->interval = cmd_v2->interval;
289 cmd_v1->duration = cmd_v2->duration;
290 if (cmd_v2->repeat == TE_V2_REPEAT_ENDLESS)
291 cmd_v1->repeat = cpu_to_le32(TE_V1_REPEAT_ENDLESS);
292 else
293 cmd_v1->repeat = cpu_to_le32(cmd_v2->repeat);
294 cmd_v1->max_frags = cpu_to_le32(cmd_v2->max_frags);
295 cmd_v1->interval_reciprocal = 0; /* unused */
296
297 cmd_v1->dep_policy = cpu_to_le32(te_v2_get_dep_policy(cmd_v2->policy));
298 cmd_v1->is_present = cpu_to_le32(!te_v2_get_absence(cmd_v2->policy));
299 cmd_v1->notify = cpu_to_le32(te_v2_get_notify(cmd_v2->policy));
300}
301
302static int iwl_mvm_send_time_event_cmd(struct iwl_mvm *mvm,
303 const struct iwl_time_event_cmd_v2 *cmd)
304{
305 struct iwl_time_event_cmd_v1 cmd_v1;
306
307 if (mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_TIME_EVENT_API_V2)
308 return iwl_mvm_send_cmd_pdu(mvm, TIME_EVENT_CMD, CMD_SYNC,
309 sizeof(*cmd), cmd);
310
311 iwl_mvm_te_v2_to_v1(cmd, &cmd_v1);
312 return iwl_mvm_send_cmd_pdu(mvm, TIME_EVENT_CMD, CMD_SYNC,
313 sizeof(cmd_v1), &cmd_v1);
314}
315
316
260static int iwl_mvm_time_event_send_add(struct iwl_mvm *mvm, 317static int iwl_mvm_time_event_send_add(struct iwl_mvm *mvm,
261 struct ieee80211_vif *vif, 318 struct ieee80211_vif *vif,
262 struct iwl_mvm_time_event_data *te_data, 319 struct iwl_mvm_time_event_data *te_data,
263 struct iwl_time_event_cmd *te_cmd) 320 struct iwl_time_event_cmd_v2 *te_cmd)
264{ 321{
265 static const u8 time_event_response[] = { TIME_EVENT_CMD }; 322 static const u8 time_event_response[] = { TIME_EVENT_CMD };
266 struct iwl_notification_wait wait_time_event; 323 struct iwl_notification_wait wait_time_event;
@@ -296,8 +353,7 @@ static int iwl_mvm_time_event_send_add(struct iwl_mvm *mvm,
296 ARRAY_SIZE(time_event_response), 353 ARRAY_SIZE(time_event_response),
297 iwl_mvm_time_event_response, te_data); 354 iwl_mvm_time_event_response, te_data);
298 355
299 ret = iwl_mvm_send_cmd_pdu(mvm, TIME_EVENT_CMD, CMD_SYNC, 356 ret = iwl_mvm_send_time_event_cmd(mvm, te_cmd);
300 sizeof(*te_cmd), te_cmd);
301 if (ret) { 357 if (ret) {
302 IWL_ERR(mvm, "Couldn't send TIME_EVENT_CMD: %d\n", ret); 358 IWL_ERR(mvm, "Couldn't send TIME_EVENT_CMD: %d\n", ret);
303 iwl_remove_notification(&mvm->notif_wait, &wait_time_event); 359 iwl_remove_notification(&mvm->notif_wait, &wait_time_event);
@@ -324,7 +380,7 @@ void iwl_mvm_protect_session(struct iwl_mvm *mvm,
324{ 380{
325 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 381 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
326 struct iwl_mvm_time_event_data *te_data = &mvmvif->time_event_data; 382 struct iwl_mvm_time_event_data *te_data = &mvmvif->time_event_data;
327 struct iwl_time_event_cmd time_cmd = {}; 383 struct iwl_time_event_cmd_v2 time_cmd = {};
328 384
329 lockdep_assert_held(&mvm->mutex); 385 lockdep_assert_held(&mvm->mutex);
330 386
@@ -359,17 +415,14 @@ void iwl_mvm_protect_session(struct iwl_mvm *mvm,
359 time_cmd.apply_time = 415 time_cmd.apply_time =
360 cpu_to_le32(iwl_read_prph(mvm->trans, DEVICE_SYSTEM_TIME_REG)); 416 cpu_to_le32(iwl_read_prph(mvm->trans, DEVICE_SYSTEM_TIME_REG));
361 417
362 time_cmd.dep_policy = TE_INDEPENDENT; 418 time_cmd.max_frags = TE_V2_FRAG_NONE;
363 time_cmd.is_present = cpu_to_le32(1);
364 time_cmd.max_frags = cpu_to_le32(TE_FRAG_NONE);
365 time_cmd.max_delay = cpu_to_le32(500); 419 time_cmd.max_delay = cpu_to_le32(500);
366 /* TODO: why do we need to interval = bi if it is not periodic? */ 420 /* TODO: why do we need to interval = bi if it is not periodic? */
367 time_cmd.interval = cpu_to_le32(1); 421 time_cmd.interval = cpu_to_le32(1);
368 time_cmd.interval_reciprocal = cpu_to_le32(iwl_mvm_reciprocal(1));
369 time_cmd.duration = cpu_to_le32(duration); 422 time_cmd.duration = cpu_to_le32(duration);
370 time_cmd.repeat = cpu_to_le32(1); 423 time_cmd.repeat = 1;
371 time_cmd.notify = cpu_to_le32(TE_NOTIF_HOST_EVENT_START | 424 time_cmd.policy = cpu_to_le16(TE_V2_NOTIF_HOST_EVENT_START |
372 TE_NOTIF_HOST_EVENT_END); 425 TE_V2_NOTIF_HOST_EVENT_END);
373 426
374 iwl_mvm_time_event_send_add(mvm, vif, te_data, &time_cmd); 427 iwl_mvm_time_event_send_add(mvm, vif, te_data, &time_cmd);
375} 428}
@@ -383,7 +436,7 @@ void iwl_mvm_remove_time_event(struct iwl_mvm *mvm,
383 struct iwl_mvm_vif *mvmvif, 436 struct iwl_mvm_vif *mvmvif,
384 struct iwl_mvm_time_event_data *te_data) 437 struct iwl_mvm_time_event_data *te_data)
385{ 438{
386 struct iwl_time_event_cmd time_cmd = {}; 439 struct iwl_time_event_cmd_v2 time_cmd = {};
387 u32 id, uid; 440 u32 id, uid;
388 int ret; 441 int ret;
389 442
@@ -420,8 +473,7 @@ void iwl_mvm_remove_time_event(struct iwl_mvm *mvm,
420 cpu_to_le32(FW_CMD_ID_AND_COLOR(mvmvif->id, mvmvif->color)); 473 cpu_to_le32(FW_CMD_ID_AND_COLOR(mvmvif->id, mvmvif->color));
421 474
422 IWL_DEBUG_TE(mvm, "Removing TE 0x%x\n", le32_to_cpu(time_cmd.id)); 475 IWL_DEBUG_TE(mvm, "Removing TE 0x%x\n", le32_to_cpu(time_cmd.id));
423 ret = iwl_mvm_send_cmd_pdu(mvm, TIME_EVENT_CMD, CMD_SYNC, 476 ret = iwl_mvm_send_time_event_cmd(mvm, &time_cmd);
424 sizeof(time_cmd), &time_cmd);
425 if (WARN_ON(ret)) 477 if (WARN_ON(ret))
426 return; 478 return;
427} 479}
@@ -441,7 +493,7 @@ int iwl_mvm_start_p2p_roc(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
441{ 493{
442 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 494 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
443 struct iwl_mvm_time_event_data *te_data = &mvmvif->time_event_data; 495 struct iwl_mvm_time_event_data *te_data = &mvmvif->time_event_data;
444 struct iwl_time_event_cmd time_cmd = {}; 496 struct iwl_time_event_cmd_v2 time_cmd = {};
445 497
446 lockdep_assert_held(&mvm->mutex); 498 lockdep_assert_held(&mvm->mutex);
447 if (te_data->running) { 499 if (te_data->running) {
@@ -472,8 +524,6 @@ int iwl_mvm_start_p2p_roc(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
472 } 524 }
473 525
474 time_cmd.apply_time = cpu_to_le32(0); 526 time_cmd.apply_time = cpu_to_le32(0);
475 time_cmd.dep_policy = cpu_to_le32(TE_INDEPENDENT);
476 time_cmd.is_present = cpu_to_le32(1);
477 time_cmd.interval = cpu_to_le32(1); 527 time_cmd.interval = cpu_to_le32(1);
478 528
479 /* 529 /*
@@ -482,12 +532,12 @@ int iwl_mvm_start_p2p_roc(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
482 * scheduled. To improve the chances of it being scheduled, allow them 532 * scheduled. To improve the chances of it being scheduled, allow them
483 * to be fragmented, and in addition allow them to be delayed. 533 * to be fragmented, and in addition allow them to be delayed.
484 */ 534 */
485 time_cmd.max_frags = cpu_to_le32(MSEC_TO_TU(duration)/20); 535 time_cmd.max_frags = min(MSEC_TO_TU(duration)/50, TE_V2_FRAG_ENDLESS);
486 time_cmd.max_delay = cpu_to_le32(MSEC_TO_TU(duration/2)); 536 time_cmd.max_delay = cpu_to_le32(MSEC_TO_TU(duration/2));
487 time_cmd.duration = cpu_to_le32(MSEC_TO_TU(duration)); 537 time_cmd.duration = cpu_to_le32(MSEC_TO_TU(duration));
488 time_cmd.repeat = cpu_to_le32(1); 538 time_cmd.repeat = 1;
489 time_cmd.notify = cpu_to_le32(TE_NOTIF_HOST_EVENT_START | 539 time_cmd.policy = cpu_to_le16(TE_V2_NOTIF_HOST_EVENT_START |
490 TE_NOTIF_HOST_EVENT_END); 540 TE_V2_NOTIF_HOST_EVENT_END);
491 541
492 return iwl_mvm_time_event_send_add(mvm, vif, te_data, &time_cmd); 542 return iwl_mvm_time_event_send_add(mvm, vif, te_data, &time_cmd);
493} 543}