diff options
Diffstat (limited to 'drivers/net')
-rw-r--r-- | drivers/net/wimax/i2400m/sdio-rx.c | 255 | ||||
-rw-r--r-- | drivers/net/wimax/i2400m/sdio-tx.c | 153 |
2 files changed, 408 insertions, 0 deletions
diff --git a/drivers/net/wimax/i2400m/sdio-rx.c b/drivers/net/wimax/i2400m/sdio-rx.c new file mode 100644 index 000000000000..a3008b904f7d --- /dev/null +++ b/drivers/net/wimax/i2400m/sdio-rx.c | |||
@@ -0,0 +1,255 @@ | |||
1 | /* | ||
2 | * Intel Wireless WiMAX Connection 2400m | ||
3 | * SDIO RX handling | ||
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 | * This handles the RX path on SDIO. | ||
41 | * | ||
42 | * The SDIO bus driver calls the "irq" routine when data is available. | ||
43 | * This is not a traditional interrupt routine since the SDIO bus | ||
44 | * driver calls us from its irq thread context. Because of this | ||
45 | * sleeping in the SDIO RX IRQ routine is okay. | ||
46 | * | ||
47 | * From there on, we obtain the size of the data that is available, | ||
48 | * allocate an skb, copy it and then pass it to the generic driver's | ||
49 | * RX routine [i2400m_rx()]. | ||
50 | * | ||
51 | * ROADMAP | ||
52 | * | ||
53 | * i2400ms_irq() | ||
54 | * i2400ms_rx() | ||
55 | * __i2400ms_rx_get_size() | ||
56 | * i2400m_rx() | ||
57 | * | ||
58 | * i2400ms_rx_setup() | ||
59 | * | ||
60 | * i2400ms_rx_release() | ||
61 | */ | ||
62 | #include <linux/workqueue.h> | ||
63 | #include <linux/wait.h> | ||
64 | #include <linux/skbuff.h> | ||
65 | #include <linux/mmc/sdio.h> | ||
66 | #include <linux/mmc/sdio_func.h> | ||
67 | #include "i2400m-sdio.h" | ||
68 | |||
69 | #define D_SUBMODULE rx | ||
70 | #include "sdio-debug-levels.h" | ||
71 | |||
72 | |||
73 | /* | ||
74 | * Read and return the amount of bytes available for RX | ||
75 | * | ||
76 | * The RX size has to be read like this: byte reads of three | ||
77 | * sequential locations; then glue'em together. | ||
78 | * | ||
79 | * sdio_readl() doesn't work. | ||
80 | */ | ||
81 | ssize_t __i2400ms_rx_get_size(struct i2400ms *i2400ms) | ||
82 | { | ||
83 | int ret, cnt, val; | ||
84 | ssize_t rx_size; | ||
85 | unsigned xfer_size_addr; | ||
86 | struct sdio_func *func = i2400ms->func; | ||
87 | struct device *dev = &i2400ms->func->dev; | ||
88 | |||
89 | d_fnstart(7, dev, "(i2400ms %p)\n", i2400ms); | ||
90 | xfer_size_addr = I2400MS_INTR_GET_SIZE_ADDR; | ||
91 | rx_size = 0; | ||
92 | for (cnt = 0; cnt < 3; cnt++) { | ||
93 | val = sdio_readb(func, xfer_size_addr + cnt, &ret); | ||
94 | if (ret < 0) { | ||
95 | dev_err(dev, "RX: Can't read byte %d of RX size from " | ||
96 | "0x%08x: %d\n", cnt, xfer_size_addr + cnt, ret); | ||
97 | rx_size = ret; | ||
98 | goto error_read; | ||
99 | } | ||
100 | rx_size = rx_size << 8 | (val & 0xff); | ||
101 | } | ||
102 | d_printf(6, dev, "RX: rx_size is %ld\n", (long) rx_size); | ||
103 | error_read: | ||
104 | d_fnend(7, dev, "(i2400ms %p) = %ld\n", i2400ms, (long) rx_size); | ||
105 | return rx_size; | ||
106 | } | ||
107 | |||
108 | |||
109 | /* | ||
110 | * Read data from the device (when in normal) | ||
111 | * | ||
112 | * Allocate an SKB of the right size, read the data in and then | ||
113 | * deliver it to the generic layer. | ||
114 | * | ||
115 | * We also check for a reboot barker. That means the device died and | ||
116 | * we have to reboot it. | ||
117 | */ | ||
118 | static | ||
119 | void i2400ms_rx(struct i2400ms *i2400ms) | ||
120 | { | ||
121 | int ret; | ||
122 | struct sdio_func *func = i2400ms->func; | ||
123 | struct device *dev = &func->dev; | ||
124 | struct i2400m *i2400m = &i2400ms->i2400m; | ||
125 | struct sk_buff *skb; | ||
126 | ssize_t rx_size; | ||
127 | |||
128 | d_fnstart(7, dev, "(i2400ms %p)\n", i2400ms); | ||
129 | rx_size = __i2400ms_rx_get_size(i2400ms); | ||
130 | if (rx_size < 0) { | ||
131 | ret = rx_size; | ||
132 | goto error_get_size; | ||
133 | } | ||
134 | ret = -ENOMEM; | ||
135 | skb = alloc_skb(rx_size, GFP_ATOMIC); | ||
136 | if (NULL == skb) { | ||
137 | dev_err(dev, "RX: unable to alloc skb\n"); | ||
138 | goto error_alloc_skb; | ||
139 | } | ||
140 | |||
141 | ret = sdio_memcpy_fromio(func, skb->data, | ||
142 | I2400MS_DATA_ADDR, rx_size); | ||
143 | if (ret < 0) { | ||
144 | dev_err(dev, "RX: SDIO data read failed: %d\n", ret); | ||
145 | goto error_memcpy_fromio; | ||
146 | } | ||
147 | /* Check if device has reset */ | ||
148 | if (!memcmp(skb->data, i2400m_NBOOT_BARKER, | ||
149 | sizeof(i2400m_NBOOT_BARKER)) | ||
150 | || !memcmp(skb->data, i2400m_SBOOT_BARKER, | ||
151 | sizeof(i2400m_SBOOT_BARKER))) { | ||
152 | ret = i2400m_dev_reset_handle(i2400m); | ||
153 | kfree_skb(skb); | ||
154 | } else { | ||
155 | skb_put(skb, rx_size); | ||
156 | i2400m_rx(i2400m, skb); | ||
157 | } | ||
158 | d_fnend(7, dev, "(i2400ms %p) = void\n", i2400ms); | ||
159 | return; | ||
160 | |||
161 | error_memcpy_fromio: | ||
162 | kfree_skb(skb); | ||
163 | error_alloc_skb: | ||
164 | error_get_size: | ||
165 | d_fnend(7, dev, "(i2400ms %p) = %d\n", i2400ms, ret); | ||
166 | return; | ||
167 | } | ||
168 | |||
169 | |||
170 | /* | ||
171 | * Process an interrupt from the SDIO card | ||
172 | * | ||
173 | * FIXME: need to process other events that are not just ready-to-read | ||
174 | * | ||
175 | * Checks there is data ready and then proceeds to read it. | ||
176 | */ | ||
177 | static | ||
178 | void i2400ms_irq(struct sdio_func *func) | ||
179 | { | ||
180 | int ret; | ||
181 | struct i2400ms *i2400ms = sdio_get_drvdata(func); | ||
182 | struct i2400m *i2400m = &i2400ms->i2400m; | ||
183 | struct device *dev = &func->dev; | ||
184 | int val; | ||
185 | |||
186 | d_fnstart(6, dev, "(i2400ms %p)\n", i2400ms); | ||
187 | val = sdio_readb(func, I2400MS_INTR_STATUS_ADDR, &ret); | ||
188 | if (ret < 0) { | ||
189 | dev_err(dev, "RX: Can't read interrupt status: %d\n", ret); | ||
190 | goto error_no_irq; | ||
191 | } | ||
192 | if (!val) { | ||
193 | dev_err(dev, "RX: BUG? got IRQ but no interrupt ready?\n"); | ||
194 | goto error_no_irq; | ||
195 | } | ||
196 | sdio_writeb(func, 1, I2400MS_INTR_CLEAR_ADDR, &ret); | ||
197 | if (WARN_ON(i2400m->boot_mode != 0)) | ||
198 | dev_err(dev, "RX: SW BUG? boot mode and IRQ is up?\n"); | ||
199 | else | ||
200 | i2400ms_rx(i2400ms); | ||
201 | error_no_irq: | ||
202 | d_fnend(6, dev, "(i2400ms %p) = void\n", i2400ms); | ||
203 | return; | ||
204 | } | ||
205 | |||
206 | |||
207 | /* | ||
208 | * Setup SDIO RX | ||
209 | * | ||
210 | * Hooks up the IRQ handler and then enables IRQs. | ||
211 | */ | ||
212 | int i2400ms_rx_setup(struct i2400ms *i2400ms) | ||
213 | { | ||
214 | int result; | ||
215 | struct sdio_func *func = i2400ms->func; | ||
216 | struct device *dev = &func->dev; | ||
217 | |||
218 | d_fnstart(5, dev, "(i2400ms %p)\n", i2400ms); | ||
219 | sdio_claim_host(func); | ||
220 | result = sdio_claim_irq(func, i2400ms_irq); | ||
221 | if (result < 0) { | ||
222 | dev_err(dev, "Cannot claim IRQ: %d\n", result); | ||
223 | goto error_irq_claim; | ||
224 | } | ||
225 | result = 0; | ||
226 | sdio_writeb(func, 1, I2400MS_INTR_ENABLE_ADDR, &result); | ||
227 | if (result < 0) { | ||
228 | sdio_release_irq(func); | ||
229 | dev_err(dev, "Failed to enable interrupts %d\n", result); | ||
230 | } | ||
231 | error_irq_claim: | ||
232 | sdio_release_host(func); | ||
233 | d_fnend(5, dev, "(i2400ms %p) = %d\n", i2400ms, result); | ||
234 | return result; | ||
235 | } | ||
236 | |||
237 | |||
238 | /* | ||
239 | * Tear down SDIO RX | ||
240 | * | ||
241 | * Disables IRQs in the device and removes the IRQ handler. | ||
242 | */ | ||
243 | void i2400ms_rx_release(struct i2400ms *i2400ms) | ||
244 | { | ||
245 | int result; | ||
246 | struct sdio_func *func = i2400ms->func; | ||
247 | struct device *dev = &func->dev; | ||
248 | |||
249 | d_fnstart(5, dev, "(i2400ms %p)\n", i2400ms); | ||
250 | sdio_claim_host(func); | ||
251 | sdio_writeb(func, 0, I2400MS_INTR_ENABLE_ADDR, &result); | ||
252 | sdio_release_irq(func); | ||
253 | sdio_release_host(func); | ||
254 | d_fnend(5, dev, "(i2400ms %p) = %d\n", i2400ms, result); | ||
255 | } | ||
diff --git a/drivers/net/wimax/i2400m/sdio-tx.c b/drivers/net/wimax/i2400m/sdio-tx.c new file mode 100644 index 000000000000..5105a5ebc44f --- /dev/null +++ b/drivers/net/wimax/i2400m/sdio-tx.c | |||
@@ -0,0 +1,153 @@ | |||
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 | } | ||