util.c 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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. u8 max_sifs_size;
  57. /* If transceiver sets CRC on his own we need to use lifs
  58. * threshold len above 16 otherwise 18, because it's not
  59. * part of skb->len.
  60. */
  61. if (hw->flags & IEEE802154_HW_TX_OMIT_CKSUM)
  62. max_sifs_size = IEEE802154_MAX_SIFS_FRAME_SIZE -
  63. IEEE802154_FCS_LEN;
  64. else
  65. max_sifs_size = IEEE802154_MAX_SIFS_FRAME_SIZE;
  66. if (skb->len > max_sifs_size)
  67. hrtimer_start(&local->ifs_timer,
  68. ktime_set(0, hw->phy->lifs_period * NSEC_PER_USEC),
  69. HRTIMER_MODE_REL);
  70. else
  71. hrtimer_start(&local->ifs_timer,
  72. ktime_set(0, hw->phy->sifs_period * NSEC_PER_USEC),
  73. HRTIMER_MODE_REL);
  74. } else {
  75. ieee802154_wake_queue(hw);
  76. }
  77. dev_consume_skb_any(skb);
  78. }
  79. EXPORT_SYMBOL(ieee802154_xmit_complete);