2 * Line6 Linux USB driver - 0.8.0
4 * Copyright (C) 2004-2009 Markus Grabner (grabner@icg.tugraz.at)
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation, version 2.
14 #include <linux/slab.h>
16 #include "dumprequest.h"
20 Set "dump in progress" flag.
22 void line6_dump_started(struct line6_dump_request *l6dr, int dest)
24 l6dr->in_progress = dest;
28 Invalidate current channel, i.e., set "dump in progress" flag.
29 Reading from the "dump" special file blocks until dump is completed.
31 void line6_invalidate_current(struct line6_dump_request *l6dr)
33 line6_dump_started(l6dr, LINE6_DUMP_CURRENT);
37 Clear "dump in progress" flag and notify waiting processes.
39 void line6_dump_finished(struct line6_dump_request *l6dr)
41 l6dr->in_progress = LINE6_DUMP_NONE;
42 wake_up_interruptible(&l6dr->wait);
46 Send an asynchronous channel dump request.
48 int line6_dump_request_async(struct line6_dump_request *l6dr,
49 struct usb_line6 *line6, int num)
52 line6_invalidate_current(l6dr);
53 ret = line6_send_raw_message_async(line6, l6dr->reqbufs[num].buffer,
54 l6dr->reqbufs[num].length);
57 line6_dump_finished(l6dr);
63 Send an asynchronous dump request after a given interval.
65 void line6_startup_delayed(struct line6_dump_request *l6dr, int seconds,
66 void (*function)(unsigned long), void *data)
68 l6dr->timer.expires = jiffies + seconds * HZ;
69 l6dr->timer.function = function;
70 l6dr->timer.data = (unsigned long)data;
71 add_timer(&l6dr->timer);
77 int line6_wait_dump(struct line6_dump_request *l6dr, int nonblock)
80 DECLARE_WAITQUEUE(wait, current);
81 add_wait_queue(&l6dr->wait, &wait);
82 current->state = TASK_INTERRUPTIBLE;
84 while (l6dr->in_progress) {
90 if (signal_pending(current)) {
91 retval = -ERESTARTSYS;
97 current->state = TASK_RUNNING;
98 remove_wait_queue(&l6dr->wait, &wait);
103 Initialize dump request buffer.
105 int line6_dumpreq_initbuf(struct line6_dump_request *l6dr, const void *buf,
108 l6dr->reqbufs[num].buffer = kmalloc(len, GFP_KERNEL);
109 if (l6dr->reqbufs[num].buffer == NULL)
111 memcpy(l6dr->reqbufs[num].buffer, buf, len);
112 l6dr->reqbufs[num].length = len;
117 Initialize dump request data structure (including one buffer).
119 int line6_dumpreq_init(struct line6_dump_request *l6dr, const void *buf,
123 ret = line6_dumpreq_initbuf(l6dr, buf, len, 0);
126 init_waitqueue_head(&l6dr->wait);
127 init_timer(&l6dr->timer);
132 Destruct dump request data structure.
134 void line6_dumpreq_destructbuf(struct line6_dump_request *l6dr, int num)
138 if (l6dr->reqbufs[num].buffer == NULL)
140 kfree(l6dr->reqbufs[num].buffer);
141 l6dr->reqbufs[num].buffer = NULL;
145 Destruct dump request data structure.
147 void line6_dumpreq_destruct(struct line6_dump_request *l6dr)
149 if (l6dr->reqbufs[0].buffer == NULL)
151 line6_dumpreq_destructbuf(l6dr, 0);
153 del_timer_sync(&l6dr->timer);