2 * Copyright 2007-2012 Siemens AG
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2
6 * as published by the Free Software Foundation.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
14 * Dmitry Eremin-Solenikov <dbaryshkov@gmail.com>
15 * Sergey Lapin <slapin@ossfans.org>
16 * Maxim Gorbachyov <maxim.gorbachev@siemens.com>
17 * Alexander Smirnov <alex.bluesman.smirnov@gmail.com>
20 #include <linux/netdevice.h>
21 #include <linux/if_arp.h>
22 #include <linux/crc-ccitt.h>
24 #include <net/ieee802154_netdev.h>
25 #include <net/mac802154.h>
26 #include <net/cfg802154.h>
28 #include "ieee802154_i.h"
30 /* IEEE 802.15.4 transceivers can sleep during the xmit session, so process
31 * packets through the workqueue.
35 struct work_struct work;
36 struct mac802154_priv *priv;
41 static void mac802154_xmit_worker(struct work_struct *work)
43 struct xmit_work *xw = container_of(work, struct xmit_work, work);
44 struct mac802154_sub_if_data *sdata;
47 mutex_lock(&xw->priv->phy->pib_lock);
48 if (xw->priv->phy->current_channel != xw->chan ||
49 xw->priv->phy->current_page != xw->page) {
50 res = xw->priv->ops->set_channel(&xw->priv->hw,
54 pr_debug("set_channel failed\n");
58 xw->priv->phy->current_channel = xw->chan;
59 xw->priv->phy->current_page = xw->page;
62 res = xw->priv->ops->xmit(&xw->priv->hw, xw->skb);
64 pr_debug("transmission failed\n");
67 mutex_unlock(&xw->priv->phy->pib_lock);
69 /* Restart the netif queue on each sub_if_data object. */
71 list_for_each_entry_rcu(sdata, &xw->priv->slaves, list)
72 netif_wake_queue(sdata->dev);
75 dev_kfree_skb(xw->skb);
80 netdev_tx_t mac802154_tx(struct mac802154_priv *priv, struct sk_buff *skb,
83 struct xmit_work *work;
84 struct mac802154_sub_if_data *sdata;
86 if (!(priv->phy->channels_supported[page] & (1 << chan))) {
91 mac802154_monitors_rx(mac802154_to_priv(&priv->hw), skb);
93 if (!(priv->hw.flags & IEEE802154_HW_OMIT_CKSUM)) {
94 u16 crc = crc_ccitt(0, skb->data, skb->len);
95 u8 *data = skb_put(skb, 2);
101 if (skb_cow_head(skb, priv->hw.extra_tx_headroom))
104 work = kzalloc(sizeof(*work), GFP_ATOMIC);
107 return NETDEV_TX_BUSY;
110 /* Stop the netif queue on each sub_if_data object. */
112 list_for_each_entry_rcu(sdata, &priv->slaves, list)
113 netif_stop_queue(sdata->dev);
116 INIT_WORK(&work->work, mac802154_xmit_worker);
122 queue_work(priv->dev_workqueue, &work->work);