ieee802154: mac802154: wireless transformation part 3
Subsystems (5)
Alexander Aring
maintainercover ieee802154: mac802154: wireless transformation part 3
Hi, this is the next series which do mainly a rework of xmit path. Also dropping some kmalloc's from hotpath and remove the channel hopping feature.
We provide now async xmit and the the at86rf230 is the only one mainline driver which supports that for now.
Next things are still frame parsing like 80211 and registration of phy's and interfaces like 80211.
I need to look which is the best to work on the next series.
It's still available on [0], which is my working branch for the mac rework.
- Alex
[0] https://github.com/linux-wpan/linux-wpan-next/commits/wpan_rework_rfc
Alexander Aring (12):
mac802154: tx: move xmit callback to tx file
mac802154: make struct ieee802154_ops const
mac802154: add netdev qeue helpers
mac802154: tx: remove kmalloc in xmit hotpath
mac802154: tx: remove xmit channel context switch
mac802154: tx: add drv_xmit to driver-ops
mac802154: tx: fix error handling on xmit
mac802154: tx: add support for async xmit callback
at86rf230: asynchrous xmit handling
ieee802154: add valid frame length helper
at86rf230: use ieee802154_is_valid_frame_len
at86rf230: improve receive handling
drivers/net/ieee802154/at86rf230.c | 64 +++++++-------------- drivers/net/ieee802154/cc2520.c | 4 +- drivers/net/ieee802154/mrf24j40.c | 4 +- include/net/ieee802154.h | 10 +++- include/net/mac802154.h | 15 ++++- net/mac802154/Makefile | 2 +- net/mac802154/driver-ops.h | 12 ++++ net/mac802154/ieee802154_i.h | 6 +- net/mac802154/iface.c | 33 ----------- net/mac802154/main.c | 6 +- net/mac802154/tx.c | 114 ++++++++++++++++++------------------- net/mac802154/util.c | 55 ++++++++++++++++++ 12 files changed, 177 insertions(+), 148 deletions(-) create mode 100644 net/mac802154/util.c
Signature · 1 line
2.0.3
Alexander Aring
maintainerPATCH 1/12 mac802154: tx: move xmit callback to tx file
This patch moves the mac802154_wpan_xmit function into the tx.c file. Currently this callback is named wpan inidcates that this callback is for WPAN (NODE) virtual interfaces.
In future this should be a generic function, we do a switch case over interface type variable to make different interface type handling.
--- net/mac802154/ieee802154_i.h | 4 +--- net/mac802154/iface.c | 33 --------------------------------- net/mac802154/tx.c | 36 ++++++++++++++++++++++++++++++++++-- 3 files changed, 35 insertions(+), 38 deletions(-)
net/mac802154/ieee802154_i.h +1 -3
@@ -136,9 +136,7 @@ extern struct ieee802154_reduced_mlme_ops mac802154_mlme_reduced;extern struct ieee802154_mlme_ops mac802154_mlme_wpan;void mac802154_wpan_setup (struct net_device *dev); - -netdev_tx_t mac802154_tx (struct ieee802154_local *local,struct sk_buff *skb, -u8 page,u8 chan); +netdev_tx_t mac802154_wpan_xmit (struct sk_buff *skb,struct net_device *dev);/* MIB callbacks */ void mac802154_dev_set_short_addr (struct net_device *dev,__le16 val);
net/mac802154/iface.c +0 -33
@@ -377,39 +377,6 @@ mac802154_header_parse(const struct sk_buff *skb, unsigned char *haddr)return sizeof (*addr); } -static netdev_tx_t -mac802154_wpan_xmit (struct sk_buff *skb,struct net_device *dev) -{ -struct ieee802154_sub_if_data *sdata =IEEE802154_DEV_TO_SUB_IF (dev); -u8 chan, page; -int rc; - -spin_lock_bh (&sdata->mib_lock); - chan = sdata->chan; - page = sdata->page; -spin_unlock_bh (&sdata->mib_lock); - -if (chan ==MAC802154_CHAN_NONE || - page >=WPAN_NUM_PAGES || - chan >=WPAN_NUM_CHANNELS ) { -kfree_skb (skb); -return NETDEV_TX_OK ; - } - - rc =mac802154_llsec_encrypt (&sdata->sec, skb); -if (rc) { -pr_warn ("encryption failed: %i\n" , rc); -kfree_skb (skb); -return NETDEV_TX_OK ; - } - - skb->skb_iif = dev->ifindex; - dev->stats.tx_packets++; - dev->stats.tx_bytes += skb->len; - -return mac802154_tx (sdata->local, skb, page, chan); -} -static struct header_ops mac802154_header_ops = { .create = mac802154_header_create, .parse = mac802154_header_parse,
net/mac802154/tx.c +34 -2
@@ -81,8 +81,8 @@ out:kfree (xw); } -netdev_tx_t mac802154_tx (struct ieee802154_local *local,struct sk_buff *skb, -u8 page,u8 chan) +static netdev_tx_t mac802154_tx (struct ieee802154_local *local, +struct sk_buff *skb,u8 page,u8 chan) {struct xmit_work *work;struct ieee802154_sub_if_data *sdata;
@@ -129,3 +129,35 @@ err_tx:kfree_skb (skb);return NETDEV_TX_OK ; } + +netdev_tx_t mac802154_wpan_xmit (struct sk_buff *skb,struct net_device *dev) +{ +struct ieee802154_sub_if_data *sdata =IEEE802154_DEV_TO_SUB_IF (dev); +u8 chan, page; +int rc; + +spin_lock_bh (&sdata->mib_lock); + chan = sdata->chan; + page = sdata->page; +spin_unlock_bh (&sdata->mib_lock); + +if (chan ==MAC802154_CHAN_NONE || + page >=WPAN_NUM_PAGES || + chan >=WPAN_NUM_CHANNELS ) { +kfree_skb (skb); +return NETDEV_TX_OK ; + } + + rc =mac802154_llsec_encrypt (&sdata->sec, skb); +if (rc) { +pr_warn ("encryption failed: %i\n" , rc); +kfree_skb (skb); +return NETDEV_TX_OK ; + } + + skb->skb_iif = dev->ifindex; + dev->stats.tx_packets++; + dev->stats.tx_bytes += skb->len; + +return mac802154_tx (sdata->local, skb, page, chan); +}
Signature · 1 line
2.0.3
Alexander Aring
maintainerPATCH 2/12 mac802154: make struct ieee802154_ops const
In reply to Alexander AringThe ieee802154_ops should never be changed during runtime.
--- drivers/net/ieee802154/at86rf230.c | 2 +- drivers/net/ieee802154/cc2520.c | 2 +- drivers/net/ieee802154/mrf24j40.c | 2 +- include/net/mac802154.h | 2 +- net/mac802154/ieee802154_i.h | 2 +- net/mac802154/main.c | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-)
drivers/net/ieee802154/at86rf230.c +1 -1
@@ -1235,7 +1235,7 @@ at86rf230_set_frame_retries(struct ieee802154_hw *hw, s8 retries)return rc; } -static struct ieee802154_ops at86rf230_ops = { +static const struct ieee802154_ops at86rf230_ops = { .owner =THIS_MODULE , .xmit = at86rf230_xmit, .ed = at86rf230_ed,
drivers/net/ieee802154/cc2520.c +1 -1
@@ -631,7 +631,7 @@ cc2520_filter(struct ieee802154_hw *hw,return 0 ; } -static struct ieee802154_ops cc2520_ops = { +static const struct ieee802154_ops cc2520_ops = { .owner =THIS_MODULE , .start = cc2520_start, .stop = cc2520_stop,
drivers/net/ieee802154/mrf24j40.c +1 -1
@@ -577,7 +577,7 @@ out:return ret; } -static struct ieee802154_ops mrf24j40_ops = { +static const struct ieee802154_ops mrf24j40_ops = { .owner =THIS_MODULE , .xmit = mrf24j40_tx, .ed = mrf24j40_ed,
include/net/mac802154.h +1 -1
@@ -186,7 +186,7 @@ struct ieee802154_ops {/* Basic interface to register ieee802154 hwice */ struct ieee802154_hw * -ieee802154_alloc_hw (size_t priv_data_len,struct ieee802154_ops *ops); +ieee802154_alloc_hw (size_t priv_data_len,const struct ieee802154_ops *ops);void ieee802154_free_hw (struct ieee802154_hw *hw);int ieee802154_register_hw (struct ieee802154_hw *hw);void ieee802154_unregister_hw (struct ieee802154_hw *hw);
net/mac802154/ieee802154_i.h +1 -1
@@ -77,7 +77,7 @@ struct ieee802154_sub_if_data {/* mac802154 device private data */ struct ieee802154_local {struct ieee802154_hw hw; -struct ieee802154_ops *ops; +const struct ieee802154_ops *ops;/* ieee802154 phy */ struct wpan_phy *phy;
net/mac802154/main.c +1 -1
@@ -182,7 +182,7 @@ static void ieee802154_tasklet_handler(unsigned long data) }struct ieee802154_hw * -ieee802154_alloc_hw (size_t priv_data_len,struct ieee802154_ops *ops) +ieee802154_alloc_hw (size_t priv_data_len,const struct ieee802154_ops *ops) {struct wpan_phy *phy;struct ieee802154_local *local;
Signature · 1 line
2.0.3
Alexander Aring
maintainerPATCH 3/12 mac802154: add netdev qeue helpers
In reply to Alexander AringThis patch adds a new file net/mac802154/util.c which contains utility functions for drivers, etc.
This file contains functions to start and stop queues for all virtual interfaces, this is useful for asynchronous handling in driver level. In future the ieee802154_xmit_complete function should be contain a delay for interfame spacing time, for now we don't provide this information inside the mac layer.
--- include/net/mac802154.h | 4 ++++ net/mac802154/Makefile | 2 +- net/mac802154/tx.c | 14 ++----------- net/mac802154/util.c | 55 +++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 62 insertions(+), 13 deletions(-) create mode 100644 net/mac802154/util.c
include/net/mac802154.h +4 -0
@@ -196,4 +196,8 @@ void ieee802154_rx_irqsafe(struct ieee802154_hw *hw, struct sk_buff *skb,void ieee802154_rx (struct ieee802154_hw *hw,struct sk_buff *skb); +void ieee802154_wake_queue (struct ieee802154_hw *hw); +void ieee802154_stop_queue (struct ieee802154_hw *hw); +void ieee802154_xmit_complete (struct ieee802154_hw *hw,struct sk_buff *skb); +#endif /* NET_MAC802154_H */
net/mac802154/Makefile +1 -1
@@ -1,5 +1,5 @@ obj-$(CONFIG_MAC802154) += mac802154.o mac802154-objs := main.o rx.o tx.o mac_cmd.o mib.o \ - iface.o llsec.o + iface.o llsec.o util.o ccflags-y += -D__CHECK_ENDIAN__
net/mac802154/tx.c +2 -12
@@ -45,7 +45,6 @@ struct xmit_work {static void mac802154_xmit_worker (struct work_struct *work) { struct xmit_work *xw = container_of(work, struct xmit_work, work); -struct ieee802154_sub_if_data *sdata;int res;mutex_lock (&xw->local->phy->pib_lock);
@@ -71,12 +70,7 @@ out:mutex_unlock (&xw->local->phy->pib_lock);/* Restart the netif queue on each sub_if_data object. */ -rcu_read_lock (); -list_for_each_entry_rcu (sdata, &xw->local->interfaces, list) -netif_wake_queue (sdata->dev); -rcu_read_unlock (); - -dev_kfree_skb (xw->skb); +ieee802154_xmit_complete (&local->hw, skb);kfree (xw); }
@@ -85,7 +79,6 @@ static netdev_tx_t mac802154_tx(struct ieee802154_local *local, struct sk_buff *skb, u8 page, u8 chan) { struct xmit_work *work; -struct ieee802154_sub_if_data *sdata;if (!(local->phy->channels_supported[page] & (1 << chan))) {WARN_ON (1 );
@@ -110,10 +103,7 @@ static netdev_tx_t mac802154_tx(struct ieee802154_local *local, }/* Stop the netif queue on each sub_if_data object. */ -rcu_read_lock (); -list_for_each_entry_rcu (sdata, &local->interfaces, list) -netif_stop_queue (sdata->dev); -rcu_read_unlock (); +ieee802154_stop_queue (&local->hw);INIT_WORK (&work->work, mac802154_xmit_worker); work->skb = skb;
net/mac802154/util.c new file +55 -0
55 lines not on this page · raw message
Signature · 1 line
2.0.3
Alexander Aring
maintainerPATCH 4/12 mac802154: tx: remove kmalloc in xmit hotpath
In reply to Alexander AringThis patch removes the kmalloc allocation for workqueue data. This patch replace the kmalloc and use the control block of skb. The control block have enough space and isn't use by any other layer in this case.
--- net/mac802154/tx.c | 51 ++++++++++++++++++++++++--------------------------- 1 file changed, 24 insertions(+), 27 deletions(-)
net/mac802154/tx.c +24 -27
@@ -34,7 +34,7 @@/* IEEE 802.15.4 transceivers can sleep during the xmit session, so process * packets through the workqueue. */ -struct xmit_work { +struct wpan_xmit_cb {struct sk_buff *skb;struct work_struct work;struct ieee802154_local *local;
@@ -42,43 +42,46 @@ struct xmit_work {u8 page; }; +static struct wpan_xmit_cb *wpan_xmit_cb (struct sk_buff *skb) +{ +return (struct wpan_xmit_cb *)skb->cb; +} +static void mac802154_xmit_worker (struct work_struct *work) { - struct xmit_work *xw = container_of(work, struct xmit_work, work); + struct wpan_xmit_cb *cb = container_of(work, struct wpan_xmit_cb, work); +struct ieee802154_local *local = cb->local; +struct sk_buff *skb = cb->skb;int res; -mutex_lock (&xw->local->phy->pib_lock); -if (xw->local->phy->current_channel != xw->chan || - xw->local->phy->current_page != xw->page) { - res = xw->local->ops->set_channel (&xw->local->hw, - xw->page, - xw->chan); +mutex_lock (&local->phy->pib_lock); +if (local->phy->current_channel != cb->chan || + local->phy->current_page != cb->page) { + res = local->ops->set_channel (&local->hw, cb->page, cb->chan);if (res) {pr_debug ("set_channel failed\n" ); goto out; } - xw->local->phy->current_channel = xw->chan; - xw->local->phy->current_page = xw->page; + local->phy->current_channel = cb->chan; + local->phy->current_page = cb->page; } - res = xw->local->ops->xmit (&xw->local->hw, xw->skb); + res = local->ops->xmit (&cb->local->hw, skb);if (res)pr_debug ("transmission failed\n" ); out: -mutex_unlock (&xw->local->phy->pib_lock); +mutex_unlock (&local->phy->pib_lock);/* Restart the netif queue on each sub_if_data object. */ ieee802154_xmit_complete (&local->hw, skb); - -kfree (xw); }static netdev_tx_t mac802154_tx (struct ieee802154_local *local,struct sk_buff *skb,u8 page,u8 chan) { -struct xmit_work *work; +struct wpan_xmit_cb *cb =wpan_xmit_cb (skb);if (!(local->phy->channels_supported[page] & (1 << chan))) {WARN_ON (1 );
@@ -96,22 +99,16 @@ static netdev_tx_t mac802154_tx(struct ieee802154_local *local,if (skb_cow_head (skb, local->hw.extra_tx_headroom)) goto err_tx; - work =kzalloc (sizeof (*work),GFP_ATOMIC ); -if (!work) { -kfree_skb (skb); -return NETDEV_TX_BUSY ; - } -/* Stop the netif queue on each sub_if_data object. */ ieee802154_stop_queue (&local->hw); -INIT_WORK (&work->work, mac802154_xmit_worker); - work->skb = skb; - work->local = local; - work->page = page; - work->chan = chan; +INIT_WORK (&cb->work, mac802154_xmit_worker); + cb->skb = skb; + cb->local = local; + cb->page = page; + cb->chan = chan; -queue_work (local->dev_workqueue, &work->work); +queue_work (local->dev_workqueue, &cb->work);return NETDEV_TX_OK ;
Signature · 1 line
2.0.3
Re: [PATCH wpan-next 04/12] mac802154: tx: remove kmalloc in xmit hotpath
Quoted 25 lines
This patch removes the kmalloc allocation for workqueue data. This patch replace the kmalloc and use the control block of skb. The control block have enough space and isn't use by any other layer in this case.
Signed-off-by Alexander Aring <[email protected]>--- net/mac802154/tx.c | 51 ++++++++++++++++++++++++--------------------------- 1 file changed, 24 insertions(+), 27 deletions(-)net/mac802154/tx.c +0
-0@@ -34,7 +34,7 @@/* IEEE 802.15.4 transceivers can sleep during the xmit session, so process
* packets through the workqueue.
*/net/mac802154/tx.c +1
-1-struct xmit_work { +struct wpan_xmit_cb {struct sk_buff *skb;struct work_struct work;struct ieee802154_local *local;
net/mac802154/tx.c struct xmit_work { · line 46
Quoted 5 lines
net/mac802154/tx.c +2
-0@@ -42,43 +42,46 @@ struct xmit_work {u8 page; }; +static struct wpan_xmit_cb *wpan_xmit_cb (struct sk_buff *skb) +{
Do add a BUILD_BUG_ON(sizeof(struct wpan_xmit_cb) > sizeof(skb->cb)) to make sure the struct will *always* fit, even if we choose to resize it for whatever reason.
Quoted 93 lines
net/mac802154/tx.c +21
-27+return (struct wpan_xmit_cb *)skb->cb; +} +static void mac802154_xmit_worker (struct work_struct *work) { - struct xmit_work *xw = container_of(work, struct xmit_work, work); + struct wpan_xmit_cb *cb = container_of(work, struct wpan_xmit_cb, work); +struct ieee802154_local *local = cb->local; +struct sk_buff *skb = cb->skb;int res; -mutex_lock (&xw->local->phy->pib_lock); -if (xw->local->phy->current_channel != xw->chan || - xw->local->phy->current_page != xw->page) { - res = xw->local->ops->set_channel (&xw->local->hw, - xw->page, - xw->chan); +mutex_lock (&local->phy->pib_lock); +if (local->phy->current_channel != cb->chan || + local->phy->current_page != cb->page) { + res = local->ops->set_channel (&local->hw, cb->page, cb->chan);if (res) {pr_debug ("set_channel failed\n" ); goto out; } - xw->local->phy->current_channel = xw->chan; - xw->local->phy->current_page = xw->page; + local->phy->current_channel = cb->chan; + local->phy->current_page = cb->page; } - res = xw->local->ops->xmit (&xw->local->hw, xw->skb); + res = local->ops->xmit (&cb->local->hw, skb);if (res)pr_debug ("transmission failed\n" ); out: -mutex_unlock (&xw->local->phy->pib_lock); +mutex_unlock (&local->phy->pib_lock);/* Restart the netif queue on each sub_if_data object. */ ieee802154_xmit_complete (&local->hw, skb); - -kfree (xw); }static netdev_tx_t mac802154_tx (struct ieee802154_local *local,struct sk_buff *skb,u8 page,u8 chan) { -struct xmit_work *work; +struct wpan_xmit_cb *cb =wpan_xmit_cb (skb);if (!(local->phy->channels_supported[page] & (1 << chan))) {WARN_ON (1 );@@ -96,22 +99,16 @@ static netdev_tx_t mac802154_tx(struct ieee802154_local *local, if (skb_cow_head(skb, local->hw.extra_tx_headroom)) goto err_tx; - work =kzalloc (sizeof (*work),GFP_ATOMIC ); -if (!work) { -kfree_skb (skb); -return NETDEV_TX_BUSY ; - } -/* Stop the netif queue on each sub_if_data object. */ ieee802154_stop_queue (&local->hw); -INIT_WORK (&work->work, mac802154_xmit_worker); - work->skb = skb; - work->local = local; - work->page = page; - work->chan = chan; +INIT_WORK (&cb->work, mac802154_xmit_worker); + cb->skb = skb; + cb->local = local; + cb->page = page; + cb->chan = chan; -queue_work (local->dev_workqueue, &work->work); +queue_work (local->dev_workqueue, &cb->work);return NETDEV_TX_OK ; --2.0.3
--
To unsubscribe from this list: send the line "unsubscribe linux-wpan" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Alexander Aring
maintainerRe: [PATCH wpan-next 04/12] mac802154: tx: remove kmalloc in xmit hotpath
Quoted 28 lines · Phoebe Buckheister
Quoted 28 lines
This patch removes the kmalloc allocation for workqueue data. This patch replace the kmalloc and use the control block of skb. The control block have enough space and isn't use by any other layer in this case.
Signed-off-by Alexander Aring <[email protected]>--- net/mac802154/tx.c | 51 ++++++++++++++++++++++++--------------------------- 1 file changed, 24 insertions(+), 27 deletions(-)net/mac802154/tx.c +0
-0@@ -34,7 +34,7 @@/* IEEE 802.15.4 transceivers can sleep during the xmit session, so process
* packets through the workqueue.
*/net/mac802154/tx.c +1
-1-struct xmit_work { +struct wpan_xmit_cb {struct sk_buff *skb;struct work_struct work;struct ieee802154_local *local;@@ -42,43 +42,46 @@ struct xmit_work {u8 page; };
Quoted 6 lines
net/mac802154/tx.c struct xmit_work { · line 46
Quoted 2 lines
net/mac802154/tx.c +2
-0+static struct wpan_xmit_cb *wpan_xmit_cb (struct sk_buff *skb) +{Do add a
BUILD_BUG_ON(sizeof(struct wpan_xmit_cb) > sizeof(skb->cb))to make sure the struct will *always* fit, even if we choose to resize it for whatever reason.
Ok, thanks. I also add a inline to this function. Thanks.
- Alex
Alexander Aring
maintainerPATCH 5/12 mac802154: tx: remove xmit channel context switch
In reply to Alexander AringThis patch removes the channel hoping feature before xmit. There are several issues to provide a real channel hoping (timing requirements, etc.). It's not very useful at the moment. In my opinion this was added for support RF4CE and doing some userspace magic to do some channel hoping.
We don't have any known kernelspace protocol which really use this featyre. We simply drop this feature now.
--- net/mac802154/tx.c | 44 +++----------------------------------------- 1 file changed, 3 insertions(+), 41 deletions(-)
net/mac802154/tx.c +3 -41
@@ -38,8 +38,6 @@ struct wpan_xmit_cb {struct sk_buff *skb;struct work_struct work;struct ieee802154_local *local; -u8 chan; -u8 page; };static struct wpan_xmit_cb *wpan_xmit_cb (struct sk_buff *skb)
@@ -54,40 +52,19 @@ static void mac802154_xmit_worker(struct work_struct *work)struct sk_buff *skb = cb->skb;int res; -mutex_lock (&local->phy->pib_lock); -if (local->phy->current_channel != cb->chan || - local->phy->current_page != cb->page) { - res = local->ops->set_channel (&local->hw, cb->page, cb->chan); -if (res) { -pr_debug ("set_channel failed\n" ); - goto out; - } - - local->phy->current_channel = cb->chan; - local->phy->current_page = cb->page; - } - res = local->ops->xmit (&cb->local->hw, skb);if (res)pr_debug ("transmission failed\n" ); -out: -mutex_unlock (&local->phy->pib_lock); -/* Restart the netif queue on each sub_if_data object. */ ieee802154_xmit_complete (&local->hw, skb); } -static netdev_tx_t mac802154_tx (struct ieee802154_local *local, -struct sk_buff *skb,u8 page,u8 chan) +static netdev_tx_t +mac802154_tx (struct ieee802154_local *local,struct sk_buff *skb) {struct wpan_xmit_cb *cb =wpan_xmit_cb (skb); -if (!(local->phy->channels_supported[page] & (1 << chan))) { -WARN_ON (1 ); - goto err_tx; - } -if (!(local->hw.flags &IEEE802154_HW_OMIT_CKSUM )) {u16 crc =crc_ccitt (0 , skb->data, skb->len);u8 *data =skb_put (skb,2 );
@@ -105,8 +82,6 @@ static netdev_tx_t mac802154_tx(struct ieee802154_local *local,INIT_WORK (&cb->work, mac802154_xmit_worker); cb->skb = skb; cb->local = local; - cb->page = page; - cb->chan = chan;queue_work (local->dev_workqueue, &cb->work);
@@ -120,21 +95,8 @@ err_tx:netdev_tx_t mac802154_wpan_xmit (struct sk_buff *skb,struct net_device *dev) {struct ieee802154_sub_if_data *sdata =IEEE802154_DEV_TO_SUB_IF (dev); -u8 chan, page;int rc; -spin_lock_bh (&sdata->mib_lock); - chan = sdata->chan; - page = sdata->page; -spin_unlock_bh (&sdata->mib_lock); - -if (chan ==MAC802154_CHAN_NONE || - page >=WPAN_NUM_PAGES || - chan >=WPAN_NUM_CHANNELS ) { -kfree_skb (skb); -return NETDEV_TX_OK ; - } - rc =mac802154_llsec_encrypt (&sdata->sec, skb);if (rc) {pr_warn ("encryption failed: %i\n" , rc);
@@ -146,5 +108,5 @@ netdev_tx_t mac802154_wpan_xmit(struct sk_buff *skb, struct net_device *dev) dev->stats.tx_packets++; dev->stats.tx_bytes += skb->len; -return mac802154_tx (sdata->local, skb, page, chan); +return mac802154_tx (sdata->local, skb); }
Signature · 1 line
2.0.3
Alexander Aring
maintainerPATCH 6/12 mac802154: tx: add drv_xmit to driver-ops
In reply to Alexander AringThis patch adds a new helper for calling the xmit callback from ieee802154_ops.
--- net/mac802154/driver-ops.h | 6 ++++++ net/mac802154/tx.c | 3 ++- 2 files changed, 8 insertions(+), 1 deletion(-)
net/mac802154/driver-ops.h +6 -0
@@ -5,6 +5,12 @@#include "ieee802154_i.h" +static inline int +drv_xmit (struct ieee802154_local *local,struct sk_buff *skb) +{ +return local->ops->xmit (&local->hw, skb); +} +static inline int drv_start (struct ieee802154_local *local) {might_sleep ();
net/mac802154/tx.c +2 -1
@@ -30,6 +30,7 @@#include <net/wpan-phy.h> #include "ieee802154_i.h" +#include "driver-ops.h" /* IEEE 802.15.4 transceivers can sleep during the xmit session, so process * packets through the workqueue.
@@ -52,7 +53,7 @@ static void mac802154_xmit_worker(struct work_struct *work)struct sk_buff *skb = cb->skb;int res; - res = local->ops->xmit (&cb->local->hw, skb); + res =drv_xmit (local, skb);if (res)pr_debug ("transmission failed\n" );
Signature · 1 line
2.0.3
Alexander Aring
maintainerPATCH 7/12 mac802154: tx: fix error handling on xmit
In reply to Alexander AringIf error occur we should call kfree_skb instead of dev_kfree_skb or consume_skb.
--- net/mac802154/tx.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
net/mac802154/tx.c +5 -1
@@ -54,8 +54,12 @@ static void mac802154_xmit_worker(struct work_struct *work)int res; res =drv_xmit (local, skb); -if (res) +if (res) {pr_debug ("transmission failed\n" ); +ieee802154_wake_queue (&local->hw); +kfree_skb (skb); +return ; + }/* Restart the netif queue on each sub_if_data object. */ ieee802154_xmit_complete (&local->hw, skb);
Signature · 1 line
2.0.3
Alexander Aring
maintainerPATCH 8/12 mac802154: tx: add support for async xmit callback
In reply to Alexander AringThis patch renames the existsing xmit callback to xmit_sync and introduce a asynchronous xmit handling. If ieee802154_ops doesn't provide the async xmit callback, then we have a fallback to the xmit_sync callback.
--- drivers/net/ieee802154/at86rf230.c | 2 +- drivers/net/ieee802154/cc2520.c | 2 +- drivers/net/ieee802154/mrf24j40.c | 2 +- include/net/mac802154.h | 9 +++++++++ net/mac802154/driver-ops.h | 6 ++++++ net/mac802154/main.c | 4 ++-- net/mac802154/tx.c | 14 +++++++++++++- 7 files changed, 33 insertions(+), 6 deletions(-)
drivers/net/ieee802154/at86rf230.c +1 -1
@@ -1237,7 +1237,7 @@ at86rf230_set_frame_retries(struct ieee802154_hw *hw, s8 retries)static const struct ieee802154_ops at86rf230_ops = { .owner =THIS_MODULE , - .xmit = at86rf230_xmit, + .xmit_sync = at86rf230_xmit, .ed = at86rf230_ed, .set_channel = at86rf230_channel, .start = at86rf230_start,
drivers/net/ieee802154/cc2520.c +1 -1
@@ -635,7 +635,7 @@ static const struct ieee802154_ops cc2520_ops = { .owner = THIS_MODULE, .start = cc2520_start, .stop = cc2520_stop, - .xmit = cc2520_tx, + .xmit_sync = cc2520_tx, .ed = cc2520_ed, .set_channel = cc2520_set_channel, .set_hw_addr_filt = cc2520_filter,
drivers/net/ieee802154/mrf24j40.c +1 -1
@@ -579,7 +579,7 @@ out:static const struct ieee802154_ops mrf24j40_ops = { .owner =THIS_MODULE , - .xmit = mrf24j40_tx, + .xmit_sync = mrf24j40_tx, .ed = mrf24j40_ed, .start = mrf24j40_start, .stop = mrf24j40_stop,
include/net/mac802154.h +9 -0
@@ -112,6 +112,13 @@ struct ieee802154_hw {* stop: Handler that 802.15.4 module calls for device cleanup. * This function is called after the last interface is removed. * +* xmit_sync: +* Handler that 802.15.4 module calls for each transmitted frame. +* skb cntains the buffer starting from the IEEE 802.15.4 header. +* The low-level driver should send the frame based on available +* configuration. This is called by a workqueue and useful for +* synchronous 802.15.4 drivers. +* * xmit: Handler that 802.15.4 module calls for each transmitted frame. * skb cntains the buffer starting from the IEEE 802.15.4 header. * The low-level driver should send the frame based on available
@@ -164,6 +171,8 @@ struct ieee802154_ops {struct module *owner;int (*start)(struct ieee802154_hw *hw);void (*stop)(struct ieee802154_hw *hw); +int (*xmit_sync)(struct ieee802154_hw *hw, +struct sk_buff *skb);int (*xmit)(struct ieee802154_hw *hw,struct sk_buff *skb);int (*ed)(struct ieee802154_hw *hw,u8 *level);
net/mac802154/driver-ops.h +6 -0
@@ -11,6 +11,12 @@ drv_xmit(struct ieee802154_local *local, struct sk_buff *skb)return local->ops->xmit (&local->hw, skb); } +static inline int +drv_xmit_sync (struct ieee802154_local *local,struct sk_buff *skb) +{ +return local->ops->xmit_sync (&local->hw, skb); +} +static inline int drv_start (struct ieee802154_local *local) {might_sleep ();
net/mac802154/main.c +2 -2
@@ -188,8 +188,8 @@ ieee802154_alloc_hw(size_t priv_data_len, const struct ieee802154_ops *ops)struct ieee802154_local *local;size_t priv_size; -if (!ops || !ops->xmit || !ops->ed || !ops->start || - !ops->stop || !ops->set_channel) { +if (!ops || !(ops->xmit || ops->xmit_sync) || !ops->ed || + !ops->start || !ops->stop || !ops->set_channel) {pr_err ("undefined IEEE802.15.4 device operations\n" );return NULL ; }
net/mac802154/tx.c +13 -1
@@ -53,7 +53,7 @@ static void mac802154_xmit_worker(struct work_struct *work)struct sk_buff *skb = cb->skb;int res; - res =drv_xmit (local, skb); + res =drv_xmit_sync (local, skb);if (res) {pr_debug ("transmission failed\n" );ieee802154_wake_queue (&local->hw);
@@ -69,6 +69,7 @@ static netdev_tx_t mac802154_tx(struct ieee802154_local *local, struct sk_buff *skb) { struct wpan_xmit_cb *cb = wpan_xmit_cb(skb); +int ret;if (!(local->hw.flags &IEEE802154_HW_OMIT_CKSUM )) {u16 crc =crc_ccitt (0 , skb->data, skb->len);
@@ -84,6 +85,17 @@ mac802154_tx(struct ieee802154_local *local, struct sk_buff *skb)/* Stop the netif queue on each sub_if_data object. */ ieee802154_stop_queue (&local->hw); +/* async is priority, otherwise sync is fallback */ +if (local->ops->xmit) { + ret =drv_xmit (local, skb); +if (ret) { +ieee802154_wake_queue (&local->hw); + goto err_tx; + } + +return NETDEV_TX_OK ; + } +INIT_WORK (&cb->work, mac802154_xmit_worker); cb->skb = skb; cb->local = local;
Signature · 1 line
2.0.3
Alexander Aring
maintainerPATCH 9/12 at86rf230: asynchrous xmit handling
In reply to Alexander AringThis patch change the sync xmit handling to an async xmit handling. The driver was mostly prepared to do this step, all other drivers needs an async spi handling to provide that.
--- drivers/net/ieee802154/at86rf230.c | 34 ++++++++++++++-------------------- 1 file changed, 14 insertions(+), 20 deletions(-)
drivers/net/ieee802154/at86rf230.c +14 -20
@@ -92,7 +92,6 @@ struct at86rf230_local {bool is_tx;/* spinlock for is_tx protection */ spinlock_t lock; -struct completion tx_complete;struct sk_buff *tx_skb;struct at86rf230_state_change tx; };
@@ -452,6 +451,7 @@ at86rf230_async_error_recover(void *context)struct at86rf230_local *lp = ctx->lp;at86rf230_async_state_change (lp, ctx,STATE_RX_AACK_ON ,NULL ); +ieee802154_wake_queue (lp->hw); } static void
@@ -701,8 +701,19 @@ at86rf230_tx_complete(void *context) {struct at86rf230_state_change *ctx = context;struct at86rf230_local *lp = ctx->lp; +struct sk_buff *skb = lp->tx_skb; + +/* Interfame spacing time, which is phy depend. +* TODO +* Move this handling in MAC 802.15.4 layer. +* This is currently a workaround to avoid fragmenation issues. +*/ +if (skb->len >18 ) +usleep_range (lp->data->t_lifs, lp->data->t_lifs +10 ); +else +usleep_range (lp->data->t_sifs, lp->data->t_sifs +10 ); -complete (&lp->tx_complete); +ieee802154_xmit_complete (lp->hw, skb); } static void
@@ -992,22 +1003,6 @@ at86rf230_xmit(struct ieee802154_hw *hw, struct sk_buff *skb)at86rf230_async_error (lp, ctx, rc);return rc; } - rc =wait_for_completion_interruptible_timeout (&lp->tx_complete, -msecs_to_jiffies (lp->data->t_tx_timeout)); -if (!rc) { -at86rf230_async_error (lp, ctx, rc); -return -ETIMEDOUT ; - } - -/* Interfame spacing time, which is phy depend. -* TODO -* Move this handling in MAC 802.15.4 layer. -* This is currently a workaround to avoid fragmenation issues. -*/ -if (skb->len >18 ) -usleep_range (lp->data->t_lifs, lp->data->t_lifs +10 ); -else -usleep_range (lp->data->t_sifs, lp->data->t_sifs +10 );return 0 ; }
@@ -1237,7 +1232,7 @@ at86rf230_set_frame_retries(struct ieee802154_hw *hw, s8 retries)static const struct ieee802154_ops at86rf230_ops = { .owner =THIS_MODULE , - .xmit_sync = at86rf230_xmit, + .xmit = at86rf230_xmit, .ed = at86rf230_ed, .set_channel = at86rf230_channel, .start = at86rf230_start,
@@ -1541,7 +1536,6 @@ static int at86rf230_probe(struct spi_device *spi) goto free_dev;spin_lock_init (&lp->lock); -init_completion (&lp->tx_complete);init_completion (&lp->state_complete);spi_set_drvdata (spi, lp);
Signature · 1 line
2.0.3
Alexander Aring
maintainerPATCH 10/12 ieee802154: add valid frame length helper
In reply to Alexander AringThis patch adds a generic valid frame length check function helper. This is useful to check the length field after receiving. For example the at86rf231 doesn't filter invalid frame length. Sometimes the CRC can be also correct. If we get the lqi value with a invalid frame length the kernel can be crash, because we dereference an invalid pointer.
--- include/net/ieee802154.h | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)
include/net/ieee802154.h +8 -2
@@ -28,6 +28,7 @@#define NET_IEEE802154_H #define IEEE802154_MTU 127 +#define IEEE802154_MIN_FRAME_SIZE 5#define IEEE802154_FC_TYPE_BEACON 0x0/* Frame is beacon */ #define IEEE802154_FC_TYPE_DATA 0x1/* Frame is data */
@@ -189,7 +190,12 @@ enum { IEEE802154_SCAN_IN_PROGRESS = 0xfc, }; +static inline bool ieee802154_is_valid_frame_len (const u8 len) +{ +if (unlikely (len >IEEE802154_MTU || len <IEEE802154_MIN_FRAME_SIZE )) +return false; -#endif - +return true; +} +#endif
Signature · 1 line
2.0.3
Alexander Aring
maintainerPATCH 11/12 at86rf230: use ieee802154_is_valid_frame_len
In reply to Alexander AringThis patch use the ieee802154_is_valid_frame_len function to validate the frame length. If the frame length is invalid we use the maximum payload to receive also corrupted frames in monitor mode.
--- drivers/net/ieee802154/at86rf230.c | 26 ++++++++------------------ 1 file changed, 8 insertions(+), 18 deletions(-)
drivers/net/ieee802154/at86rf230.c +8 -18
@@ -782,26 +782,11 @@ at86rf230_tx_trac_status(void *context)static void at86rf230_rx (struct at86rf230_local *lp, -const u8 *data,u8 len) +const u8 *data,const u8 len) { -u8 lqi;struct sk_buff *skb;u8 rx_local_buf[AT86RF2XX_MAX_BUF ]; -if (len <2 ) -return ; - -/* read full frame buffer and invalid lqi value to lowest -* indicator if frame was is in a corrupted state. -*/ -if (len >IEEE802154_MTU ) { - lqi =0 ; - len =IEEE802154_MTU ; -dev_vdbg (&lp->spi->dev,"corrupted frame received\n" ); - }else { - lqi = data[len]; - } -memcpy (rx_local_buf, data, len);enable_irq (lp->spi->irq);
@@ -816,7 +801,7 @@ at86rf230_rx(struct at86rf230_local *lp,/* We do not put CRC into the frame */ skb_trim (skb, len -2 ); -ieee802154_rx_irqsafe (lp->hw, skb, lqi); +ieee802154_rx_irqsafe (lp->hw, skb, rx_local_buf[len]); } static void
@@ -825,7 +810,12 @@ at86rf230_rx_read_frame_complete(void *context)struct at86rf230_state_change *ctx = context;struct at86rf230_local *lp = ctx->lp;const u8 *buf = lp->irq.buf; -const u8 len = buf[1 ]; +u8 len = buf[1 ]; + +if (!ieee802154_is_valid_frame_len (len)) { +dev_vdbg (&lp->spi->dev,"corrupted frame received\n" ); + len =IEEE802154_MTU ; + }at86rf230_rx (lp, buf +2 , len); }
Signature · 1 line
2.0.3
Alexander Aring
maintainerPATCH 12/12 at86rf230: improve receive handling
In reply to Alexander AringCurrent behaviour is copy frame inklusive CRC into skb, then remove the CRC from the skb. This patch provide that we doesn't copy the CRC into the skb. It's a slighty improving of this handling.
--- drivers/net/ieee802154/at86rf230.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-)
drivers/net/ieee802154/at86rf230.c +3 -7
@@ -782,7 +782,7 @@ at86rf230_tx_trac_status(void *context)static void at86rf230_rx (struct at86rf230_local *lp, -const u8 *data,const u8 len) +const u8 *data,const u8 len,const u8 lqi) {struct sk_buff *skb;u8 rx_local_buf[AT86RF2XX_MAX_BUF ];
@@ -797,11 +797,7 @@ at86rf230_rx(struct at86rf230_local *lp, }memcpy (skb_put (skb, len), rx_local_buf, len); - -/* We do not put CRC into the frame */ -skb_trim (skb, len -2 ); - -ieee802154_rx_irqsafe (lp->hw, skb, rx_local_buf[len]); +ieee802154_rx_irqsafe (lp->hw, skb, lqi); } static void
@@ -817,7 +813,7 @@ at86rf230_rx_read_frame_complete(void *context) len =IEEE802154_MTU ; } -at86rf230_rx (lp, buf +2 , len); +at86rf230_rx (lp, buf +2 , len -2 , buf[2 + len]); } static int
Signature · 1 line
2.0.3