]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blame - net/mac802154/tx.c
mac802154: Do not try to resend failed packets
[mirror_ubuntu-artful-kernel.git] / net / mac802154 / tx.c
CommitLineData
5b641ebe 1/*
2 * Copyright 2007-2012 Siemens AG
3 *
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.
7 *
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.
12 *
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
16 *
17 * Written by:
18 * Dmitry Eremin-Solenikov <dbaryshkov@gmail.com>
19 * Sergey Lapin <slapin@ossfans.org>
20 * Maxim Gorbachyov <maxim.gorbachev@siemens.com>
21 * Alexander Smirnov <alex.bluesman.smirnov@gmail.com>
22 */
23
24#include <linux/netdevice.h>
25#include <linux/if_arp.h>
26#include <linux/crc-ccitt.h>
27
28#include <net/mac802154.h>
29#include <net/wpan-phy.h>
30
31#include "mac802154.h"
32
33/* IEEE 802.15.4 transceivers can sleep during the xmit session, so process
34 * packets through the workqueue.
35 */
36struct xmit_work {
37 struct sk_buff *skb;
38 struct work_struct work;
39 struct mac802154_priv *priv;
40 u8 chan;
41 u8 page;
5b641ebe 42};
43
44static void mac802154_xmit_worker(struct work_struct *work)
45{
46 struct xmit_work *xw = container_of(work, struct xmit_work, work);
47 int res;
48
49 mutex_lock(&xw->priv->phy->pib_lock);
50 if (xw->priv->phy->current_channel != xw->chan ||
51 xw->priv->phy->current_page != xw->page) {
52 res = xw->priv->ops->set_channel(&xw->priv->hw,
53 xw->page,
54 xw->chan);
55 if (res) {
56 pr_debug("set_channel failed\n");
57 goto out;
58 }
59 }
60
61 res = xw->priv->ops->xmit(&xw->priv->hw, xw->skb);
7dd43d35
AO
62 if (res)
63 pr_debug("transmission failed\n");
5b641ebe 64
65out:
66 mutex_unlock(&xw->priv->phy->pib_lock);
67
5b641ebe 68
69 dev_kfree_skb(xw->skb);
70
71 kfree(xw);
72}
73
74netdev_tx_t mac802154_tx(struct mac802154_priv *priv, struct sk_buff *skb,
75 u8 page, u8 chan)
76{
77 struct xmit_work *work;
78
8a8e28b8 79 if (!(priv->phy->channels_supported[page] & (1 << chan))) {
5b641ebe 80 WARN_ON(1);
fcefbe9f 81 kfree_skb(skb);
5b641ebe 82 return NETDEV_TX_OK;
8a8e28b8 83 }
5b641ebe 84
72fd5a8b 85 mac802154_monitors_rx(mac802154_to_priv(&priv->hw), skb);
86
5b641ebe 87 if (!(priv->hw.flags & IEEE802154_HW_OMIT_CKSUM)) {
88 u16 crc = crc_ccitt(0, skb->data, skb->len);
89 u8 *data = skb_put(skb, 2);
90 data[0] = crc & 0xff;
91 data[1] = crc >> 8;
92 }
93
94 if (skb_cow_head(skb, priv->hw.extra_tx_headroom)) {
92a2ec72 95 kfree_skb(skb);
5b641ebe 96 return NETDEV_TX_OK;
97 }
98
99 work = kzalloc(sizeof(struct xmit_work), GFP_ATOMIC);
fcefbe9f
AO
100 if (!work) {
101 kfree_skb(skb);
5b641ebe 102 return NETDEV_TX_BUSY;
fcefbe9f 103 }
5b641ebe 104
105 INIT_WORK(&work->work, mac802154_xmit_worker);
106 work->skb = skb;
107 work->priv = priv;
108 work->page = page;
109 work->chan = chan;
5b641ebe 110
111 queue_work(priv->dev_workqueue, &work->work);
112
113 return NETDEV_TX_OK;
114}