time-event.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587
  1. /******************************************************************************
  2. *
  3. * This file is provided under a dual BSD/GPLv2 license. When using or
  4. * redistributing this file, you may do so under either license.
  5. *
  6. * GPL LICENSE SUMMARY
  7. *
  8. * Copyright(c) 2012 - 2013 Intel Corporation. All rights reserved.
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of version 2 of the GNU General Public License as
  12. * published by the Free Software Foundation.
  13. *
  14. * This program is distributed in the hope that it will be useful, but
  15. * WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17. * General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, write to the Free Software
  21. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110,
  22. * USA
  23. *
  24. * The full GNU General Public License is included in this distribution
  25. * in the file called COPYING.
  26. *
  27. * Contact Information:
  28. * Intel Linux Wireless <ilw@linux.intel.com>
  29. * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
  30. *
  31. * BSD LICENSE
  32. *
  33. * Copyright(c) 2012 - 2013 Intel Corporation. All rights reserved.
  34. * All rights reserved.
  35. *
  36. * Redistribution and use in source and binary forms, with or without
  37. * modification, are permitted provided that the following conditions
  38. * are met:
  39. *
  40. * * Redistributions of source code must retain the above copyright
  41. * notice, this list of conditions and the following disclaimer.
  42. * * Redistributions in binary form must reproduce the above copyright
  43. * notice, this list of conditions and the following disclaimer in
  44. * the documentation and/or other materials provided with the
  45. * distribution.
  46. * * Neither the name Intel Corporation nor the names of its
  47. * contributors may be used to endorse or promote products derived
  48. * from this software without specific prior written permission.
  49. *
  50. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  51. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  52. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  53. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  54. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  55. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  56. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  57. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  58. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  59. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  60. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  61. *
  62. *****************************************************************************/
  63. #include <linux/jiffies.h>
  64. #include <net/mac80211.h>
  65. #include "iwl-notif-wait.h"
  66. #include "iwl-trans.h"
  67. #include "fw-api.h"
  68. #include "time-event.h"
  69. #include "mvm.h"
  70. #include "iwl-io.h"
  71. #include "iwl-prph.h"
  72. /* A TimeUnit is 1024 microsecond */
  73. #define MSEC_TO_TU(_msec) (_msec*1000/1024)
  74. /*
  75. * For the high priority TE use a time event type that has similar priority to
  76. * the FW's action scan priority.
  77. */
  78. #define IWL_MVM_ROC_TE_TYPE_NORMAL TE_P2P_DEVICE_DISCOVERABLE
  79. #define IWL_MVM_ROC_TE_TYPE_MGMT_TX TE_P2P_CLIENT_ASSOC
  80. void iwl_mvm_te_clear_data(struct iwl_mvm *mvm,
  81. struct iwl_mvm_time_event_data *te_data)
  82. {
  83. lockdep_assert_held(&mvm->time_event_lock);
  84. if (te_data->id == TE_MAX)
  85. return;
  86. list_del(&te_data->list);
  87. te_data->running = false;
  88. te_data->uid = 0;
  89. te_data->id = TE_MAX;
  90. te_data->vif = NULL;
  91. }
  92. void iwl_mvm_roc_done_wk(struct work_struct *wk)
  93. {
  94. struct iwl_mvm *mvm = container_of(wk, struct iwl_mvm, roc_done_wk);
  95. synchronize_net();
  96. /*
  97. * Flush the offchannel queue -- this is called when the time
  98. * event finishes or is cancelled, so that frames queued for it
  99. * won't get stuck on the queue and be transmitted in the next
  100. * time event.
  101. * We have to send the command asynchronously since this cannot
  102. * be under the mutex for locking reasons, but that's not an
  103. * issue as it will have to complete before the next command is
  104. * executed, and a new time event means a new command.
  105. */
  106. iwl_mvm_flush_tx_path(mvm, BIT(IWL_MVM_OFFCHANNEL_QUEUE), false);
  107. }
  108. static void iwl_mvm_roc_finished(struct iwl_mvm *mvm)
  109. {
  110. /*
  111. * First, clear the ROC_RUNNING status bit. This will cause the TX
  112. * path to drop offchannel transmissions. That would also be done
  113. * by mac80211, but it is racy, in particular in the case that the
  114. * time event actually completed in the firmware (which is handled
  115. * in iwl_mvm_te_handle_notif).
  116. */
  117. clear_bit(IWL_MVM_STATUS_ROC_RUNNING, &mvm->status);
  118. /*
  119. * Of course, our status bit is just as racy as mac80211, so in
  120. * addition, fire off the work struct which will drop all frames
  121. * from the hardware queues that made it through the race. First
  122. * it will of course synchronize the TX path to make sure that
  123. * any *new* TX will be rejected.
  124. */
  125. schedule_work(&mvm->roc_done_wk);
  126. }
  127. static bool iwl_mvm_te_check_disconnect(struct iwl_mvm *mvm,
  128. struct ieee80211_vif *vif,
  129. const char *errmsg)
  130. {
  131. if (vif->type != NL80211_IFTYPE_STATION)
  132. return false;
  133. if (vif->bss_conf.assoc && vif->bss_conf.dtim_period)
  134. return false;
  135. if (errmsg)
  136. IWL_ERR(mvm, "%s\n", errmsg);
  137. ieee80211_connection_loss(vif);
  138. return true;
  139. }
  140. /*
  141. * Handles a FW notification for an event that is known to the driver.
  142. *
  143. * @mvm: the mvm component
  144. * @te_data: the time event data
  145. * @notif: the notification data corresponding the time event data.
  146. */
  147. static void iwl_mvm_te_handle_notif(struct iwl_mvm *mvm,
  148. struct iwl_mvm_time_event_data *te_data,
  149. struct iwl_time_event_notif *notif)
  150. {
  151. lockdep_assert_held(&mvm->time_event_lock);
  152. IWL_DEBUG_TE(mvm, "Handle time event notif - UID = 0x%x action %d\n",
  153. le32_to_cpu(notif->unique_id),
  154. le32_to_cpu(notif->action));
  155. /*
  156. * The FW sends the start/end time event notifications even for events
  157. * that it fails to schedule. This is indicated in the status field of
  158. * the notification. This happens in cases that the scheduler cannot
  159. * find a schedule that can handle the event (for example requesting a
  160. * P2P Device discoveribility, while there are other higher priority
  161. * events in the system).
  162. */
  163. if (WARN_ONCE(!le32_to_cpu(notif->status),
  164. "Failed to schedule time event\n")) {
  165. if (iwl_mvm_te_check_disconnect(mvm, te_data->vif, NULL)) {
  166. iwl_mvm_te_clear_data(mvm, te_data);
  167. return;
  168. }
  169. }
  170. if (le32_to_cpu(notif->action) & TE_V2_NOTIF_HOST_EVENT_END) {
  171. IWL_DEBUG_TE(mvm,
  172. "TE ended - current time %lu, estimated end %lu\n",
  173. jiffies, te_data->end_jiffies);
  174. if (te_data->vif->type == NL80211_IFTYPE_P2P_DEVICE) {
  175. ieee80211_remain_on_channel_expired(mvm->hw);
  176. iwl_mvm_roc_finished(mvm);
  177. }
  178. /*
  179. * By now, we should have finished association
  180. * and know the dtim period.
  181. */
  182. iwl_mvm_te_check_disconnect(mvm, te_data->vif,
  183. "No association and the time event is over already...");
  184. iwl_mvm_te_clear_data(mvm, te_data);
  185. } else if (le32_to_cpu(notif->action) & TE_V2_NOTIF_HOST_EVENT_START) {
  186. te_data->running = true;
  187. te_data->end_jiffies = TU_TO_EXP_TIME(te_data->duration);
  188. if (te_data->vif->type == NL80211_IFTYPE_P2P_DEVICE) {
  189. set_bit(IWL_MVM_STATUS_ROC_RUNNING, &mvm->status);
  190. ieee80211_ready_on_channel(mvm->hw);
  191. }
  192. } else {
  193. IWL_WARN(mvm, "Got TE with unknown action\n");
  194. }
  195. }
  196. /*
  197. * The Rx handler for time event notifications
  198. */
  199. int iwl_mvm_rx_time_event_notif(struct iwl_mvm *mvm,
  200. struct iwl_rx_cmd_buffer *rxb,
  201. struct iwl_device_cmd *cmd)
  202. {
  203. struct iwl_rx_packet *pkt = rxb_addr(rxb);
  204. struct iwl_time_event_notif *notif = (void *)pkt->data;
  205. struct iwl_mvm_time_event_data *te_data, *tmp;
  206. IWL_DEBUG_TE(mvm, "Time event notification - UID = 0x%x action %d\n",
  207. le32_to_cpu(notif->unique_id),
  208. le32_to_cpu(notif->action));
  209. spin_lock_bh(&mvm->time_event_lock);
  210. list_for_each_entry_safe(te_data, tmp, &mvm->time_event_list, list) {
  211. if (le32_to_cpu(notif->unique_id) == te_data->uid)
  212. iwl_mvm_te_handle_notif(mvm, te_data, notif);
  213. }
  214. spin_unlock_bh(&mvm->time_event_lock);
  215. return 0;
  216. }
  217. static bool iwl_mvm_time_event_response(struct iwl_notif_wait_data *notif_wait,
  218. struct iwl_rx_packet *pkt, void *data)
  219. {
  220. struct iwl_mvm *mvm =
  221. container_of(notif_wait, struct iwl_mvm, notif_wait);
  222. struct iwl_mvm_time_event_data *te_data = data;
  223. struct iwl_time_event_resp *resp;
  224. int resp_len = le32_to_cpu(pkt->len_n_flags) & FH_RSCSR_FRAME_SIZE_MSK;
  225. if (WARN_ON(pkt->hdr.cmd != TIME_EVENT_CMD))
  226. return true;
  227. if (WARN_ON_ONCE(resp_len != sizeof(pkt->hdr) + sizeof(*resp))) {
  228. IWL_ERR(mvm, "Invalid TIME_EVENT_CMD response\n");
  229. return true;
  230. }
  231. resp = (void *)pkt->data;
  232. /* we should never get a response to another TIME_EVENT_CMD here */
  233. if (WARN_ON_ONCE(le32_to_cpu(resp->id) != te_data->id))
  234. return false;
  235. te_data->uid = le32_to_cpu(resp->unique_id);
  236. IWL_DEBUG_TE(mvm, "TIME_EVENT_CMD response - UID = 0x%x\n",
  237. te_data->uid);
  238. return true;
  239. }
  240. /* used to convert from time event API v2 to v1 */
  241. #define TE_V2_DEP_POLICY_MSK (TE_V2_DEP_OTHER | TE_V2_DEP_TSF |\
  242. TE_V2_EVENT_SOCIOPATHIC)
  243. static inline u16 te_v2_get_notify(__le16 policy)
  244. {
  245. return le16_to_cpu(policy) & TE_V2_NOTIF_MSK;
  246. }
  247. static inline u16 te_v2_get_dep_policy(__le16 policy)
  248. {
  249. return (le16_to_cpu(policy) & TE_V2_DEP_POLICY_MSK) >>
  250. TE_V2_PLACEMENT_POS;
  251. }
  252. static inline u16 te_v2_get_absence(__le16 policy)
  253. {
  254. return (le16_to_cpu(policy) & TE_V2_ABSENCE) >> TE_V2_ABSENCE_POS;
  255. }
  256. static void iwl_mvm_te_v2_to_v1(const struct iwl_time_event_cmd_v2 *cmd_v2,
  257. struct iwl_time_event_cmd_v1 *cmd_v1)
  258. {
  259. cmd_v1->id_and_color = cmd_v2->id_and_color;
  260. cmd_v1->action = cmd_v2->action;
  261. cmd_v1->id = cmd_v2->id;
  262. cmd_v1->apply_time = cmd_v2->apply_time;
  263. cmd_v1->max_delay = cmd_v2->max_delay;
  264. cmd_v1->depends_on = cmd_v2->depends_on;
  265. cmd_v1->interval = cmd_v2->interval;
  266. cmd_v1->duration = cmd_v2->duration;
  267. if (cmd_v2->repeat == TE_V2_REPEAT_ENDLESS)
  268. cmd_v1->repeat = cpu_to_le32(TE_V1_REPEAT_ENDLESS);
  269. else
  270. cmd_v1->repeat = cpu_to_le32(cmd_v2->repeat);
  271. cmd_v1->max_frags = cpu_to_le32(cmd_v2->max_frags);
  272. cmd_v1->interval_reciprocal = 0; /* unused */
  273. cmd_v1->dep_policy = cpu_to_le32(te_v2_get_dep_policy(cmd_v2->policy));
  274. cmd_v1->is_present = cpu_to_le32(!te_v2_get_absence(cmd_v2->policy));
  275. cmd_v1->notify = cpu_to_le32(te_v2_get_notify(cmd_v2->policy));
  276. }
  277. static int iwl_mvm_send_time_event_cmd(struct iwl_mvm *mvm,
  278. const struct iwl_time_event_cmd_v2 *cmd)
  279. {
  280. struct iwl_time_event_cmd_v1 cmd_v1;
  281. if (mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_TIME_EVENT_API_V2)
  282. return iwl_mvm_send_cmd_pdu(mvm, TIME_EVENT_CMD, CMD_SYNC,
  283. sizeof(*cmd), cmd);
  284. iwl_mvm_te_v2_to_v1(cmd, &cmd_v1);
  285. return iwl_mvm_send_cmd_pdu(mvm, TIME_EVENT_CMD, CMD_SYNC,
  286. sizeof(cmd_v1), &cmd_v1);
  287. }
  288. static int iwl_mvm_time_event_send_add(struct iwl_mvm *mvm,
  289. struct ieee80211_vif *vif,
  290. struct iwl_mvm_time_event_data *te_data,
  291. struct iwl_time_event_cmd_v2 *te_cmd)
  292. {
  293. static const u8 time_event_response[] = { TIME_EVENT_CMD };
  294. struct iwl_notification_wait wait_time_event;
  295. int ret;
  296. lockdep_assert_held(&mvm->mutex);
  297. IWL_DEBUG_TE(mvm, "Add new TE, duration %d TU\n",
  298. le32_to_cpu(te_cmd->duration));
  299. spin_lock_bh(&mvm->time_event_lock);
  300. if (WARN_ON(te_data->id != TE_MAX)) {
  301. spin_unlock_bh(&mvm->time_event_lock);
  302. return -EIO;
  303. }
  304. te_data->vif = vif;
  305. te_data->duration = le32_to_cpu(te_cmd->duration);
  306. te_data->id = le32_to_cpu(te_cmd->id);
  307. list_add_tail(&te_data->list, &mvm->time_event_list);
  308. spin_unlock_bh(&mvm->time_event_lock);
  309. /*
  310. * Use a notification wait, which really just processes the
  311. * command response and doesn't wait for anything, in order
  312. * to be able to process the response and get the UID inside
  313. * the RX path. Using CMD_WANT_SKB doesn't work because it
  314. * stores the buffer and then wakes up this thread, by which
  315. * time another notification (that the time event started)
  316. * might already be processed unsuccessfully.
  317. */
  318. iwl_init_notification_wait(&mvm->notif_wait, &wait_time_event,
  319. time_event_response,
  320. ARRAY_SIZE(time_event_response),
  321. iwl_mvm_time_event_response, te_data);
  322. ret = iwl_mvm_send_time_event_cmd(mvm, te_cmd);
  323. if (ret) {
  324. IWL_ERR(mvm, "Couldn't send TIME_EVENT_CMD: %d\n", ret);
  325. iwl_remove_notification(&mvm->notif_wait, &wait_time_event);
  326. goto out_clear_te;
  327. }
  328. /* No need to wait for anything, so just pass 1 (0 isn't valid) */
  329. ret = iwl_wait_notification(&mvm->notif_wait, &wait_time_event, 1);
  330. /* should never fail */
  331. WARN_ON_ONCE(ret);
  332. if (ret) {
  333. out_clear_te:
  334. spin_lock_bh(&mvm->time_event_lock);
  335. iwl_mvm_te_clear_data(mvm, te_data);
  336. spin_unlock_bh(&mvm->time_event_lock);
  337. }
  338. return ret;
  339. }
  340. void iwl_mvm_protect_session(struct iwl_mvm *mvm,
  341. struct ieee80211_vif *vif,
  342. u32 duration, u32 min_duration)
  343. {
  344. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  345. struct iwl_mvm_time_event_data *te_data = &mvmvif->time_event_data;
  346. struct iwl_time_event_cmd_v2 time_cmd = {};
  347. lockdep_assert_held(&mvm->mutex);
  348. if (te_data->running &&
  349. time_after(te_data->end_jiffies, TU_TO_EXP_TIME(min_duration))) {
  350. IWL_DEBUG_TE(mvm, "We have enough time in the current TE: %u\n",
  351. jiffies_to_msecs(te_data->end_jiffies - jiffies));
  352. return;
  353. }
  354. if (te_data->running) {
  355. IWL_DEBUG_TE(mvm, "extend 0x%x: only %u ms left\n",
  356. te_data->uid,
  357. jiffies_to_msecs(te_data->end_jiffies - jiffies));
  358. /*
  359. * we don't have enough time
  360. * cancel the current TE and issue a new one
  361. * Of course it would be better to remove the old one only
  362. * when the new one is added, but we don't care if we are off
  363. * channel for a bit. All we need to do, is not to return
  364. * before we actually begin to be on the channel.
  365. */
  366. iwl_mvm_stop_session_protection(mvm, vif);
  367. }
  368. time_cmd.action = cpu_to_le32(FW_CTXT_ACTION_ADD);
  369. time_cmd.id_and_color =
  370. cpu_to_le32(FW_CMD_ID_AND_COLOR(mvmvif->id, mvmvif->color));
  371. time_cmd.id = cpu_to_le32(TE_BSS_STA_AGGRESSIVE_ASSOC);
  372. time_cmd.apply_time =
  373. cpu_to_le32(iwl_read_prph(mvm->trans, DEVICE_SYSTEM_TIME_REG));
  374. time_cmd.max_frags = TE_V2_FRAG_NONE;
  375. time_cmd.max_delay = cpu_to_le32(500);
  376. /* TODO: why do we need to interval = bi if it is not periodic? */
  377. time_cmd.interval = cpu_to_le32(1);
  378. time_cmd.duration = cpu_to_le32(duration);
  379. time_cmd.repeat = 1;
  380. time_cmd.policy = cpu_to_le16(TE_V2_NOTIF_HOST_EVENT_START |
  381. TE_V2_NOTIF_HOST_EVENT_END);
  382. iwl_mvm_time_event_send_add(mvm, vif, te_data, &time_cmd);
  383. }
  384. /*
  385. * Explicit request to remove a time event. The removal of a time event needs to
  386. * be synchronized with the flow of a time event's end notification, which also
  387. * removes the time event from the op mode data structures.
  388. */
  389. void iwl_mvm_remove_time_event(struct iwl_mvm *mvm,
  390. struct iwl_mvm_vif *mvmvif,
  391. struct iwl_mvm_time_event_data *te_data)
  392. {
  393. struct iwl_time_event_cmd_v2 time_cmd = {};
  394. u32 id, uid;
  395. int ret;
  396. /*
  397. * It is possible that by the time we got to this point the time
  398. * event was already removed.
  399. */
  400. spin_lock_bh(&mvm->time_event_lock);
  401. /* Save time event uid before clearing its data */
  402. uid = te_data->uid;
  403. id = te_data->id;
  404. /*
  405. * The clear_data function handles time events that were already removed
  406. */
  407. iwl_mvm_te_clear_data(mvm, te_data);
  408. spin_unlock_bh(&mvm->time_event_lock);
  409. /*
  410. * It is possible that by the time we try to remove it, the time event
  411. * has already ended and removed. In such a case there is no need to
  412. * send a removal command.
  413. */
  414. if (id == TE_MAX) {
  415. IWL_DEBUG_TE(mvm, "TE 0x%x has already ended\n", uid);
  416. return;
  417. }
  418. /* When we remove a TE, the UID is to be set in the id field */
  419. time_cmd.id = cpu_to_le32(uid);
  420. time_cmd.action = cpu_to_le32(FW_CTXT_ACTION_REMOVE);
  421. time_cmd.id_and_color =
  422. cpu_to_le32(FW_CMD_ID_AND_COLOR(mvmvif->id, mvmvif->color));
  423. IWL_DEBUG_TE(mvm, "Removing TE 0x%x\n", le32_to_cpu(time_cmd.id));
  424. ret = iwl_mvm_send_time_event_cmd(mvm, &time_cmd);
  425. if (WARN_ON(ret))
  426. return;
  427. }
  428. void iwl_mvm_stop_session_protection(struct iwl_mvm *mvm,
  429. struct ieee80211_vif *vif)
  430. {
  431. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  432. struct iwl_mvm_time_event_data *te_data = &mvmvif->time_event_data;
  433. lockdep_assert_held(&mvm->mutex);
  434. iwl_mvm_remove_time_event(mvm, mvmvif, te_data);
  435. }
  436. int iwl_mvm_start_p2p_roc(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
  437. int duration, enum ieee80211_roc_type type)
  438. {
  439. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  440. struct iwl_mvm_time_event_data *te_data = &mvmvif->time_event_data;
  441. struct iwl_time_event_cmd_v2 time_cmd = {};
  442. lockdep_assert_held(&mvm->mutex);
  443. if (te_data->running) {
  444. IWL_WARN(mvm, "P2P_DEVICE remain on channel already running\n");
  445. return -EBUSY;
  446. }
  447. /*
  448. * Flush the done work, just in case it's still pending, so that
  449. * the work it does can complete and we can accept new frames.
  450. */
  451. flush_work(&mvm->roc_done_wk);
  452. time_cmd.action = cpu_to_le32(FW_CTXT_ACTION_ADD);
  453. time_cmd.id_and_color =
  454. cpu_to_le32(FW_CMD_ID_AND_COLOR(mvmvif->id, mvmvif->color));
  455. switch (type) {
  456. case IEEE80211_ROC_TYPE_NORMAL:
  457. time_cmd.id = cpu_to_le32(IWL_MVM_ROC_TE_TYPE_NORMAL);
  458. break;
  459. case IEEE80211_ROC_TYPE_MGMT_TX:
  460. time_cmd.id = cpu_to_le32(IWL_MVM_ROC_TE_TYPE_MGMT_TX);
  461. break;
  462. default:
  463. WARN_ONCE(1, "Got an invalid ROC type\n");
  464. return -EINVAL;
  465. }
  466. time_cmd.apply_time = cpu_to_le32(0);
  467. time_cmd.interval = cpu_to_le32(1);
  468. /*
  469. * The P2P Device TEs can have lower priority than other events
  470. * that are being scheduled by the driver/fw, and thus it might not be
  471. * scheduled. To improve the chances of it being scheduled, allow them
  472. * to be fragmented, and in addition allow them to be delayed.
  473. */
  474. time_cmd.max_frags = min(MSEC_TO_TU(duration)/50, TE_V2_FRAG_ENDLESS);
  475. time_cmd.max_delay = cpu_to_le32(MSEC_TO_TU(duration/2));
  476. time_cmd.duration = cpu_to_le32(MSEC_TO_TU(duration));
  477. time_cmd.repeat = 1;
  478. time_cmd.policy = cpu_to_le16(TE_V2_NOTIF_HOST_EVENT_START |
  479. TE_V2_NOTIF_HOST_EVENT_END);
  480. return iwl_mvm_time_event_send_add(mvm, vif, te_data, &time_cmd);
  481. }
  482. void iwl_mvm_stop_p2p_roc(struct iwl_mvm *mvm)
  483. {
  484. struct iwl_mvm_vif *mvmvif;
  485. struct iwl_mvm_time_event_data *te_data;
  486. lockdep_assert_held(&mvm->mutex);
  487. /*
  488. * Iterate over the list of time events and find the time event that is
  489. * associated with a P2P_DEVICE interface.
  490. * This assumes that a P2P_DEVICE interface can have only a single time
  491. * event at any given time and this time event coresponds to a ROC
  492. * request
  493. */
  494. mvmvif = NULL;
  495. spin_lock_bh(&mvm->time_event_lock);
  496. list_for_each_entry(te_data, &mvm->time_event_list, list) {
  497. if (te_data->vif->type == NL80211_IFTYPE_P2P_DEVICE) {
  498. mvmvif = iwl_mvm_vif_from_mac80211(te_data->vif);
  499. break;
  500. }
  501. }
  502. spin_unlock_bh(&mvm->time_event_lock);
  503. if (!mvmvif) {
  504. IWL_WARN(mvm, "P2P_DEVICE no remain on channel event\n");
  505. return;
  506. }
  507. iwl_mvm_remove_time_event(mvm, mvmvif, te_data);
  508. iwl_mvm_roc_finished(mvm);
  509. }