util.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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. #include "driver-ops.h"
  17. /* privid for wpan_phys to determine whether they belong to us or not */
  18. const void *const mac802154_wpan_phy_privid = &mac802154_wpan_phy_privid;
  19. void ieee802154_wake_queue(struct ieee802154_hw *hw)
  20. {
  21. struct ieee802154_local *local = hw_to_local(hw);
  22. struct ieee802154_sub_if_data *sdata;
  23. rcu_read_lock();
  24. list_for_each_entry_rcu(sdata, &local->interfaces, list) {
  25. if (!sdata->dev)
  26. continue;
  27. netif_wake_queue(sdata->dev);
  28. }
  29. rcu_read_unlock();
  30. }
  31. EXPORT_SYMBOL(ieee802154_wake_queue);
  32. void ieee802154_stop_queue(struct ieee802154_hw *hw)
  33. {
  34. struct ieee802154_local *local = hw_to_local(hw);
  35. struct ieee802154_sub_if_data *sdata;
  36. rcu_read_lock();
  37. list_for_each_entry_rcu(sdata, &local->interfaces, list) {
  38. if (!sdata->dev)
  39. continue;
  40. netif_stop_queue(sdata->dev);
  41. }
  42. rcu_read_unlock();
  43. }
  44. EXPORT_SYMBOL(ieee802154_stop_queue);
  45. enum hrtimer_restart ieee802154_xmit_ifs_timer(struct hrtimer *timer)
  46. {
  47. struct ieee802154_local *local =
  48. container_of(timer, struct ieee802154_local, ifs_timer);
  49. ieee802154_wake_queue(&local->hw);
  50. return HRTIMER_NORESTART;
  51. }
  52. void ieee802154_xmit_complete(struct ieee802154_hw *hw, struct sk_buff *skb,
  53. bool ifs_handling)
  54. {
  55. if (ifs_handling) {
  56. struct ieee802154_local *local = hw_to_local(hw);
  57. u8 max_sifs_size;
  58. /* If transceiver sets CRC on his own we need to use lifs
  59. * threshold len above 16 otherwise 18, because it's not
  60. * part of skb->len.
  61. */
  62. if (hw->flags & IEEE802154_HW_TX_OMIT_CKSUM)
  63. max_sifs_size = IEEE802154_MAX_SIFS_FRAME_SIZE -
  64. IEEE802154_FCS_LEN;
  65. else
  66. max_sifs_size = IEEE802154_MAX_SIFS_FRAME_SIZE;
  67. if (skb->len > max_sifs_size)
  68. hrtimer_start(&local->ifs_timer,
  69. ktime_set(0, hw->phy->lifs_period * NSEC_PER_USEC),
  70. HRTIMER_MODE_REL);
  71. else
  72. hrtimer_start(&local->ifs_timer,
  73. ktime_set(0, hw->phy->sifs_period * NSEC_PER_USEC),
  74. HRTIMER_MODE_REL);
  75. } else {
  76. ieee802154_wake_queue(hw);
  77. }
  78. dev_consume_skb_any(skb);
  79. }
  80. EXPORT_SYMBOL(ieee802154_xmit_complete);
  81. void ieee802154_stop_device(struct ieee802154_local *local)
  82. {
  83. flush_workqueue(local->workqueue);
  84. hrtimer_cancel(&local->ifs_timer);
  85. drv_stop(local);
  86. }