]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blob - net/mac802154/tx.c
mac802154: tx: use netdev print helpers
[mirror_ubuntu-artful-kernel.git] / net / mac802154 / tx.c
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 * 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
24 #include <net/rtnetlink.h>
25 #include <net/ieee802154_netdev.h>
26 #include <net/mac802154.h>
27 #include <net/cfg802154.h>
28
29 #include "ieee802154_i.h"
30
31 /* IEEE 802.15.4 transceivers can sleep during the xmit session, so process
32 * packets through the workqueue.
33 */
34 struct wpan_xmit_cb {
35 struct sk_buff *skb;
36 struct work_struct work;
37 struct ieee802154_local *local;
38 };
39
40 static inline struct wpan_xmit_cb *wpan_xmit_cb(const struct sk_buff *skb)
41 {
42 BUILD_BUG_ON(sizeof(skb->cb) < sizeof(struct wpan_xmit_cb));
43
44 return (struct wpan_xmit_cb *)skb->cb;
45 }
46
47 static void mac802154_xmit_worker(struct work_struct *work)
48 {
49 struct wpan_xmit_cb *cb = container_of(work, struct wpan_xmit_cb, work);
50 struct ieee802154_local *local = cb->local;
51 struct sk_buff *skb = cb->skb;
52 int res;
53
54 rtnl_lock();
55
56 /* check if ifdown occurred while schedule */
57 if (!netif_running(skb->dev))
58 goto err_tx;
59
60 res = local->ops->xmit_sync(&local->hw, skb);
61 if (res)
62 goto err_tx;
63
64 ieee802154_xmit_complete(&local->hw, skb);
65
66 rtnl_unlock();
67
68 return;
69
70 err_tx:
71 /* Restart the netif queue on each sub_if_data object. */
72 ieee802154_wake_queue(&local->hw);
73 rtnl_unlock();
74 kfree_skb(skb);
75 netdev_dbg(skb->dev, "transmission failed\n");
76 }
77
78 static netdev_tx_t
79 mac802154_tx(struct ieee802154_local *local, struct sk_buff *skb)
80 {
81 struct wpan_xmit_cb *cb = wpan_xmit_cb(skb);
82 int ret;
83
84 mac802154_monitors_rx(local, skb);
85
86 if (!(local->hw.flags & IEEE802154_HW_OMIT_CKSUM)) {
87 u16 crc = crc_ccitt(0, skb->data, skb->len);
88 u8 *data = skb_put(skb, 2);
89
90 data[0] = crc & 0xff;
91 data[1] = crc >> 8;
92 }
93
94 if (skb_cow_head(skb, local->hw.extra_tx_headroom))
95 goto err_tx;
96
97 /* Stop the netif queue on each sub_if_data object. */
98 ieee802154_stop_queue(&local->hw);
99
100 /* async is priority, otherwise sync is fallback */
101 if (local->ops->xmit_async) {
102 ret = local->ops->xmit_async(&local->hw, skb);
103 if (ret) {
104 ieee802154_wake_queue(&local->hw);
105 goto err_tx;
106 }
107 } else {
108 INIT_WORK(&cb->work, mac802154_xmit_worker);
109 cb->skb = skb;
110 cb->local = local;
111
112 queue_work(local->workqueue, &cb->work);
113 }
114
115 return NETDEV_TX_OK;
116
117 err_tx:
118 kfree_skb(skb);
119 return NETDEV_TX_OK;
120 }
121
122 netdev_tx_t mac802154_monitor_xmit(struct sk_buff *skb, struct net_device *dev)
123 {
124 struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev);
125
126 skb->skb_iif = dev->ifindex;
127 dev->stats.tx_packets++;
128 dev->stats.tx_bytes += skb->len;
129
130 return mac802154_tx(sdata->local, skb);
131 }
132
133 netdev_tx_t mac802154_wpan_xmit(struct sk_buff *skb, struct net_device *dev)
134 {
135 struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev);
136 int rc;
137
138 rc = mac802154_llsec_encrypt(&sdata->sec, skb);
139 if (rc) {
140 netdev_warn(dev, "encryption failed: %i\n", rc);
141 kfree_skb(skb);
142 return NETDEV_TX_OK;
143 }
144
145 skb->skb_iif = dev->ifindex;
146 dev->stats.tx_packets++;
147 dev->stats.tx_bytes += skb->len;
148
149 return mac802154_tx(sdata->local, skb);
150 }