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