aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/uwb/whc-rc.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/uwb/whc-rc.c')
-rw-r--r--drivers/uwb/whc-rc.c118
1 files changed, 39 insertions, 79 deletions
diff --git a/drivers/uwb/whc-rc.c b/drivers/uwb/whc-rc.c
index 1711deadb114..19a1dd129212 100644
--- a/drivers/uwb/whc-rc.c
+++ b/drivers/uwb/whc-rc.c
@@ -39,7 +39,6 @@
39 * them to the hw and transfer the replies/notifications back to the 39 * them to the hw and transfer the replies/notifications back to the
40 * UWB stack through the UWB daemon (UWBD). 40 * UWB stack through the UWB daemon (UWBD).
41 */ 41 */
42#include <linux/version.h>
43#include <linux/init.h> 42#include <linux/init.h>
44#include <linux/module.h> 43#include <linux/module.h>
45#include <linux/pci.h> 44#include <linux/pci.h>
@@ -49,10 +48,8 @@
49#include <linux/uwb.h> 48#include <linux/uwb.h>
50#include <linux/uwb/whci.h> 49#include <linux/uwb/whci.h>
51#include <linux/uwb/umc.h> 50#include <linux/uwb/umc.h>
52#include "uwb-internal.h"
53 51
54#define D_LOCAL 0 52#include "uwb-internal.h"
55#include <linux/uwb/debug.h>
56 53
57/** 54/**
58 * Descriptor for an instance of the UWB Radio Control Driver that 55 * Descriptor for an instance of the UWB Radio Control Driver that
@@ -98,13 +95,8 @@ static int whcrc_cmd(struct uwb_rc *uwb_rc,
98 struct device *dev = &whcrc->umc_dev->dev; 95 struct device *dev = &whcrc->umc_dev->dev;
99 u32 urccmd; 96 u32 urccmd;
100 97
101 d_fnstart(3, dev, "(%p, %p, %zu)\n", uwb_rc, cmd, cmd_size); 98 if (cmd_size >= 4096)
102 might_sleep(); 99 return -EINVAL;
103
104 if (cmd_size >= 4096) {
105 result = -E2BIG;
106 goto error;
107 }
108 100
109 /* 101 /*
110 * If the URC is halted, then the hardware has reset itself. 102 * If the URC is halted, then the hardware has reset itself.
@@ -115,16 +107,14 @@ static int whcrc_cmd(struct uwb_rc *uwb_rc,
115 if (le_readl(whcrc->rc_base + URCSTS) & URCSTS_HALTED) { 107 if (le_readl(whcrc->rc_base + URCSTS) & URCSTS_HALTED) {
116 dev_err(dev, "requesting reset of halted radio controller\n"); 108 dev_err(dev, "requesting reset of halted radio controller\n");
117 uwb_rc_reset_all(uwb_rc); 109 uwb_rc_reset_all(uwb_rc);
118 result = -EIO; 110 return -EIO;
119 goto error;
120 } 111 }
121 112
122 result = wait_event_timeout(whcrc->cmd_wq, 113 result = wait_event_timeout(whcrc->cmd_wq,
123 !(le_readl(whcrc->rc_base + URCCMD) & URCCMD_ACTIVE), HZ/2); 114 !(le_readl(whcrc->rc_base + URCCMD) & URCCMD_ACTIVE), HZ/2);
124 if (result == 0) { 115 if (result == 0) {
125 dev_err(dev, "device is not ready to execute commands\n"); 116 dev_err(dev, "device is not ready to execute commands\n");
126 result = -ETIMEDOUT; 117 return -ETIMEDOUT;
127 goto error;
128 } 118 }
129 119
130 memmove(whcrc->cmd_buf, cmd, cmd_size); 120 memmove(whcrc->cmd_buf, cmd, cmd_size);
@@ -137,10 +127,7 @@ static int whcrc_cmd(struct uwb_rc *uwb_rc,
137 whcrc->rc_base + URCCMD); 127 whcrc->rc_base + URCCMD);
138 spin_unlock(&whcrc->irq_lock); 128 spin_unlock(&whcrc->irq_lock);
139 129
140error: 130 return 0;
141 d_fnend(3, dev, "(%p, %p, %zu) = %d\n",
142 uwb_rc, cmd, cmd_size, result);
143 return result;
144} 131}
145 132
146static int whcrc_reset(struct uwb_rc *rc) 133static int whcrc_reset(struct uwb_rc *rc)
@@ -167,34 +154,25 @@ static int whcrc_reset(struct uwb_rc *rc)
167static 154static
168void whcrc_enable_events(struct whcrc *whcrc) 155void whcrc_enable_events(struct whcrc *whcrc)
169{ 156{
170 struct device *dev = &whcrc->umc_dev->dev;
171 u32 urccmd; 157 u32 urccmd;
172 158
173 d_fnstart(4, dev, "(whcrc %p)\n", whcrc);
174
175 le_writeq(whcrc->evt_dma_buf, whcrc->rc_base + URCEVTADDR); 159 le_writeq(whcrc->evt_dma_buf, whcrc->rc_base + URCEVTADDR);
176 160
177 spin_lock(&whcrc->irq_lock); 161 spin_lock(&whcrc->irq_lock);
178 urccmd = le_readl(whcrc->rc_base + URCCMD) & ~URCCMD_ACTIVE; 162 urccmd = le_readl(whcrc->rc_base + URCCMD) & ~URCCMD_ACTIVE;
179 le_writel(urccmd | URCCMD_EARV, whcrc->rc_base + URCCMD); 163 le_writel(urccmd | URCCMD_EARV, whcrc->rc_base + URCCMD);
180 spin_unlock(&whcrc->irq_lock); 164 spin_unlock(&whcrc->irq_lock);
181
182 d_fnend(4, dev, "(whcrc %p) = void\n", whcrc);
183} 165}
184 166
185static void whcrc_event_work(struct work_struct *work) 167static void whcrc_event_work(struct work_struct *work)
186{ 168{
187 struct whcrc *whcrc = container_of(work, struct whcrc, event_work); 169 struct whcrc *whcrc = container_of(work, struct whcrc, event_work);
188 struct device *dev = &whcrc->umc_dev->dev;
189 size_t size; 170 size_t size;
190 u64 urcevtaddr; 171 u64 urcevtaddr;
191 172
192 urcevtaddr = le_readq(whcrc->rc_base + URCEVTADDR); 173 urcevtaddr = le_readq(whcrc->rc_base + URCEVTADDR);
193 size = urcevtaddr & URCEVTADDR_OFFSET_MASK; 174 size = urcevtaddr & URCEVTADDR_OFFSET_MASK;
194 175
195 d_printf(3, dev, "received %zu octet event\n", size);
196 d_dump(4, dev, whcrc->evt_buf, size > 32 ? 32 : size);
197
198 uwb_rc_neh_grok(whcrc->uwb_rc, whcrc->evt_buf, size); 176 uwb_rc_neh_grok(whcrc->uwb_rc, whcrc->evt_buf, size);
199 whcrc_enable_events(whcrc); 177 whcrc_enable_events(whcrc);
200} 178}
@@ -217,22 +195,15 @@ irqreturn_t whcrc_irq_cb(int irq, void *_whcrc)
217 return IRQ_NONE; 195 return IRQ_NONE;
218 le_writel(urcsts & URCSTS_INT_MASK, whcrc->rc_base + URCSTS); 196 le_writel(urcsts & URCSTS_INT_MASK, whcrc->rc_base + URCSTS);
219 197
220 d_printf(4, dev, "acked 0x%08x, urcsts 0x%08x\n",
221 le_readl(whcrc->rc_base + URCSTS), urcsts);
222
223 if (urcsts & URCSTS_HSE) { 198 if (urcsts & URCSTS_HSE) {
224 dev_err(dev, "host system error -- hardware halted\n"); 199 dev_err(dev, "host system error -- hardware halted\n");
225 /* FIXME: do something sensible here */ 200 /* FIXME: do something sensible here */
226 goto out; 201 goto out;
227 } 202 }
228 if (urcsts & URCSTS_ER) { 203 if (urcsts & URCSTS_ER)
229 d_printf(3, dev, "ER: event ready\n");
230 schedule_work(&whcrc->event_work); 204 schedule_work(&whcrc->event_work);
231 } 205 if (urcsts & URCSTS_RCI)
232 if (urcsts & URCSTS_RCI) {
233 d_printf(3, dev, "RCI: ready to execute another command\n");
234 wake_up_all(&whcrc->cmd_wq); 206 wake_up_all(&whcrc->cmd_wq);
235 }
236out: 207out:
237 return IRQ_HANDLED; 208 return IRQ_HANDLED;
238} 209}
@@ -251,8 +222,7 @@ int whcrc_setup_rc_umc(struct whcrc *whcrc)
251 whcrc->area = umc_dev->resource.start; 222 whcrc->area = umc_dev->resource.start;
252 whcrc->rc_len = umc_dev->resource.end - umc_dev->resource.start + 1; 223 whcrc->rc_len = umc_dev->resource.end - umc_dev->resource.start + 1;
253 result = -EBUSY; 224 result = -EBUSY;
254 if (request_mem_region(whcrc->area, whcrc->rc_len, KBUILD_MODNAME) 225 if (request_mem_region(whcrc->area, whcrc->rc_len, KBUILD_MODNAME) == NULL) {
255 == NULL) {
256 dev_err(dev, "can't request URC region (%zu bytes @ 0x%lx): %d\n", 226 dev_err(dev, "can't request URC region (%zu bytes @ 0x%lx): %d\n",
257 whcrc->rc_len, whcrc->area, result); 227 whcrc->rc_len, whcrc->area, result);
258 goto error_request_region; 228 goto error_request_region;
@@ -287,8 +257,6 @@ int whcrc_setup_rc_umc(struct whcrc *whcrc)
287 dev_err(dev, "Can't allocate evt transfer buffer\n"); 257 dev_err(dev, "Can't allocate evt transfer buffer\n");
288 goto error_evt_buffer; 258 goto error_evt_buffer;
289 } 259 }
290 d_printf(3, dev, "UWB RC Interface: %zu bytes at 0x%p, irq %u\n",
291 whcrc->rc_len, whcrc->rc_base, umc_dev->irq);
292 return 0; 260 return 0;
293 261
294error_evt_buffer: 262error_evt_buffer:
@@ -333,47 +301,23 @@ void whcrc_release_rc_umc(struct whcrc *whcrc)
333static int whcrc_start_rc(struct uwb_rc *rc) 301static int whcrc_start_rc(struct uwb_rc *rc)
334{ 302{
335 struct whcrc *whcrc = rc->priv; 303 struct whcrc *whcrc = rc->priv;
336 int result = 0;
337 struct device *dev = &whcrc->umc_dev->dev; 304 struct device *dev = &whcrc->umc_dev->dev;
338 unsigned long start, duration;
339 305
340 /* Reset the thing */ 306 /* Reset the thing */
341 le_writel(URCCMD_RESET, whcrc->rc_base + URCCMD); 307 le_writel(URCCMD_RESET, whcrc->rc_base + URCCMD);
342 if (d_test(3))
343 start = jiffies;
344 if (whci_wait_for(dev, whcrc->rc_base + URCCMD, URCCMD_RESET, 0, 308 if (whci_wait_for(dev, whcrc->rc_base + URCCMD, URCCMD_RESET, 0,
345 5000, "device to reset at init") < 0) { 309 5000, "hardware reset") < 0)
346 result = -EBUSY; 310 return -EBUSY;
347 goto error;
348 } else if (d_test(3)) {
349 duration = jiffies - start;
350 if (duration > msecs_to_jiffies(40))
351 dev_err(dev, "Device took %ums to "
352 "reset. MAX expected: 40ms\n",
353 jiffies_to_msecs(duration));
354 }
355 311
356 /* Set the event buffer, start the controller (enable IRQs later) */ 312 /* Set the event buffer, start the controller (enable IRQs later) */
357 le_writel(0, whcrc->rc_base + URCINTR); 313 le_writel(0, whcrc->rc_base + URCINTR);
358 le_writel(URCCMD_RS, whcrc->rc_base + URCCMD); 314 le_writel(URCCMD_RS, whcrc->rc_base + URCCMD);
359 result = -ETIMEDOUT;
360 if (d_test(3))
361 start = jiffies;
362 if (whci_wait_for(dev, whcrc->rc_base + URCSTS, URCSTS_HALTED, 0, 315 if (whci_wait_for(dev, whcrc->rc_base + URCSTS, URCSTS_HALTED, 0,
363 5000, "device to start") < 0) 316 5000, "radio controller start") < 0)
364 goto error; 317 return -ETIMEDOUT;
365 if (d_test(3)) {
366 duration = jiffies - start;
367 if (duration > msecs_to_jiffies(40))
368 dev_err(dev, "Device took %ums to start. "
369 "MAX expected: 40ms\n",
370 jiffies_to_msecs(duration));
371 }
372 whcrc_enable_events(whcrc); 318 whcrc_enable_events(whcrc);
373 result = 0;
374 le_writel(URCINTR_EN_ALL, whcrc->rc_base + URCINTR); 319 le_writel(URCINTR_EN_ALL, whcrc->rc_base + URCINTR);
375error: 320 return 0;
376 return result;
377} 321}
378 322
379 323
@@ -395,7 +339,7 @@ void whcrc_stop_rc(struct uwb_rc *rc)
395 339
396 le_writel(0, whcrc->rc_base + URCCMD); 340 le_writel(0, whcrc->rc_base + URCCMD);
397 whci_wait_for(&umc_dev->dev, whcrc->rc_base + URCSTS, 341 whci_wait_for(&umc_dev->dev, whcrc->rc_base + URCSTS,
398 URCSTS_HALTED, 0, 40, "URCSTS.HALTED"); 342 URCSTS_HALTED, URCSTS_HALTED, 100, "radio controller stop");
399} 343}
400 344
401static void whcrc_init(struct whcrc *whcrc) 345static void whcrc_init(struct whcrc *whcrc)
@@ -421,7 +365,6 @@ int whcrc_probe(struct umc_dev *umc_dev)
421 struct whcrc *whcrc; 365 struct whcrc *whcrc;
422 struct device *dev = &umc_dev->dev; 366 struct device *dev = &umc_dev->dev;
423 367
424 d_fnstart(3, dev, "(umc_dev %p)\n", umc_dev);
425 result = -ENOMEM; 368 result = -ENOMEM;
426 uwb_rc = uwb_rc_alloc(); 369 uwb_rc = uwb_rc_alloc();
427 if (uwb_rc == NULL) { 370 if (uwb_rc == NULL) {
@@ -453,7 +396,6 @@ int whcrc_probe(struct umc_dev *umc_dev)
453 if (result < 0) 396 if (result < 0)
454 goto error_rc_add; 397 goto error_rc_add;
455 umc_set_drvdata(umc_dev, whcrc); 398 umc_set_drvdata(umc_dev, whcrc);
456 d_fnend(3, dev, "(umc_dev %p) = 0\n", umc_dev);
457 return 0; 399 return 0;
458 400
459error_rc_add: 401error_rc_add:
@@ -463,7 +405,6 @@ error_setup_rc_umc:
463error_alloc: 405error_alloc:
464 uwb_rc_put(uwb_rc); 406 uwb_rc_put(uwb_rc);
465error_rc_alloc: 407error_rc_alloc:
466 d_fnend(3, dev, "(umc_dev %p) = %d\n", umc_dev, result);
467 return result; 408 return result;
468} 409}
469 410
@@ -486,7 +427,24 @@ static void whcrc_remove(struct umc_dev *umc_dev)
486 whcrc_release_rc_umc(whcrc); 427 whcrc_release_rc_umc(whcrc);
487 kfree(whcrc); 428 kfree(whcrc);
488 uwb_rc_put(uwb_rc); 429 uwb_rc_put(uwb_rc);
489 d_printf(1, &umc_dev->dev, "freed whcrc %p\n", whcrc); 430}
431
432static int whcrc_pre_reset(struct umc_dev *umc)
433{
434 struct whcrc *whcrc = umc_get_drvdata(umc);
435 struct uwb_rc *uwb_rc = whcrc->uwb_rc;
436
437 uwb_rc_pre_reset(uwb_rc);
438 return 0;
439}
440
441static int whcrc_post_reset(struct umc_dev *umc)
442{
443 struct whcrc *whcrc = umc_get_drvdata(umc);
444 struct uwb_rc *uwb_rc = whcrc->uwb_rc;
445
446 uwb_rc_post_reset(uwb_rc);
447 return 0;
490} 448}
491 449
492/* PCI device ID's that we handle [so it gets loaded] */ 450/* PCI device ID's that we handle [so it gets loaded] */
@@ -497,10 +455,12 @@ static struct pci_device_id whcrc_id_table[] = {
497MODULE_DEVICE_TABLE(pci, whcrc_id_table); 455MODULE_DEVICE_TABLE(pci, whcrc_id_table);
498 456
499static struct umc_driver whcrc_driver = { 457static struct umc_driver whcrc_driver = {
500 .name = "whc-rc", 458 .name = "whc-rc",
501 .cap_id = UMC_CAP_ID_WHCI_RC, 459 .cap_id = UMC_CAP_ID_WHCI_RC,
502 .probe = whcrc_probe, 460 .probe = whcrc_probe,
503 .remove = whcrc_remove, 461 .remove = whcrc_remove,
462 .pre_reset = whcrc_pre_reset,
463 .post_reset = whcrc_post_reset,
504}; 464};
505 465
506static int __init whcrc_driver_init(void) 466static int __init whcrc_driver_init(void)