2 * Copyright 2007-2012 Siemens AG
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.
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.
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 * Dmitry Eremin-Solenikov <dbaryshkov@gmail.com>
19 * Sergey Lapin <slapin@ossfans.org>
20 * Maxim Gorbachyov <maxim.gorbachev@siemens.com>
21 * Alexander Smirnov <alex.bluesman.smirnov@gmail.com>
24 #include <linux/netdevice.h>
25 #include <linux/if_arp.h>
26 #include <linux/crc-ccitt.h>
28 #include <net/mac802154.h>
29 #include <net/wpan-phy.h>
31 #include "mac802154.h"
33 /* IEEE 802.15.4 transceivers can sleep during the xmit session, so process
34 * packets through the workqueue.
38 struct work_struct work
;
39 struct mac802154_priv
*priv
;
45 static void mac802154_xmit_worker(struct work_struct
*work
)
47 struct xmit_work
*xw
= container_of(work
, struct xmit_work
, work
);
50 mutex_lock(&xw
->priv
->phy
->pib_lock
);
51 if (xw
->priv
->phy
->current_channel
!= xw
->chan
||
52 xw
->priv
->phy
->current_page
!= xw
->page
) {
53 res
= xw
->priv
->ops
->set_channel(&xw
->priv
->hw
,
57 pr_debug("set_channel failed\n");
62 res
= xw
->priv
->ops
->xmit(&xw
->priv
->hw
, xw
->skb
);
65 mutex_unlock(&xw
->priv
->phy
->pib_lock
);
68 if (xw
->xmit_attempts
++ < MAC802154_MAX_XMIT_ATTEMPTS
) {
69 queue_work(xw
->priv
->dev_workqueue
, &xw
->work
);
72 pr_debug("transmission failed for %d times",
73 MAC802154_MAX_XMIT_ATTEMPTS
);
76 dev_kfree_skb(xw
->skb
);
81 netdev_tx_t
mac802154_tx(struct mac802154_priv
*priv
, struct sk_buff
*skb
,
84 struct xmit_work
*work
;
86 if (!(priv
->phy
->channels_supported
[page
] & (1 << chan
))) {
91 mac802154_monitors_rx(mac802154_to_priv(&priv
->hw
), skb
);
93 if (!(priv
->hw
.flags
& IEEE802154_HW_OMIT_CKSUM
)) {
94 u16 crc
= crc_ccitt(0, skb
->data
, skb
->len
);
95 u8
*data
= skb_put(skb
, 2);
100 if (skb_cow_head(skb
, priv
->hw
.extra_tx_headroom
)) {
105 work
= kzalloc(sizeof(struct xmit_work
), GFP_ATOMIC
);
107 return NETDEV_TX_BUSY
;
109 INIT_WORK(&work
->work
, mac802154_xmit_worker
);
114 work
->xmit_attempts
= 0;
116 queue_work(priv
->dev_workqueue
, &work
->work
);