util.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. *
  4. * Authors:
  5. * Alexander Aring <[email protected]>
  6. *
  7. * Based on: net/mac80211/util.c
  8. */
  9. #include "ieee802154_i.h"
  10. #include "driver-ops.h"
  11. /* privid for wpan_phys to determine whether they belong to us or not */
  12. const void *const mac802154_wpan_phy_privid = &mac802154_wpan_phy_privid;
  13. void ieee802154_wake_queue(struct ieee802154_hw *hw)
  14. {
  15. struct ieee802154_local *local = hw_to_local(hw);
  16. struct ieee802154_sub_if_data *sdata;
  17. rcu_read_lock();
  18. list_for_each_entry_rcu(sdata, &local->interfaces, list) {
  19. if (!sdata->dev)
  20. continue;
  21. netif_wake_queue(sdata->dev);
  22. }
  23. rcu_read_unlock();
  24. }
  25. EXPORT_SYMBOL(ieee802154_wake_queue);
  26. void ieee802154_stop_queue(struct ieee802154_hw *hw)
  27. {
  28. struct ieee802154_local *local = hw_to_local(hw);
  29. struct ieee802154_sub_if_data *sdata;
  30. rcu_read_lock();
  31. list_for_each_entry_rcu(sdata, &local->interfaces, list) {
  32. if (!sdata->dev)
  33. continue;
  34. netif_stop_queue(sdata->dev);
  35. }
  36. rcu_read_unlock();
  37. }
  38. EXPORT_SYMBOL(ieee802154_stop_queue);
  39. enum hrtimer_restart ieee802154_xmit_ifs_timer(struct hrtimer *timer)
  40. {
  41. struct ieee802154_local *local =
  42. container_of(timer, struct ieee802154_local, ifs_timer);
  43. ieee802154_wake_queue(&local->hw);
  44. return HRTIMER_NORESTART;
  45. }
  46. void ieee802154_xmit_complete(struct ieee802154_hw *hw, struct sk_buff *skb,
  47. bool ifs_handling)
  48. {
  49. struct ieee802154_local *local = hw_to_local(hw);
  50. local->tx_result = IEEE802154_SUCCESS;
  51. if (ifs_handling) {
  52. u8 max_sifs_size;
  53. /* If transceiver sets CRC on his own we need to use lifs
  54. * threshold len above 16 otherwise 18, because it's not
  55. * part of skb->len.
  56. */
  57. if (hw->flags & IEEE802154_HW_TX_OMIT_CKSUM)
  58. max_sifs_size = IEEE802154_MAX_SIFS_FRAME_SIZE -
  59. IEEE802154_FCS_LEN;
  60. else
  61. max_sifs_size = IEEE802154_MAX_SIFS_FRAME_SIZE;
  62. if (skb->len > max_sifs_size)
  63. hrtimer_start(&local->ifs_timer,
  64. hw->phy->lifs_period * NSEC_PER_USEC,
  65. HRTIMER_MODE_REL);
  66. else
  67. hrtimer_start(&local->ifs_timer,
  68. hw->phy->sifs_period * NSEC_PER_USEC,
  69. HRTIMER_MODE_REL);
  70. } else {
  71. ieee802154_wake_queue(hw);
  72. }
  73. dev_consume_skb_any(skb);
  74. }
  75. EXPORT_SYMBOL(ieee802154_xmit_complete);
  76. void ieee802154_xmit_error(struct ieee802154_hw *hw, struct sk_buff *skb,
  77. int reason)
  78. {
  79. struct ieee802154_local *local = hw_to_local(hw);
  80. local->tx_result = reason;
  81. ieee802154_wake_queue(hw);
  82. dev_kfree_skb_any(skb);
  83. }
  84. EXPORT_SYMBOL(ieee802154_xmit_error);
  85. void ieee802154_xmit_hw_error(struct ieee802154_hw *hw, struct sk_buff *skb)
  86. {
  87. ieee802154_xmit_error(hw, skb, IEEE802154_SYSTEM_ERROR);
  88. }
  89. EXPORT_SYMBOL(ieee802154_xmit_hw_error);
  90. void ieee802154_stop_device(struct ieee802154_local *local)
  91. {
  92. flush_workqueue(local->workqueue);
  93. hrtimer_cancel(&local->ifs_timer);
  94. drv_stop(local);
  95. }