Thomas Gleixner | 1802d0b | 2019-05-27 08:55:21 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-only |
alex.bluesman.smirnov@gmail.com | 5b641eb | 2012-05-15 20:50:22 +0000 | [diff] [blame] | 2 | /* |
| 3 | * Copyright 2007-2012 Siemens AG |
| 4 | * |
alex.bluesman.smirnov@gmail.com | 5b641eb | 2012-05-15 20:50:22 +0000 | [diff] [blame] | 5 | * Written by: |
| 6 | * Dmitry Eremin-Solenikov <dbaryshkov@gmail.com> |
| 7 | * Sergey Lapin <slapin@ossfans.org> |
| 8 | * Maxim Gorbachyov <maxim.gorbachev@siemens.com> |
| 9 | * Alexander Smirnov <alex.bluesman.smirnov@gmail.com> |
| 10 | */ |
| 11 | |
| 12 | #include <linux/netdevice.h> |
| 13 | #include <linux/if_arp.h> |
| 14 | #include <linux/crc-ccitt.h> |
Alexander Aring | 061ef8f | 2014-10-27 17:13:28 +0100 | [diff] [blame] | 15 | #include <asm/unaligned.h> |
alex.bluesman.smirnov@gmail.com | 5b641eb | 2012-05-15 20:50:22 +0000 | [diff] [blame] | 16 | |
Alexander Aring | 6001d52 | 2014-10-26 09:37:09 +0100 | [diff] [blame] | 17 | #include <net/rtnetlink.h> |
Alan Ott | b5992fe | 2013-04-03 04:00:56 +0000 | [diff] [blame] | 18 | #include <net/ieee802154_netdev.h> |
alex.bluesman.smirnov@gmail.com | 5b641eb | 2012-05-15 20:50:22 +0000 | [diff] [blame] | 19 | #include <net/mac802154.h> |
Alexander Aring | 5ad60d3 | 2014-10-25 09:41:02 +0200 | [diff] [blame] | 20 | #include <net/cfg802154.h> |
alex.bluesman.smirnov@gmail.com | 5b641eb | 2012-05-15 20:50:22 +0000 | [diff] [blame] | 21 | |
Alexander Aring | 0f1556b | 2014-10-25 09:41:00 +0200 | [diff] [blame] | 22 | #include "ieee802154_i.h" |
Alexander Aring | 59cb300 | 2014-10-28 18:21:21 +0100 | [diff] [blame] | 23 | #include "driver-ops.h" |
alex.bluesman.smirnov@gmail.com | 5b641eb | 2012-05-15 20:50:22 +0000 | [diff] [blame] | 24 | |
Lennert Buytenhek | c22ff7b | 2015-07-21 17:44:47 +0300 | [diff] [blame] | 25 | void ieee802154_xmit_worker(struct work_struct *work) |
alex.bluesman.smirnov@gmail.com | 5b641eb | 2012-05-15 20:50:22 +0000 | [diff] [blame] | 26 | { |
Lennert Buytenhek | c22ff7b | 2015-07-21 17:44:47 +0300 | [diff] [blame] | 27 | struct ieee802154_local *local = |
| 28 | container_of(work, struct ieee802154_local, tx_work); |
| 29 | struct sk_buff *skb = local->tx_skb; |
Alexander Aring | 409c3b0 | 2014-10-26 09:37:12 +0100 | [diff] [blame] | 30 | struct net_device *dev = skb->dev; |
alex.bluesman.smirnov@gmail.com | 5b641eb | 2012-05-15 20:50:22 +0000 | [diff] [blame] | 31 | int res; |
| 32 | |
Alexander Aring | 59cb300 | 2014-10-28 18:21:21 +0100 | [diff] [blame] | 33 | res = drv_xmit_sync(local, skb); |
Alexander Aring | 6001d52 | 2014-10-26 09:37:09 +0100 | [diff] [blame] | 34 | if (res) |
| 35 | goto err_tx; |
| 36 | |
Alexander Aring | 61f2dcb | 2014-11-12 19:51:56 +0100 | [diff] [blame] | 37 | ieee802154_xmit_complete(&local->hw, skb, false); |
Alexander Aring | 6001d52 | 2014-10-26 09:37:09 +0100 | [diff] [blame] | 38 | |
Alexander Aring | 409c3b0 | 2014-10-26 09:37:12 +0100 | [diff] [blame] | 39 | dev->stats.tx_packets++; |
| 40 | dev->stats.tx_bytes += skb->len; |
| 41 | |
Alexander Aring | 6001d52 | 2014-10-26 09:37:09 +0100 | [diff] [blame] | 42 | return; |
| 43 | |
| 44 | err_tx: |
| 45 | /* Restart the netif queue on each sub_if_data object. */ |
| 46 | ieee802154_wake_queue(&local->hw); |
Alexander Aring | 6001d52 | 2014-10-26 09:37:09 +0100 | [diff] [blame] | 47 | kfree_skb(skb); |
Alexander Aring | 409c3b0 | 2014-10-26 09:37:12 +0100 | [diff] [blame] | 48 | netdev_dbg(dev, "transmission failed\n"); |
alex.bluesman.smirnov@gmail.com | 5b641eb | 2012-05-15 20:50:22 +0000 | [diff] [blame] | 49 | } |
| 50 | |
Alexander Aring | dc67c6b | 2014-10-26 09:37:04 +0100 | [diff] [blame] | 51 | static netdev_tx_t |
Alexander Aring | e5e584f | 2014-10-26 09:37:13 +0100 | [diff] [blame] | 52 | ieee802154_tx(struct ieee802154_local *local, struct sk_buff *skb) |
alex.bluesman.smirnov@gmail.com | 5b641eb | 2012-05-15 20:50:22 +0000 | [diff] [blame] | 53 | { |
Alexander Aring | 409c3b0 | 2014-10-26 09:37:12 +0100 | [diff] [blame] | 54 | struct net_device *dev = skb->dev; |
Alexander Aring | ed0a5dc | 2014-10-26 09:37:08 +0100 | [diff] [blame] | 55 | int ret; |
alex.bluesman.smirnov@gmail.com | 5b641eb | 2012-05-15 20:50:22 +0000 | [diff] [blame] | 56 | |
Alexander Aring | 90386a7 | 2014-10-29 21:34:34 +0100 | [diff] [blame] | 57 | if (!(local->hw.flags & IEEE802154_HW_TX_OMIT_CKSUM)) { |
Alexander Aring | f9c5283 | 2018-07-02 16:32:03 -0400 | [diff] [blame] | 58 | struct sk_buff *nskb; |
| 59 | u16 crc; |
Varka Bhadram | 4710d80 | 2014-07-02 09:01:09 +0530 | [diff] [blame] | 60 | |
Alexander Aring | f9c5283 | 2018-07-02 16:32:03 -0400 | [diff] [blame] | 61 | if (unlikely(skb_tailroom(skb) < IEEE802154_FCS_LEN)) { |
| 62 | nskb = skb_copy_expand(skb, 0, IEEE802154_FCS_LEN, |
| 63 | GFP_ATOMIC); |
| 64 | if (likely(nskb)) { |
| 65 | consume_skb(skb); |
| 66 | skb = nskb; |
| 67 | } else { |
| 68 | goto err_tx; |
| 69 | } |
| 70 | } |
| 71 | |
| 72 | crc = crc_ccitt(0, skb->data, skb->len); |
Alexander Aring | 061ef8f | 2014-10-27 17:13:28 +0100 | [diff] [blame] | 73 | put_unaligned_le16(crc, skb_put(skb, 2)); |
alex.bluesman.smirnov@gmail.com | 5b641eb | 2012-05-15 20:50:22 +0000 | [diff] [blame] | 74 | } |
| 75 | |
Alan Ott | b5992fe | 2013-04-03 04:00:56 +0000 | [diff] [blame] | 76 | /* Stop the netif queue on each sub_if_data object. */ |
Alexander Aring | 18d60a0 | 2014-10-26 09:37:06 +0100 | [diff] [blame] | 77 | ieee802154_stop_queue(&local->hw); |
Alan Ott | b5992fe | 2013-04-03 04:00:56 +0000 | [diff] [blame] | 78 | |
Alexander Aring | ed0a5dc | 2014-10-26 09:37:08 +0100 | [diff] [blame] | 79 | /* async is priority, otherwise sync is fallback */ |
| 80 | if (local->ops->xmit_async) { |
Alexander Aring | 59cb300 | 2014-10-28 18:21:21 +0100 | [diff] [blame] | 81 | ret = drv_xmit_async(local, skb); |
Alexander Aring | ed0a5dc | 2014-10-26 09:37:08 +0100 | [diff] [blame] | 82 | if (ret) { |
| 83 | ieee802154_wake_queue(&local->hw); |
| 84 | goto err_tx; |
| 85 | } |
Alexander Aring | 409c3b0 | 2014-10-26 09:37:12 +0100 | [diff] [blame] | 86 | |
| 87 | dev->stats.tx_packets++; |
| 88 | dev->stats.tx_bytes += skb->len; |
Alexander Aring | ed0a5dc | 2014-10-26 09:37:08 +0100 | [diff] [blame] | 89 | } else { |
Lennert Buytenhek | c22ff7b | 2015-07-21 17:44:47 +0300 | [diff] [blame] | 90 | local->tx_skb = skb; |
| 91 | queue_work(local->workqueue, &local->tx_work); |
Alexander Aring | ed0a5dc | 2014-10-26 09:37:08 +0100 | [diff] [blame] | 92 | } |
alex.bluesman.smirnov@gmail.com | 5b641eb | 2012-05-15 20:50:22 +0000 | [diff] [blame] | 93 | |
| 94 | return NETDEV_TX_OK; |
Varka Bhadram | f558891 | 2014-08-11 13:25:10 +0200 | [diff] [blame] | 95 | |
| 96 | err_tx: |
| 97 | kfree_skb(skb); |
| 98 | return NETDEV_TX_OK; |
alex.bluesman.smirnov@gmail.com | 5b641eb | 2012-05-15 20:50:22 +0000 | [diff] [blame] | 99 | } |
Alexander Aring | 50c6fb9 | 2014-10-26 09:37:01 +0100 | [diff] [blame] | 100 | |
Alexander Aring | e5e584f | 2014-10-26 09:37:13 +0100 | [diff] [blame] | 101 | netdev_tx_t |
| 102 | ieee802154_monitor_start_xmit(struct sk_buff *skb, struct net_device *dev) |
Alexander Aring | 50c6fb9 | 2014-10-26 09:37:01 +0100 | [diff] [blame] | 103 | { |
| 104 | struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev); |
Alexander Aring | 50c6fb9 | 2014-10-26 09:37:01 +0100 | [diff] [blame] | 105 | |
| 106 | skb->skb_iif = dev->ifindex; |
Alexander Aring | 50c6fb9 | 2014-10-26 09:37:01 +0100 | [diff] [blame] | 107 | |
Alexander Aring | e5e584f | 2014-10-26 09:37:13 +0100 | [diff] [blame] | 108 | return ieee802154_tx(sdata->local, skb); |
Alexander Aring | 50c6fb9 | 2014-10-26 09:37:01 +0100 | [diff] [blame] | 109 | } |
| 110 | |
Alexander Aring | e5e584f | 2014-10-26 09:37:13 +0100 | [diff] [blame] | 111 | netdev_tx_t |
| 112 | ieee802154_subif_start_xmit(struct sk_buff *skb, struct net_device *dev) |
Alexander Aring | 50c6fb9 | 2014-10-26 09:37:01 +0100 | [diff] [blame] | 113 | { |
| 114 | struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev); |
Alexander Aring | 50c6fb9 | 2014-10-26 09:37:01 +0100 | [diff] [blame] | 115 | int rc; |
| 116 | |
Alexander Aring | d58a2fa | 2015-09-28 09:00:26 +0200 | [diff] [blame] | 117 | /* TODO we should move it to wpan_dev_hard_header and dev_hard_header |
| 118 | * functions. The reason is wireshark will show a mac header which is |
| 119 | * with security fields but the payload is not encrypted. |
| 120 | */ |
Alexander Aring | 50c6fb9 | 2014-10-26 09:37:01 +0100 | [diff] [blame] | 121 | rc = mac802154_llsec_encrypt(&sdata->sec, skb); |
| 122 | if (rc) { |
Alexander Aring | cfa626c | 2014-10-26 09:37:10 +0100 | [diff] [blame] | 123 | netdev_warn(dev, "encryption failed: %i\n", rc); |
Alexander Aring | 50c6fb9 | 2014-10-26 09:37:01 +0100 | [diff] [blame] | 124 | kfree_skb(skb); |
| 125 | return NETDEV_TX_OK; |
| 126 | } |
| 127 | |
| 128 | skb->skb_iif = dev->ifindex; |
Alexander Aring | 50c6fb9 | 2014-10-26 09:37:01 +0100 | [diff] [blame] | 129 | |
Alexander Aring | e5e584f | 2014-10-26 09:37:13 +0100 | [diff] [blame] | 130 | return ieee802154_tx(sdata->local, skb); |
Alexander Aring | 50c6fb9 | 2014-10-26 09:37:01 +0100 | [diff] [blame] | 131 | } |