tx.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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. #include <linux/netdevice.h>
  20. #include <linux/if_arp.h>
  21. #include <linux/crc-ccitt.h>
  22. #include <asm/unaligned.h>
  23. #include <net/rtnetlink.h>
  24. #include <net/ieee802154_netdev.h>
  25. #include <net/mac802154.h>
  26. #include <net/cfg802154.h>
  27. #include "ieee802154_i.h"
  28. #include "driver-ops.h"
  29. void ieee802154_xmit_worker(struct work_struct *work)
  30. {
  31. struct ieee802154_local *local =
  32. container_of(work, struct ieee802154_local, tx_work);
  33. struct sk_buff *skb = local->tx_skb;
  34. struct net_device *dev = skb->dev;
  35. int res;
  36. rtnl_lock();
  37. /* check if ifdown occurred while schedule */
  38. if (!netif_running(dev))
  39. goto err_tx;
  40. res = drv_xmit_sync(local, skb);
  41. if (res)
  42. goto err_tx;
  43. ieee802154_xmit_complete(&local->hw, skb, false);
  44. dev->stats.tx_packets++;
  45. dev->stats.tx_bytes += skb->len;
  46. rtnl_unlock();
  47. return;
  48. err_tx:
  49. /* Restart the netif queue on each sub_if_data object. */
  50. ieee802154_wake_queue(&local->hw);
  51. rtnl_unlock();
  52. kfree_skb(skb);
  53. netdev_dbg(dev, "transmission failed\n");
  54. }
  55. static netdev_tx_t
  56. ieee802154_tx(struct ieee802154_local *local, struct sk_buff *skb)
  57. {
  58. struct net_device *dev = skb->dev;
  59. int ret;
  60. if (!(local->hw.flags & IEEE802154_HW_TX_OMIT_CKSUM)) {
  61. u16 crc = crc_ccitt(0, skb->data, skb->len);
  62. put_unaligned_le16(crc, skb_put(skb, 2));
  63. }
  64. if (skb_cow_head(skb, local->hw.extra_tx_headroom))
  65. goto err_tx;
  66. /* Stop the netif queue on each sub_if_data object. */
  67. ieee802154_stop_queue(&local->hw);
  68. /* async is priority, otherwise sync is fallback */
  69. if (local->ops->xmit_async) {
  70. ret = drv_xmit_async(local, skb);
  71. if (ret) {
  72. ieee802154_wake_queue(&local->hw);
  73. goto err_tx;
  74. }
  75. dev->stats.tx_packets++;
  76. dev->stats.tx_bytes += skb->len;
  77. } else {
  78. local->tx_skb = skb;
  79. queue_work(local->workqueue, &local->tx_work);
  80. }
  81. return NETDEV_TX_OK;
  82. err_tx:
  83. kfree_skb(skb);
  84. return NETDEV_TX_OK;
  85. }
  86. netdev_tx_t
  87. ieee802154_monitor_start_xmit(struct sk_buff *skb, struct net_device *dev)
  88. {
  89. struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev);
  90. skb->skb_iif = dev->ifindex;
  91. return ieee802154_tx(sdata->local, skb);
  92. }
  93. netdev_tx_t
  94. ieee802154_subif_start_xmit(struct sk_buff *skb, struct net_device *dev)
  95. {
  96. struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev);
  97. int rc;
  98. rc = mac802154_llsec_encrypt(&sdata->sec, skb);
  99. if (rc) {
  100. netdev_warn(dev, "encryption failed: %i\n", rc);
  101. kfree_skb(skb);
  102. return NETDEV_TX_OK;
  103. }
  104. skb->skb_iif = dev->ifindex;
  105. return ieee802154_tx(sdata->local, skb);
  106. }