OSDN Git Service

sunrpc: expiry_time should be seconds not timeval
[sagit-ice-cold/kernel_xiaomi_msm8998.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 #include <asm/unaligned.h>
24
25 #include <net/rtnetlink.h>
26 #include <net/ieee802154_netdev.h>
27 #include <net/mac802154.h>
28 #include <net/cfg802154.h>
29
30 #include "ieee802154_i.h"
31 #include "driver-ops.h"
32
33 void ieee802154_xmit_worker(struct work_struct *work)
34 {
35         struct ieee802154_local *local =
36                 container_of(work, struct ieee802154_local, tx_work);
37         struct sk_buff *skb = local->tx_skb;
38         struct net_device *dev = skb->dev;
39         int res;
40
41         rtnl_lock();
42
43         /* check if ifdown occurred while schedule */
44         if (!netif_running(dev))
45                 goto err_tx;
46
47         res = drv_xmit_sync(local, skb);
48         if (res)
49                 goto err_tx;
50
51         ieee802154_xmit_complete(&local->hw, skb, false);
52
53         dev->stats.tx_packets++;
54         dev->stats.tx_bytes += skb->len;
55
56         rtnl_unlock();
57
58         return;
59
60 err_tx:
61         /* Restart the netif queue on each sub_if_data object. */
62         ieee802154_wake_queue(&local->hw);
63         rtnl_unlock();
64         kfree_skb(skb);
65         netdev_dbg(dev, "transmission failed\n");
66 }
67
68 static netdev_tx_t
69 ieee802154_tx(struct ieee802154_local *local, struct sk_buff *skb)
70 {
71         struct net_device *dev = skb->dev;
72         int ret;
73
74         if (!(local->hw.flags & IEEE802154_HW_TX_OMIT_CKSUM)) {
75                 struct sk_buff *nskb;
76                 u16 crc;
77
78                 if (unlikely(skb_tailroom(skb) < IEEE802154_FCS_LEN)) {
79                         nskb = skb_copy_expand(skb, 0, IEEE802154_FCS_LEN,
80                                                GFP_ATOMIC);
81                         if (likely(nskb)) {
82                                 consume_skb(skb);
83                                 skb = nskb;
84                         } else {
85                                 goto err_tx;
86                         }
87                 }
88
89                 crc = crc_ccitt(0, skb->data, skb->len);
90                 put_unaligned_le16(crc, skb_put(skb, 2));
91         }
92
93         /* Stop the netif queue on each sub_if_data object. */
94         ieee802154_stop_queue(&local->hw);
95
96         /* async is priority, otherwise sync is fallback */
97         if (local->ops->xmit_async) {
98                 ret = drv_xmit_async(local, skb);
99                 if (ret) {
100                         ieee802154_wake_queue(&local->hw);
101                         goto err_tx;
102                 }
103
104                 dev->stats.tx_packets++;
105                 dev->stats.tx_bytes += skb->len;
106         } else {
107                 local->tx_skb = skb;
108                 queue_work(local->workqueue, &local->tx_work);
109         }
110
111         return NETDEV_TX_OK;
112
113 err_tx:
114         kfree_skb(skb);
115         return NETDEV_TX_OK;
116 }
117
118 netdev_tx_t
119 ieee802154_monitor_start_xmit(struct sk_buff *skb, struct net_device *dev)
120 {
121         struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev);
122
123         skb->skb_iif = dev->ifindex;
124
125         return ieee802154_tx(sdata->local, skb);
126 }
127
128 netdev_tx_t
129 ieee802154_subif_start_xmit(struct sk_buff *skb, struct net_device *dev)
130 {
131         struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev);
132         int rc;
133
134         /* TODO we should move it to wpan_dev_hard_header and dev_hard_header
135          * functions. The reason is wireshark will show a mac header which is
136          * with security fields but the payload is not encrypted.
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
147         return ieee802154_tx(sdata->local, skb);
148 }