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