]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blame - net/mac802154/tx.c
mac802154: tx: change naming convention
[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 *
5b641ebe 13 * Written by:
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>
18 */
19
20#include <linux/netdevice.h>
21#include <linux/if_arp.h>
22#include <linux/crc-ccitt.h>
23
6001d522 24#include <net/rtnetlink.h>
b5992fe9 25#include <net/ieee802154_netdev.h>
5b641ebe 26#include <net/mac802154.h>
5ad60d36 27#include <net/cfg802154.h>
5b641ebe 28
0f1556bc 29#include "ieee802154_i.h"
5b641ebe 30
31/* IEEE 802.15.4 transceivers can sleep during the xmit session, so process
32 * packets through the workqueue.
33 */
e5e584fc 34struct ieee802154_xmit_cb {
5b641ebe 35 struct sk_buff *skb;
36 struct work_struct work;
a5e1ec53 37 struct ieee802154_local *local;
5b641ebe 38};
39
e5e584fc
AA
40static inline struct ieee802154_xmit_cb *
41ieee802154_xmit_cb(const struct sk_buff *skb)
fe24371d 42{
e5e584fc 43 BUILD_BUG_ON(sizeof(skb->cb) < sizeof(struct ieee802154_xmit_cb));
fe24371d 44
e5e584fc 45 return (struct ieee802154_xmit_cb *)skb->cb;
fe24371d
AA
46}
47
e5e584fc 48static void ieee802154_xmit_worker(struct work_struct *work)
5b641ebe 49{
e5e584fc
AA
50 struct ieee802154_xmit_cb *cb =
51 container_of(work, struct ieee802154_xmit_cb, work);
e89e45f2 52 struct ieee802154_local *local = cb->local;
e89e45f2 53 struct sk_buff *skb = cb->skb;
409c3b0c 54 struct net_device *dev = skb->dev;
5b641ebe 55 int res;
56
6001d522
AA
57 rtnl_lock();
58
59 /* check if ifdown occurred while schedule */
409c3b0c 60 if (!netif_running(dev))
6001d522
AA
61 goto err_tx;
62
ed0a5dce 63 res = local->ops->xmit_sync(&local->hw, skb);
6001d522
AA
64 if (res)
65 goto err_tx;
66
67 ieee802154_xmit_complete(&local->hw, skb);
68
409c3b0c
AA
69 dev->stats.tx_packets++;
70 dev->stats.tx_bytes += skb->len;
71
6001d522
AA
72 rtnl_unlock();
73
74 return;
75
76err_tx:
77 /* Restart the netif queue on each sub_if_data object. */
78 ieee802154_wake_queue(&local->hw);
79 rtnl_unlock();
80 kfree_skb(skb);
409c3b0c 81 netdev_dbg(dev, "transmission failed\n");
5b641ebe 82}
83
dc67c6b3 84static netdev_tx_t
e5e584fc 85ieee802154_tx(struct ieee802154_local *local, struct sk_buff *skb)
5b641ebe 86{
e5e584fc 87 struct ieee802154_xmit_cb *cb = ieee802154_xmit_cb(skb);
409c3b0c 88 struct net_device *dev = skb->dev;
ed0a5dce 89 int ret;
5b641ebe 90
60741361 91 mac802154_monitors_rx(local, skb);
72fd5a8b 92
a5e1ec53 93 if (!(local->hw.flags & IEEE802154_HW_OMIT_CKSUM)) {
b7eec52b 94 __le16 crc = cpu_to_le16(crc_ccitt(0, skb->data, skb->len));
4710d806 95
b7eec52b 96 memcpy(skb_put(skb, 2), &crc, 2);
5b641ebe 97 }
98
a5e1ec53 99 if (skb_cow_head(skb, local->hw.extra_tx_headroom))
f5588912 100 goto err_tx;
5b641ebe 101
b5992fe9 102 /* Stop the netif queue on each sub_if_data object. */
18d60a0d 103 ieee802154_stop_queue(&local->hw);
b5992fe9 104
ed0a5dce
AA
105 /* async is priority, otherwise sync is fallback */
106 if (local->ops->xmit_async) {
107 ret = local->ops->xmit_async(&local->hw, skb);
108 if (ret) {
109 ieee802154_wake_queue(&local->hw);
110 goto err_tx;
111 }
409c3b0c
AA
112
113 dev->stats.tx_packets++;
114 dev->stats.tx_bytes += skb->len;
ed0a5dce 115 } else {
e5e584fc 116 INIT_WORK(&cb->work, ieee802154_xmit_worker);
ed0a5dce
AA
117 cb->skb = skb;
118 cb->local = local;
5b641ebe 119
ed0a5dce
AA
120 queue_work(local->workqueue, &cb->work);
121 }
5b641ebe 122
123 return NETDEV_TX_OK;
f5588912
VB
124
125err_tx:
126 kfree_skb(skb);
127 return NETDEV_TX_OK;
5b641ebe 128}
50c6fb99 129
e5e584fc
AA
130netdev_tx_t
131ieee802154_monitor_start_xmit(struct sk_buff *skb, struct net_device *dev)
50c6fb99
AA
132{
133 struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev);
50c6fb99
AA
134
135 skb->skb_iif = dev->ifindex;
50c6fb99 136
e5e584fc 137 return ieee802154_tx(sdata->local, skb);
50c6fb99
AA
138}
139
e5e584fc
AA
140netdev_tx_t
141ieee802154_subif_start_xmit(struct sk_buff *skb, struct net_device *dev)
50c6fb99
AA
142{
143 struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev);
50c6fb99
AA
144 int rc;
145
50c6fb99
AA
146 rc = mac802154_llsec_encrypt(&sdata->sec, skb);
147 if (rc) {
cfa626cb 148 netdev_warn(dev, "encryption failed: %i\n", rc);
50c6fb99
AA
149 kfree_skb(skb);
150 return NETDEV_TX_OK;
151 }
152
153 skb->skb_iif = dev->ifindex;
50c6fb99 154
e5e584fc 155 return ieee802154_tx(sdata->local, skb);
50c6fb99 156}