blob: 7ed439172f30809d59fb5673131957ca8c25c56c [file] [log] [blame]
alex.bluesman.smirnov@gmail.com5b641eb2012-05-15 20:50:22 +00001/*
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 *
alex.bluesman.smirnov@gmail.com5b641eb2012-05-15 20:50:22 +000013 * 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>
Alexander Aring061ef8f2014-10-27 17:13:28 +010023#include <asm/unaligned.h>
alex.bluesman.smirnov@gmail.com5b641eb2012-05-15 20:50:22 +000024
Alexander Aring6001d522014-10-26 09:37:09 +010025#include <net/rtnetlink.h>
Alan Ottb5992fe2013-04-03 04:00:56 +000026#include <net/ieee802154_netdev.h>
alex.bluesman.smirnov@gmail.com5b641eb2012-05-15 20:50:22 +000027#include <net/mac802154.h>
Alexander Aring5ad60d32014-10-25 09:41:02 +020028#include <net/cfg802154.h>
alex.bluesman.smirnov@gmail.com5b641eb2012-05-15 20:50:22 +000029
Alexander Aring0f1556b2014-10-25 09:41:00 +020030#include "ieee802154_i.h"
Alexander Aring59cb3002014-10-28 18:21:21 +010031#include "driver-ops.h"
alex.bluesman.smirnov@gmail.com5b641eb2012-05-15 20:50:22 +000032
Lennert Buytenhekc22ff7b2015-07-21 17:44:47 +030033void ieee802154_xmit_worker(struct work_struct *work)
alex.bluesman.smirnov@gmail.com5b641eb2012-05-15 20:50:22 +000034{
Lennert Buytenhekc22ff7b2015-07-21 17:44:47 +030035 struct ieee802154_local *local =
36 container_of(work, struct ieee802154_local, tx_work);
37 struct sk_buff *skb = local->tx_skb;
Alexander Aring409c3b02014-10-26 09:37:12 +010038 struct net_device *dev = skb->dev;
alex.bluesman.smirnov@gmail.com5b641eb2012-05-15 20:50:22 +000039 int res;
40
Alexander Aring6001d522014-10-26 09:37:09 +010041 rtnl_lock();
42
43 /* check if ifdown occurred while schedule */
Alexander Aring409c3b02014-10-26 09:37:12 +010044 if (!netif_running(dev))
Alexander Aring6001d522014-10-26 09:37:09 +010045 goto err_tx;
46
Alexander Aring59cb3002014-10-28 18:21:21 +010047 res = drv_xmit_sync(local, skb);
Alexander Aring6001d522014-10-26 09:37:09 +010048 if (res)
49 goto err_tx;
50
Alexander Aring61f2dcb2014-11-12 19:51:56 +010051 ieee802154_xmit_complete(&local->hw, skb, false);
Alexander Aring6001d522014-10-26 09:37:09 +010052
Alexander Aring409c3b02014-10-26 09:37:12 +010053 dev->stats.tx_packets++;
54 dev->stats.tx_bytes += skb->len;
55
Alexander Aring6001d522014-10-26 09:37:09 +010056 rtnl_unlock();
57
58 return;
59
60err_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);
Alexander Aring409c3b02014-10-26 09:37:12 +010065 netdev_dbg(dev, "transmission failed\n");
alex.bluesman.smirnov@gmail.com5b641eb2012-05-15 20:50:22 +000066}
67
Alexander Aringdc67c6b2014-10-26 09:37:04 +010068static netdev_tx_t
Alexander Aringe5e584f2014-10-26 09:37:13 +010069ieee802154_tx(struct ieee802154_local *local, struct sk_buff *skb)
alex.bluesman.smirnov@gmail.com5b641eb2012-05-15 20:50:22 +000070{
Alexander Aring409c3b02014-10-26 09:37:12 +010071 struct net_device *dev = skb->dev;
Alexander Aringed0a5dc2014-10-26 09:37:08 +010072 int ret;
alex.bluesman.smirnov@gmail.com5b641eb2012-05-15 20:50:22 +000073
Alexander Aring90386a72014-10-29 21:34:34 +010074 if (!(local->hw.flags & IEEE802154_HW_TX_OMIT_CKSUM)) {
Alexander Aring061ef8f2014-10-27 17:13:28 +010075 u16 crc = crc_ccitt(0, skb->data, skb->len);
Varka Bhadram4710d802014-07-02 09:01:09 +053076
Alexander Aring061ef8f2014-10-27 17:13:28 +010077 put_unaligned_le16(crc, skb_put(skb, 2));
alex.bluesman.smirnov@gmail.com5b641eb2012-05-15 20:50:22 +000078 }
79
Alexander Aringa5e1ec52014-10-25 17:16:35 +020080 if (skb_cow_head(skb, local->hw.extra_tx_headroom))
Varka Bhadramf5588912014-08-11 13:25:10 +020081 goto err_tx;
alex.bluesman.smirnov@gmail.com5b641eb2012-05-15 20:50:22 +000082
Alan Ottb5992fe2013-04-03 04:00:56 +000083 /* Stop the netif queue on each sub_if_data object. */
Alexander Aring18d60a02014-10-26 09:37:06 +010084 ieee802154_stop_queue(&local->hw);
Alan Ottb5992fe2013-04-03 04:00:56 +000085
Alexander Aringed0a5dc2014-10-26 09:37:08 +010086 /* async is priority, otherwise sync is fallback */
87 if (local->ops->xmit_async) {
Alexander Aring59cb3002014-10-28 18:21:21 +010088 ret = drv_xmit_async(local, skb);
Alexander Aringed0a5dc2014-10-26 09:37:08 +010089 if (ret) {
90 ieee802154_wake_queue(&local->hw);
91 goto err_tx;
92 }
Alexander Aring409c3b02014-10-26 09:37:12 +010093
94 dev->stats.tx_packets++;
95 dev->stats.tx_bytes += skb->len;
Alexander Aringed0a5dc2014-10-26 09:37:08 +010096 } else {
Lennert Buytenhekc22ff7b2015-07-21 17:44:47 +030097 local->tx_skb = skb;
98 queue_work(local->workqueue, &local->tx_work);
Alexander Aringed0a5dc2014-10-26 09:37:08 +010099 }
alex.bluesman.smirnov@gmail.com5b641eb2012-05-15 20:50:22 +0000100
101 return NETDEV_TX_OK;
Varka Bhadramf5588912014-08-11 13:25:10 +0200102
103err_tx:
104 kfree_skb(skb);
105 return NETDEV_TX_OK;
alex.bluesman.smirnov@gmail.com5b641eb2012-05-15 20:50:22 +0000106}
Alexander Aring50c6fb92014-10-26 09:37:01 +0100107
Alexander Aringe5e584f2014-10-26 09:37:13 +0100108netdev_tx_t
109ieee802154_monitor_start_xmit(struct sk_buff *skb, struct net_device *dev)
Alexander Aring50c6fb92014-10-26 09:37:01 +0100110{
111 struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev);
Alexander Aring50c6fb92014-10-26 09:37:01 +0100112
113 skb->skb_iif = dev->ifindex;
Alexander Aring50c6fb92014-10-26 09:37:01 +0100114
Alexander Aringe5e584f2014-10-26 09:37:13 +0100115 return ieee802154_tx(sdata->local, skb);
Alexander Aring50c6fb92014-10-26 09:37:01 +0100116}
117
Alexander Aringe5e584f2014-10-26 09:37:13 +0100118netdev_tx_t
119ieee802154_subif_start_xmit(struct sk_buff *skb, struct net_device *dev)
Alexander Aring50c6fb92014-10-26 09:37:01 +0100120{
121 struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev);
Alexander Aring50c6fb92014-10-26 09:37:01 +0100122 int rc;
123
Alexander Aring50c6fb92014-10-26 09:37:01 +0100124 rc = mac802154_llsec_encrypt(&sdata->sec, skb);
125 if (rc) {
Alexander Aringcfa626c2014-10-26 09:37:10 +0100126 netdev_warn(dev, "encryption failed: %i\n", rc);
Alexander Aring50c6fb92014-10-26 09:37:01 +0100127 kfree_skb(skb);
128 return NETDEV_TX_OK;
129 }
130
131 skb->skb_iif = dev->ifindex;
Alexander Aring50c6fb92014-10-26 09:37:01 +0100132
Alexander Aringe5e584f2014-10-26 09:37:13 +0100133 return ieee802154_tx(sdata->local, skb);
Alexander Aring50c6fb92014-10-26 09:37:01 +0100134}