time-event.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569
  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 LICENSE.GPL.
  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 TU_TO_JIFFIES(_tu) (usecs_to_jiffies((_tu) * 1024))
  74. #define MSEC_TO_TU(_msec) (_msec*1000/1024)
  75. void iwl_mvm_te_clear_data(struct iwl_mvm *mvm,
  76. struct iwl_mvm_time_event_data *te_data)
  77. {
  78. lockdep_assert_held(&mvm->time_event_lock);
  79. if (te_data->id == TE_MAX)
  80. return;
  81. list_del(&te_data->list);
  82. te_data->running = false;
  83. te_data->uid = 0;
  84. te_data->id = TE_MAX;
  85. te_data->vif = NULL;
  86. }
  87. void iwl_mvm_roc_done_wk(struct work_struct *wk)
  88. {
  89. struct iwl_mvm *mvm = container_of(wk, struct iwl_mvm, roc_done_wk);
  90. synchronize_net();
  91. /*
  92. * Flush the offchannel queue -- this is called when the time
  93. * event finishes or is cancelled, so that frames queued for it
  94. * won't get stuck on the queue and be transmitted in the next
  95. * time event.
  96. * We have to send the command asynchronously since this cannot
  97. * be under the mutex for locking reasons, but that's not an
  98. * issue as it will have to complete before the next command is
  99. * executed, and a new time event means a new command.
  100. */
  101. iwl_mvm_flush_tx_path(mvm, BIT(IWL_OFFCHANNEL_QUEUE), false);
  102. }
  103. static void iwl_mvm_roc_finished(struct iwl_mvm *mvm)
  104. {
  105. /*
  106. * First, clear the ROC_RUNNING status bit. This will cause the TX
  107. * path to drop offchannel transmissions. That would also be done
  108. * by mac80211, but it is racy, in particular in the case that the
  109. * time event actually completed in the firmware (which is handled
  110. * in iwl_mvm_te_handle_notif).
  111. */
  112. clear_bit(IWL_MVM_STATUS_ROC_RUNNING, &mvm->status);
  113. /*
  114. * Of course, our status bit is just as racy as mac80211, so in
  115. * addition, fire off the work struct which will drop all frames
  116. * from the hardware queues that made it through the race. First
  117. * it will of course synchronize the TX path to make sure that
  118. * any *new* TX will be rejected.
  119. */
  120. schedule_work(&mvm->roc_done_wk);
  121. }
  122. /*
  123. * Handles a FW notification for an event that is known to the driver.
  124. *
  125. * @mvm: the mvm component
  126. * @te_data: the time event data
  127. * @notif: the notification data corresponding the time event data.
  128. */
  129. static void iwl_mvm_te_handle_notif(struct iwl_mvm *mvm,
  130. struct iwl_mvm_time_event_data *te_data,
  131. struct iwl_time_event_notif *notif)
  132. {
  133. lockdep_assert_held(&mvm->time_event_lock);
  134. IWL_DEBUG_TE(mvm, "Handle time event notif - UID = 0x%x action %d\n",
  135. le32_to_cpu(notif->unique_id),
  136. le32_to_cpu(notif->action));
  137. /*
  138. * The FW sends the start/end time event notifications even for events
  139. * that it fails to schedule. This is indicated in the status field of
  140. * the notification. This happens in cases that the scheduler cannot
  141. * find a schedule that can handle the event (for example requesting a
  142. * P2P Device discoveribility, while there are other higher priority
  143. * events in the system).
  144. */
  145. WARN_ONCE(!le32_to_cpu(notif->status),
  146. "Failed to schedule time event\n");
  147. if (le32_to_cpu(notif->action) == TE_NOTIF_HOST_END) {
  148. IWL_DEBUG_TE(mvm,
  149. "TE ended - current time %lu, estimated end %lu\n",
  150. jiffies, te_data->end_jiffies);
  151. if (te_data->vif->type == NL80211_IFTYPE_P2P_DEVICE) {
  152. ieee80211_remain_on_channel_expired(mvm->hw);
  153. iwl_mvm_roc_finished(mvm);
  154. }
  155. /*
  156. * By now, we should have finished association
  157. * and know the dtim period.
  158. */
  159. if (te_data->vif->type == NL80211_IFTYPE_STATION &&
  160. (!te_data->vif->bss_conf.assoc ||
  161. !te_data->vif->bss_conf.dtim_period))
  162. IWL_ERR(mvm,
  163. "No assocation and the time event is over already...\n");
  164. iwl_mvm_te_clear_data(mvm, te_data);
  165. } else if (le32_to_cpu(notif->action) == TE_NOTIF_HOST_START) {
  166. te_data->running = true;
  167. te_data->end_jiffies = jiffies +
  168. TU_TO_JIFFIES(te_data->duration);
  169. if (te_data->vif->type == NL80211_IFTYPE_P2P_DEVICE) {
  170. set_bit(IWL_MVM_STATUS_ROC_RUNNING, &mvm->status);
  171. ieee80211_ready_on_channel(mvm->hw);
  172. }
  173. } else {
  174. IWL_WARN(mvm, "Got TE with unknown action\n");
  175. }
  176. }
  177. /*
  178. * The Rx handler for time event notifications
  179. */
  180. int iwl_mvm_rx_time_event_notif(struct iwl_mvm *mvm,
  181. struct iwl_rx_cmd_buffer *rxb,
  182. struct iwl_device_cmd *cmd)
  183. {
  184. struct iwl_rx_packet *pkt = rxb_addr(rxb);
  185. struct iwl_time_event_notif *notif = (void *)pkt->data;
  186. struct iwl_mvm_time_event_data *te_data, *tmp;
  187. IWL_DEBUG_TE(mvm, "Time event notification - UID = 0x%x action %d\n",
  188. le32_to_cpu(notif->unique_id),
  189. le32_to_cpu(notif->action));
  190. spin_lock_bh(&mvm->time_event_lock);
  191. list_for_each_entry_safe(te_data, tmp, &mvm->time_event_list, list) {
  192. if (le32_to_cpu(notif->unique_id) == te_data->uid)
  193. iwl_mvm_te_handle_notif(mvm, te_data, notif);
  194. }
  195. spin_unlock_bh(&mvm->time_event_lock);
  196. return 0;
  197. }
  198. static bool iwl_mvm_time_event_notif(struct iwl_notif_wait_data *notif_wait,
  199. struct iwl_rx_packet *pkt, void *data)
  200. {
  201. struct iwl_mvm *mvm =
  202. container_of(notif_wait, struct iwl_mvm, notif_wait);
  203. struct iwl_mvm_time_event_data *te_data = data;
  204. struct ieee80211_vif *vif = te_data->vif;
  205. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  206. struct iwl_time_event_notif *notif;
  207. struct iwl_time_event_resp *resp;
  208. u32 mac_id_n_color = FW_CMD_ID_AND_COLOR(mvmvif->id, mvmvif->color);
  209. /* until we do something else */
  210. WARN_ON(te_data->id != TE_BSS_STA_AGGRESSIVE_ASSOC);
  211. switch (pkt->hdr.cmd) {
  212. case TIME_EVENT_CMD:
  213. resp = (void *)pkt->data;
  214. /* TODO: I can't check that since the fw is buggy - it doesn't
  215. * put the right values when we remove a TE. We can be here
  216. * when we remove a TE because the remove TE command is sent in
  217. * ASYNC...
  218. * WARN_ON(mac_id_n_color != le32_to_cpu(resp->id_and_color));
  219. */
  220. te_data->uid = le32_to_cpu(resp->unique_id);
  221. IWL_DEBUG_TE(mvm, "Got response - UID = 0x%x\n", te_data->uid);
  222. return false;
  223. case TIME_EVENT_NOTIFICATION:
  224. notif = (void *)pkt->data;
  225. WARN_ON(le32_to_cpu(notif->status) != 1);
  226. WARN_ON(mac_id_n_color != le32_to_cpu(notif->id_and_color));
  227. /* check if this is our Time Event that is starting */
  228. if (le32_to_cpu(notif->unique_id) != te_data->uid)
  229. return false;
  230. IWL_DEBUG_TE(mvm, "Event %d is starting - time is %d\n",
  231. te_data->uid, le32_to_cpu(notif->timestamp));
  232. WARN_ONCE(!le32_to_cpu(notif->status),
  233. "Failed to schedule protected session TE\n");
  234. te_data->running = true;
  235. te_data->end_jiffies = jiffies +
  236. TU_TO_JIFFIES(te_data->duration);
  237. return true;
  238. default:
  239. WARN_ON(1);
  240. return false;
  241. };
  242. }
  243. void iwl_mvm_protect_session(struct iwl_mvm *mvm,
  244. struct ieee80211_vif *vif,
  245. u32 duration, u32 min_duration)
  246. {
  247. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  248. struct iwl_mvm_time_event_data *te_data = &mvmvif->time_event_data;
  249. static const u8 time_event_notif[] = { TIME_EVENT_CMD,
  250. TIME_EVENT_NOTIFICATION };
  251. struct iwl_notification_wait wait_time_event;
  252. struct iwl_time_event_cmd time_cmd = {};
  253. int ret;
  254. lockdep_assert_held(&mvm->mutex);
  255. if (te_data->running &&
  256. time_after(te_data->end_jiffies,
  257. jiffies + TU_TO_JIFFIES(min_duration))) {
  258. IWL_DEBUG_TE(mvm, "We have enough time in the current TE: %u\n",
  259. jiffies_to_msecs(te_data->end_jiffies - jiffies));
  260. return;
  261. }
  262. if (te_data->running) {
  263. IWL_DEBUG_TE(mvm, "extend 0x%x: only %u ms left\n",
  264. te_data->uid,
  265. jiffies_to_msecs(te_data->end_jiffies - jiffies));
  266. /*
  267. * we don't have enough time
  268. * cancel the current TE and issue a new one
  269. * Of course it would be better to remove the old one only
  270. * when the new one is added, but we don't care if we are off
  271. * channel for a bit. All we need to do, is not to return
  272. * before we actually begin to be on the channel.
  273. */
  274. iwl_mvm_stop_session_protection(mvm, vif);
  275. }
  276. iwl_init_notification_wait(&mvm->notif_wait, &wait_time_event,
  277. time_event_notif,
  278. ARRAY_SIZE(time_event_notif),
  279. iwl_mvm_time_event_notif,
  280. &mvmvif->time_event_data);
  281. time_cmd.action = cpu_to_le32(FW_CTXT_ACTION_ADD);
  282. time_cmd.id_and_color =
  283. cpu_to_le32(FW_CMD_ID_AND_COLOR(mvmvif->id, mvmvif->color));
  284. time_cmd.id = cpu_to_le32(TE_BSS_STA_AGGRESSIVE_ASSOC);
  285. time_cmd.apply_time =
  286. cpu_to_le32(iwl_read_prph(mvm->trans, DEVICE_SYSTEM_TIME_REG));
  287. time_cmd.dep_policy = TE_INDEPENDENT;
  288. time_cmd.is_present = cpu_to_le32(1);
  289. time_cmd.max_frags = cpu_to_le32(TE_FRAG_NONE);
  290. time_cmd.max_delay = cpu_to_le32(500);
  291. /* TODO: why do we need to interval = bi if it is not periodic? */
  292. time_cmd.interval = cpu_to_le32(1);
  293. time_cmd.interval_reciprocal = cpu_to_le32(iwl_mvm_reciprocal(1));
  294. time_cmd.duration = cpu_to_le32(duration);
  295. time_cmd.repeat = cpu_to_le32(1);
  296. time_cmd.notify = cpu_to_le32(TE_NOTIF_HOST_START | TE_NOTIF_HOST_END);
  297. te_data->vif = vif;
  298. te_data->duration = duration;
  299. spin_lock_bh(&mvm->time_event_lock);
  300. te_data->id = le32_to_cpu(time_cmd.id);
  301. list_add_tail(&te_data->list, &mvm->time_event_list);
  302. spin_unlock_bh(&mvm->time_event_lock);
  303. ret = iwl_mvm_send_cmd_pdu(mvm, TIME_EVENT_CMD, CMD_SYNC,
  304. sizeof(time_cmd), &time_cmd);
  305. if (ret) {
  306. IWL_ERR(mvm, "Couldn't send TIME_EVENT_CMD: %d\n", ret);
  307. goto out_remove_notif;
  308. }
  309. ret = iwl_wait_notification(&mvm->notif_wait, &wait_time_event, 1 * HZ);
  310. if (ret) {
  311. IWL_ERR(mvm, "%s - failed on timeout\n", __func__);
  312. spin_lock_bh(&mvm->time_event_lock);
  313. iwl_mvm_te_clear_data(mvm, te_data);
  314. spin_unlock_bh(&mvm->time_event_lock);
  315. }
  316. return;
  317. out_remove_notif:
  318. iwl_remove_notification(&mvm->notif_wait, &wait_time_event);
  319. }
  320. /*
  321. * Explicit request to remove a time event. The removal of a time event needs to
  322. * be synchronized with the flow of a time event's end notification, which also
  323. * removes the time event from the op mode data structures.
  324. */
  325. void iwl_mvm_remove_time_event(struct iwl_mvm *mvm,
  326. struct iwl_mvm_vif *mvmvif,
  327. struct iwl_mvm_time_event_data *te_data)
  328. {
  329. struct iwl_time_event_cmd time_cmd = {};
  330. u32 id, uid;
  331. int ret;
  332. /*
  333. * It is possible that by the time we got to this point the time
  334. * event was already removed.
  335. */
  336. spin_lock_bh(&mvm->time_event_lock);
  337. /* Save time event uid before clearing its data */
  338. uid = te_data->uid;
  339. id = te_data->id;
  340. /*
  341. * The clear_data function handles time events that were already removed
  342. */
  343. iwl_mvm_te_clear_data(mvm, te_data);
  344. spin_unlock_bh(&mvm->time_event_lock);
  345. /*
  346. * It is possible that by the time we try to remove it, the time event
  347. * has already ended and removed. In such a case there is no need to
  348. * send a removal command.
  349. */
  350. if (id == TE_MAX) {
  351. IWL_DEBUG_TE(mvm, "TE 0x%x has already ended\n", uid);
  352. return;
  353. }
  354. /* When we remove a TE, the UID is to be set in the id field */
  355. time_cmd.id = cpu_to_le32(uid);
  356. time_cmd.action = cpu_to_le32(FW_CTXT_ACTION_REMOVE);
  357. time_cmd.id_and_color =
  358. cpu_to_le32(FW_CMD_ID_AND_COLOR(mvmvif->id, mvmvif->color));
  359. IWL_DEBUG_TE(mvm, "Removing TE 0x%x\n", le32_to_cpu(time_cmd.id));
  360. ret = iwl_mvm_send_cmd_pdu(mvm, TIME_EVENT_CMD, CMD_ASYNC,
  361. sizeof(time_cmd), &time_cmd);
  362. if (WARN_ON(ret))
  363. return;
  364. }
  365. void iwl_mvm_stop_session_protection(struct iwl_mvm *mvm,
  366. struct ieee80211_vif *vif)
  367. {
  368. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  369. struct iwl_mvm_time_event_data *te_data = &mvmvif->time_event_data;
  370. lockdep_assert_held(&mvm->mutex);
  371. iwl_mvm_remove_time_event(mvm, mvmvif, te_data);
  372. }
  373. static bool iwl_mvm_roc_te_notif(struct iwl_notif_wait_data *notif_wait,
  374. struct iwl_rx_packet *pkt, void *data)
  375. {
  376. struct iwl_mvm *mvm =
  377. container_of(notif_wait, struct iwl_mvm, notif_wait);
  378. struct iwl_mvm_time_event_data *te_data = data;
  379. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(te_data->vif);
  380. struct iwl_time_event_resp *resp;
  381. u32 mac_id_n_color = FW_CMD_ID_AND_COLOR(mvmvif->id, mvmvif->color);
  382. /* until we do something else */
  383. WARN_ON(te_data->id != TE_P2P_DEVICE_DISCOVERABLE);
  384. switch (pkt->hdr.cmd) {
  385. case TIME_EVENT_CMD:
  386. resp = (void *)pkt->data;
  387. WARN_ON(mac_id_n_color != le32_to_cpu(resp->id_and_color));
  388. te_data->uid = le32_to_cpu(resp->unique_id);
  389. IWL_DEBUG_TE(mvm, "Got response - UID = 0x%x\n", te_data->uid);
  390. return true;
  391. default:
  392. WARN_ON(1);
  393. return false;
  394. };
  395. }
  396. int iwl_mvm_start_p2p_roc(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
  397. int duration)
  398. {
  399. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  400. struct iwl_mvm_time_event_data *te_data = &mvmvif->time_event_data;
  401. static const u8 roc_te_notif[] = { TIME_EVENT_CMD };
  402. struct iwl_notification_wait wait_time_event;
  403. struct iwl_time_event_cmd time_cmd = {};
  404. int ret;
  405. lockdep_assert_held(&mvm->mutex);
  406. if (te_data->running) {
  407. IWL_WARN(mvm, "P2P_DEVICE remain on channel already running\n");
  408. return -EBUSY;
  409. }
  410. /*
  411. * Flush the done work, just in case it's still pending, so that
  412. * the work it does can complete and we can accept new frames.
  413. */
  414. flush_work(&mvm->roc_done_wk);
  415. iwl_init_notification_wait(&mvm->notif_wait, &wait_time_event,
  416. roc_te_notif,
  417. ARRAY_SIZE(roc_te_notif),
  418. iwl_mvm_roc_te_notif,
  419. &mvmvif->time_event_data);
  420. time_cmd.action = cpu_to_le32(FW_CTXT_ACTION_ADD);
  421. time_cmd.id_and_color =
  422. cpu_to_le32(FW_CMD_ID_AND_COLOR(mvmvif->id, mvmvif->color));
  423. time_cmd.id = cpu_to_le32(TE_P2P_DEVICE_DISCOVERABLE);
  424. time_cmd.apply_time = cpu_to_le32(0);
  425. time_cmd.dep_policy = cpu_to_le32(TE_INDEPENDENT);
  426. time_cmd.is_present = cpu_to_le32(1);
  427. time_cmd.interval = cpu_to_le32(1);
  428. /*
  429. * TE_P2P_DEVICE_DISCOVERABLE can have lower priority than other events
  430. * that are being scheduled by the driver/fw, and thus it might not be
  431. * scheduled. To improve the chances of it being scheduled, allow it to
  432. * be fragmented.
  433. * In addition, for the same reasons, allow to delay the scheduling of
  434. * the time event.
  435. */
  436. time_cmd.max_frags = cpu_to_le32(MSEC_TO_TU(duration)/20);
  437. time_cmd.max_delay = cpu_to_le32(MSEC_TO_TU(duration/2));
  438. time_cmd.duration = cpu_to_le32(MSEC_TO_TU(duration));
  439. time_cmd.repeat = cpu_to_le32(1);
  440. time_cmd.notify = cpu_to_le32(TE_NOTIF_HOST_START | TE_NOTIF_HOST_END);
  441. /* Push the te data to the tracked te list */
  442. te_data->vif = vif;
  443. te_data->duration = MSEC_TO_TU(duration);
  444. spin_lock_bh(&mvm->time_event_lock);
  445. te_data->id = le32_to_cpu(time_cmd.id);
  446. list_add_tail(&te_data->list, &mvm->time_event_list);
  447. spin_unlock_bh(&mvm->time_event_lock);
  448. ret = iwl_mvm_send_cmd_pdu(mvm, TIME_EVENT_CMD, CMD_SYNC,
  449. sizeof(time_cmd), &time_cmd);
  450. if (ret) {
  451. IWL_ERR(mvm, "Couldn't send TIME_EVENT_CMD: %d\n", ret);
  452. goto out_remove_notif;
  453. }
  454. ret = iwl_wait_notification(&mvm->notif_wait, &wait_time_event, 1 * HZ);
  455. if (ret) {
  456. IWL_ERR(mvm, "%s - failed on timeout\n", __func__);
  457. iwl_mvm_te_clear_data(mvm, te_data);
  458. }
  459. return ret;
  460. out_remove_notif:
  461. iwl_remove_notification(&mvm->notif_wait, &wait_time_event);
  462. return ret;
  463. }
  464. void iwl_mvm_stop_p2p_roc(struct iwl_mvm *mvm)
  465. {
  466. struct iwl_mvm_vif *mvmvif;
  467. struct iwl_mvm_time_event_data *te_data;
  468. lockdep_assert_held(&mvm->mutex);
  469. /*
  470. * Iterate over the list of time events and find the time event that is
  471. * associated with a P2P_DEVICE interface.
  472. * This assumes that a P2P_DEVICE interface can have only a single time
  473. * event at any given time and this time event coresponds to a ROC
  474. * request
  475. */
  476. mvmvif = NULL;
  477. spin_lock_bh(&mvm->time_event_lock);
  478. list_for_each_entry(te_data, &mvm->time_event_list, list) {
  479. if (te_data->vif->type == NL80211_IFTYPE_P2P_DEVICE) {
  480. mvmvif = iwl_mvm_vif_from_mac80211(te_data->vif);
  481. break;
  482. }
  483. }
  484. spin_unlock_bh(&mvm->time_event_lock);
  485. if (!mvmvif) {
  486. IWL_WARN(mvm, "P2P_DEVICE no remain on channel event\n");
  487. return;
  488. }
  489. iwl_mvm_remove_time_event(mvm, mvmvif, te_data);
  490. iwl_mvm_roc_finished(mvm);
  491. }