• Home
  • History
  • Annotate
  • Line#
  • Navigate
  • Raw
  • Download
  • only in /netgear-R7000-V1.0.7.12_1.2.5/components/opensource/linux/linux-2.6.36/drivers/staging/line6/
1/*
2 * Line6 Linux USB driver - 0.8.0
3 *
4 * Copyright (C) 2004-2009 Markus Grabner (grabner@icg.tugraz.at)
5 *
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.
9 *
10 */
11
12#include "driver.h"
13
14#include <linux/slab.h>
15
16#include "dumprequest.h"
17
18
19/*
20	Set "dump in progress" flag.
21*/
22void line6_dump_started(struct line6_dump_request *l6dr, int dest)
23{
24	l6dr->in_progress = dest;
25}
26
27/*
28	Invalidate current channel, i.e., set "dump in progress" flag.
29	Reading from the "dump" special file blocks until dump is completed.
30*/
31void line6_invalidate_current(struct line6_dump_request *l6dr)
32{
33	line6_dump_started(l6dr, LINE6_DUMP_CURRENT);
34}
35
36/*
37	Clear "dump in progress" flag and notify waiting processes.
38*/
39void line6_dump_finished(struct line6_dump_request *l6dr)
40{
41	l6dr->in_progress = LINE6_DUMP_NONE;
42	wake_up_interruptible(&l6dr->wait);
43}
44
45/*
46	Send an asynchronous channel dump request.
47*/
48int line6_dump_request_async(struct line6_dump_request *l6dr,
49			     struct usb_line6 *line6, int num)
50{
51	int ret;
52	line6_invalidate_current(l6dr);
53	ret = line6_send_raw_message_async(line6, l6dr->reqbufs[num].buffer,
54					   l6dr->reqbufs[num].length);
55
56	if (ret < 0)
57		line6_dump_finished(l6dr);
58
59	return ret;
60}
61
62/*
63	Send an asynchronous dump request after a given interval.
64*/
65void line6_startup_delayed(struct line6_dump_request *l6dr, int seconds,
66			   void (*function)(unsigned long), void *data)
67{
68	l6dr->timer.expires = jiffies + seconds * HZ;
69	l6dr->timer.function = function;
70	l6dr->timer.data = (unsigned long)data;
71	add_timer(&l6dr->timer);
72}
73
74/*
75	Wait for completion.
76*/
77int line6_wait_dump(struct line6_dump_request *l6dr, int nonblock)
78{
79	int retval = 0;
80	DECLARE_WAITQUEUE(wait, current);
81	add_wait_queue(&l6dr->wait, &wait);
82	current->state = TASK_INTERRUPTIBLE;
83
84	while (l6dr->in_progress) {
85		if (nonblock) {
86			retval = -EAGAIN;
87			break;
88		}
89
90		if (signal_pending(current)) {
91			retval = -ERESTARTSYS;
92			break;
93		} else
94			schedule();
95	}
96
97	current->state = TASK_RUNNING;
98	remove_wait_queue(&l6dr->wait, &wait);
99	return retval;
100}
101
102/*
103	Initialize dump request buffer.
104*/
105int line6_dumpreq_initbuf(struct line6_dump_request *l6dr, const void *buf,
106			  size_t len, int num)
107{
108	l6dr->reqbufs[num].buffer = kmemdup(buf, len, GFP_KERNEL);
109	if (l6dr->reqbufs[num].buffer == NULL)
110		return -ENOMEM;
111	l6dr->reqbufs[num].length = len;
112	return 0;
113}
114
115/*
116	Initialize dump request data structure (including one buffer).
117*/
118int line6_dumpreq_init(struct line6_dump_request *l6dr, const void *buf,
119		       size_t len)
120{
121	int ret;
122	ret = line6_dumpreq_initbuf(l6dr, buf, len, 0);
123	if (ret < 0)
124		return ret;
125	init_waitqueue_head(&l6dr->wait);
126	init_timer(&l6dr->timer);
127	return 0;
128}
129
130/*
131	Destruct dump request data structure.
132*/
133void line6_dumpreq_destructbuf(struct line6_dump_request *l6dr, int num)
134{
135	if (l6dr == NULL)
136		return;
137	if (l6dr->reqbufs[num].buffer == NULL)
138		return;
139	kfree(l6dr->reqbufs[num].buffer);
140	l6dr->reqbufs[num].buffer = NULL;
141}
142
143/*
144	Destruct dump request data structure.
145*/
146void line6_dumpreq_destruct(struct line6_dump_request *l6dr)
147{
148	if (l6dr->reqbufs[0].buffer == NULL)
149		return;
150	line6_dumpreq_destructbuf(l6dr, 0);
151	l6dr->ok = 1;
152	del_timer_sync(&l6dr->timer);
153}
154