util.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /* This program is free software; you can redistribute it and/or modify
  2. * it under the terms of the GNU General Public License version 2
  3. * as published by the Free Software Foundation.
  4. *
  5. * This program is distributed in the hope that it will be useful,
  6. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  7. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  8. * GNU General Public License for more details.
  9. *
  10. * Authors:
  11. * Alexander Aring <aar@pengutronix.de>
  12. *
  13. * Based on: net/mac80211/util.c
  14. */
  15. #include "ieee802154_i.h"
  16. /* privid for wpan_phys to determine whether they belong to us or not */
  17. const void *const mac802154_wpan_phy_privid = &mac802154_wpan_phy_privid;
  18. void ieee802154_wake_queue(struct ieee802154_hw *hw)
  19. {
  20. struct ieee802154_local *local = hw_to_local(hw);
  21. struct ieee802154_sub_if_data *sdata;
  22. rcu_read_lock();
  23. list_for_each_entry_rcu(sdata, &local->interfaces, list) {
  24. if (!sdata->dev)
  25. continue;
  26. netif_wake_queue(sdata->dev);
  27. }
  28. rcu_read_unlock();
  29. }
  30. EXPORT_SYMBOL(ieee802154_wake_queue);
  31. void ieee802154_stop_queue(struct ieee802154_hw *hw)
  32. {
  33. struct ieee802154_local *local = hw_to_local(hw);
  34. struct ieee802154_sub_if_data *sdata;
  35. rcu_read_lock();
  36. list_for_each_entry_rcu(sdata, &local->interfaces, list) {
  37. if (!sdata->dev)
  38. continue;
  39. netif_stop_queue(sdata->dev);
  40. }
  41. rcu_read_unlock();
  42. }
  43. EXPORT_SYMBOL(ieee802154_stop_queue);
  44. enum hrtimer_restart ieee802154_xmit_ifs_timer(struct hrtimer *timer)
  45. {
  46. struct ieee802154_local *local =
  47. container_of(timer, struct ieee802154_local, ifs_timer);
  48. ieee802154_wake_queue(&local->hw);
  49. return HRTIMER_NORESTART;
  50. }
  51. void ieee802154_xmit_complete(struct ieee802154_hw *hw, struct sk_buff *skb,
  52. bool ifs_handling)
  53. {
  54. if (ifs_handling) {
  55. struct ieee802154_local *local = hw_to_local(hw);
  56. if (skb->len > 18)
  57. hrtimer_start(&local->ifs_timer,
  58. ktime_set(0, hw->phy->lifs_period * NSEC_PER_USEC),
  59. HRTIMER_MODE_REL);
  60. else
  61. hrtimer_start(&local->ifs_timer,
  62. ktime_set(0, hw->phy->sifs_period * NSEC_PER_USEC),
  63. HRTIMER_MODE_REL);
  64. consume_skb(skb);
  65. } else {
  66. ieee802154_wake_queue(hw);
  67. consume_skb(skb);
  68. }
  69. }
  70. EXPORT_SYMBOL(ieee802154_xmit_complete);