mac802154: rename sdata slaves and slaves_mtx
[deliverable/linux.git] / net / mac802154 / tx.c
CommitLineData
5b641ebe 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 *
5b641ebe 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
b5992fe9 24#include <net/ieee802154_netdev.h>
5b641ebe 25#include <net/mac802154.h>
5ad60d36 26#include <net/cfg802154.h>
5b641ebe 27
0f1556bc 28#include "ieee802154_i.h"
5b641ebe 29
30/* IEEE 802.15.4 transceivers can sleep during the xmit session, so process
31 * packets through the workqueue.
32 */
33struct xmit_work {
34 struct sk_buff *skb;
35 struct work_struct work;
a5e1ec53 36 struct ieee802154_local *local;
5b641ebe 37 u8 chan;
38 u8 page;
5b641ebe 39};
40
41static void mac802154_xmit_worker(struct work_struct *work)
42{
43 struct xmit_work *xw = container_of(work, struct xmit_work, work);
036562f9 44 struct ieee802154_sub_if_data *sdata;
5b641ebe 45 int res;
46
a5e1ec53
AA
47 mutex_lock(&xw->local->phy->pib_lock);
48 if (xw->local->phy->current_channel != xw->chan ||
49 xw->local->phy->current_page != xw->page) {
50 res = xw->local->ops->set_channel(&xw->local->hw,
5b641ebe 51 xw->page,
52 xw->chan);
53 if (res) {
54 pr_debug("set_channel failed\n");
55 goto out;
56 }
9f7f78b4 57
a5e1ec53
AA
58 xw->local->phy->current_channel = xw->chan;
59 xw->local->phy->current_page = xw->page;
5b641ebe 60 }
61
a5e1ec53 62 res = xw->local->ops->xmit(&xw->local->hw, xw->skb);
7dd43d35
AO
63 if (res)
64 pr_debug("transmission failed\n");
5b641ebe 65
66out:
a5e1ec53 67 mutex_unlock(&xw->local->phy->pib_lock);
5b641ebe 68
b5992fe9
AO
69 /* Restart the netif queue on each sub_if_data object. */
70 rcu_read_lock();
d98be45b 71 list_for_each_entry_rcu(sdata, &xw->local->interfaces, list)
b5992fe9
AO
72 netif_wake_queue(sdata->dev);
73 rcu_read_unlock();
5b641ebe 74
75 dev_kfree_skb(xw->skb);
76
77 kfree(xw);
78}
79
a5e1ec53 80netdev_tx_t mac802154_tx(struct ieee802154_local *local, struct sk_buff *skb,
5b641ebe 81 u8 page, u8 chan)
82{
83 struct xmit_work *work;
036562f9 84 struct ieee802154_sub_if_data *sdata;
5b641ebe 85
a5e1ec53 86 if (!(local->phy->channels_supported[page] & (1 << chan))) {
5b641ebe 87 WARN_ON(1);
f5588912 88 goto err_tx;
8a8e28b8 89 }
5b641ebe 90
a5e1ec53 91 mac802154_monitors_rx(mac802154_to_priv(&local->hw), skb);
72fd5a8b 92
a5e1ec53 93 if (!(local->hw.flags & IEEE802154_HW_OMIT_CKSUM)) {
5b641ebe 94 u16 crc = crc_ccitt(0, skb->data, skb->len);
95 u8 *data = skb_put(skb, 2);
4710d806 96
5b641ebe 97 data[0] = crc & 0xff;
98 data[1] = crc >> 8;
99 }
100
a5e1ec53 101 if (skb_cow_head(skb, local->hw.extra_tx_headroom))
f5588912 102 goto err_tx;
5b641ebe 103
f5588912 104 work = kzalloc(sizeof(*work), GFP_ATOMIC);
fcefbe9f
AO
105 if (!work) {
106 kfree_skb(skb);
5b641ebe 107 return NETDEV_TX_BUSY;
fcefbe9f 108 }
5b641ebe 109
b5992fe9
AO
110 /* Stop the netif queue on each sub_if_data object. */
111 rcu_read_lock();
d98be45b 112 list_for_each_entry_rcu(sdata, &local->interfaces, list)
b5992fe9
AO
113 netif_stop_queue(sdata->dev);
114 rcu_read_unlock();
115
5b641ebe 116 INIT_WORK(&work->work, mac802154_xmit_worker);
117 work->skb = skb;
a5e1ec53 118 work->local = local;
5b641ebe 119 work->page = page;
120 work->chan = chan;
5b641ebe 121
a5e1ec53 122 queue_work(local->dev_workqueue, &work->work);
5b641ebe 123
124 return NETDEV_TX_OK;
f5588912
VB
125
126err_tx:
127 kfree_skb(skb);
128 return NETDEV_TX_OK;
5b641ebe 129}
This page took 0.154922 seconds and 5 git commands to generate.