blob: 150bf807e572eb85458371d1c8e930e2cb7ec0b2 [file] [log] [blame]
Alexander Aringc2085102014-10-26 09:37:05 +01001/* 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"
17
Alexander Aring6322d502014-11-12 03:36:51 +010018/* privid for wpan_phys to determine whether they belong to us or not */
19const void *const mac802154_wpan_phy_privid = &mac802154_wpan_phy_privid;
20
Alexander Aringc2085102014-10-26 09:37:05 +010021void ieee802154_wake_queue(struct ieee802154_hw *hw)
22{
23 struct ieee802154_local *local = hw_to_local(hw);
24 struct ieee802154_sub_if_data *sdata;
25
26 rcu_read_lock();
27 list_for_each_entry_rcu(sdata, &local->interfaces, list) {
28 if (!sdata->dev)
29 continue;
30
31 netif_wake_queue(sdata->dev);
32 }
33 rcu_read_unlock();
34}
35EXPORT_SYMBOL(ieee802154_wake_queue);
36
37void ieee802154_stop_queue(struct ieee802154_hw *hw)
38{
39 struct ieee802154_local *local = hw_to_local(hw);
40 struct ieee802154_sub_if_data *sdata;
41
42 rcu_read_lock();
43 list_for_each_entry_rcu(sdata, &local->interfaces, list) {
44 if (!sdata->dev)
45 continue;
46
47 netif_stop_queue(sdata->dev);
48 }
49 rcu_read_unlock();
50}
51EXPORT_SYMBOL(ieee802154_stop_queue);
52
Alexander Aring61f2dcb2014-11-12 19:51:56 +010053enum hrtimer_restart ieee802154_xmit_ifs_timer(struct hrtimer *timer)
Alexander Aringc2085102014-10-26 09:37:05 +010054{
Alexander Aring61f2dcb2014-11-12 19:51:56 +010055 struct ieee802154_local *local =
56 container_of(timer, struct ieee802154_local, ifs_timer);
57
58 ieee802154_wake_queue(&local->hw);
59
60 return HRTIMER_NORESTART;
61}
62
63void ieee802154_xmit_complete(struct ieee802154_hw *hw, struct sk_buff *skb,
64 bool ifs_handling)
65{
66 if (ifs_handling) {
67 struct ieee802154_local *local = hw_to_local(hw);
Alexander Aring3f3c4bb2015-03-04 21:19:59 +010068 u8 max_sifs_size;
Alexander Aring61f2dcb2014-11-12 19:51:56 +010069
Alexander Aring3f3c4bb2015-03-04 21:19:59 +010070 /* If transceiver sets CRC on his own we need to use lifs
71 * threshold len above 16 otherwise 18, because it's not
72 * part of skb->len.
73 */
74 if (hw->flags & IEEE802154_HW_TX_OMIT_CKSUM)
75 max_sifs_size = IEEE802154_MAX_SIFS_FRAME_SIZE -
76 IEEE802154_FCS_LEN;
77 else
78 max_sifs_size = IEEE802154_MAX_SIFS_FRAME_SIZE;
79
80 if (skb->len > max_sifs_size)
Alexander Aring61f2dcb2014-11-12 19:51:56 +010081 hrtimer_start(&local->ifs_timer,
82 ktime_set(0, hw->phy->lifs_period * NSEC_PER_USEC),
83 HRTIMER_MODE_REL);
84 else
85 hrtimer_start(&local->ifs_timer,
86 ktime_set(0, hw->phy->sifs_period * NSEC_PER_USEC),
87 HRTIMER_MODE_REL);
88
89 consume_skb(skb);
90 } else {
91 ieee802154_wake_queue(hw);
92 consume_skb(skb);
93 }
Alexander Aringc2085102014-10-26 09:37:05 +010094}
95EXPORT_SYMBOL(ieee802154_xmit_complete);