]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/blob - drivers/net/wimax/i2400m/sdio-tx.c
i2400m/SDIO: TX and RX path backends
[linux-2.6-omap-h63xx.git] / drivers / net / wimax / i2400m / sdio-tx.c
1 /*
2  * Intel Wireless WiMAX Connection 2400m
3  * SDIO TX transaction backends
4  *
5  *
6  * Copyright (C) 2007-2008 Intel Corporation. All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  *
12  *   * Redistributions of source code must retain the above copyright
13  *     notice, this list of conditions and the following disclaimer.
14  *   * Redistributions in binary form must reproduce the above copyright
15  *     notice, this list of conditions and the following disclaimer in
16  *     the documentation and/or other materials provided with the
17  *     distribution.
18  *   * Neither the name of Intel Corporation nor the names of its
19  *     contributors may be used to endorse or promote products derived
20  *     from this software without specific prior written permission.
21  *
22  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
25  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
26  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
27  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
28  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
32  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33  *
34  *
35  * Intel Corporation <linux-wimax@intel.com>
36  * Dirk Brandewie <dirk.j.brandewie@intel.com>
37  *  - Initial implementation
38  *
39  *
40  * Takes the TX messages in the i2400m's driver TX FIFO and sends them
41  * to the device until there are no more.
42  *
43  * If we fail sending the message, we just drop it. There isn't much
44  * we can do at this point. Most of the traffic is network, which has
45  * recovery methods for dropped packets.
46  *
47  * The SDIO functions are not atomic, so we can't run from the context
48  * where i2400m->bus_tx_kick() [i2400ms_bus_tx_kick()] is being called
49  * (some times atomic). Thus, the actual TX work is deferred to a
50  * workqueue.
51  *
52  * ROADMAP
53  *
54  * i2400ms_bus_tx_kick()
55  *   i2400ms_tx_submit()     [through workqueue]
56  *
57  * i2400m_tx_setup()
58  *
59  * i2400m_tx_release()
60  */
61 #include <linux/mmc/sdio_func.h>
62 #include "i2400m-sdio.h"
63
64 #define D_SUBMODULE tx
65 #include "sdio-debug-levels.h"
66
67
68 /*
69  * Pull TX transations from the TX FIFO and send them to the device
70  * until there are no more.
71  */
72 static
73 void i2400ms_tx_submit(struct work_struct *ws)
74 {
75         int result;
76         struct i2400ms *i2400ms = container_of(ws, struct i2400ms, tx_worker);
77         struct i2400m *i2400m = &i2400ms->i2400m;
78         struct sdio_func *func = i2400ms->func;
79         struct device *dev = &func->dev;
80         struct i2400m_msg_hdr *tx_msg;
81         size_t tx_msg_size;
82
83         d_fnstart(4, dev, "(i2400ms %p, i2400m %p)\n", i2400ms, i2400ms);
84
85         while (NULL != (tx_msg = i2400m_tx_msg_get(i2400m, &tx_msg_size))) {
86                 d_printf(2, dev, "TX: submitting %zu bytes\n", tx_msg_size);
87                 d_dump(5, dev, tx_msg, tx_msg_size);
88
89                 sdio_claim_host(func);
90                 result = sdio_memcpy_toio(func, 0, tx_msg, tx_msg_size);
91                 sdio_release_host(func);
92
93                 i2400m_tx_msg_sent(i2400m);
94
95                 if (result < 0) {
96                         dev_err(dev, "TX: cannot submit TX; tx_msg @%zu %zu B:"
97                                 " %d\n", (void *) tx_msg - i2400m->tx_buf,
98                                 tx_msg_size, result);
99                 }
100
101                 d_printf(2, dev, "TX: %zub submitted\n", tx_msg_size);
102         }
103
104         d_fnend(4, dev, "(i2400ms %p) = void\n", i2400ms);
105 }
106
107
108 /*
109  * The generic driver notifies us that there is data ready for TX
110  *
111  * Schedule a run of i2400ms_tx_submit() to handle it.
112  */
113 void i2400ms_bus_tx_kick(struct i2400m *i2400m)
114 {
115         struct i2400ms *i2400ms = container_of(i2400m, struct i2400ms, i2400m);
116         struct device *dev = &i2400ms->func->dev;
117
118         d_fnstart(3, dev, "(i2400m %p) = void\n", i2400m);
119
120         /* schedule tx work, this is because tx may block, therefore
121          * it has to run in a thread context.
122          */
123         queue_work(i2400ms->tx_workqueue, &i2400ms->tx_worker);
124
125         d_fnend(3, dev, "(i2400m %p) = void\n", i2400m);
126 }
127
128 int i2400ms_tx_setup(struct i2400ms *i2400ms)
129 {
130         int result;
131         struct device *dev = &i2400ms->func->dev;
132         struct i2400m *i2400m = &i2400ms->i2400m;
133
134         d_fnstart(5, dev, "(i2400ms %p)\n", i2400ms);
135
136         INIT_WORK(&i2400ms->tx_worker, i2400ms_tx_submit);
137         snprintf(i2400ms->tx_wq_name, sizeof(i2400ms->tx_wq_name),
138                  "%s-tx", i2400m->wimax_dev.name);
139         i2400ms->tx_workqueue =
140                 create_singlethread_workqueue(i2400ms->tx_wq_name);
141         if (NULL == i2400ms->tx_workqueue) {
142                 dev_err(dev, "TX: failed to create workqueue\n");
143                 result = -ENOMEM;
144         } else
145                 result = 0;
146         d_fnend(5, dev, "(i2400ms %p) = %d\n", i2400ms, result);
147         return result;
148 }
149
150 void i2400ms_tx_release(struct i2400ms *i2400ms)
151 {
152         destroy_workqueue(i2400ms->tx_workqueue);
153 }