1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22#include "dvb_usb_common.h"
23
24static int dvb_usb_v2_generic_io(struct dvb_usb_device *d,
25 u8 *wbuf, u16 wlen, u8 *rbuf, u16 rlen)
26{
27 int ret, actual_length;
28
29 if (!d || !wbuf || !wlen || !d->props->generic_bulk_ctrl_endpoint ||
30 !d->props->generic_bulk_ctrl_endpoint_response) {
31 dev_dbg(&d->udev->dev, "%s: failed=%d\n", __func__, -EINVAL);
32 return -EINVAL;
33 }
34
35 dev_dbg(&d->udev->dev, "%s: >>> %*ph\n", __func__, wlen, wbuf);
36
37 ret = usb_bulk_msg(d->udev, usb_sndbulkpipe(d->udev,
38 d->props->generic_bulk_ctrl_endpoint), wbuf, wlen,
39 &actual_length, 2000);
40 if (ret < 0)
41 dev_err(&d->udev->dev, "%s: usb_bulk_msg() failed=%d\n",
42 KBUILD_MODNAME, ret);
43 else
44 ret = actual_length != wlen ? -EIO : 0;
45
46
47 if (!ret && rbuf && rlen) {
48 if (d->props->generic_bulk_ctrl_delay)
49 usleep_range(d->props->generic_bulk_ctrl_delay,
50 d->props->generic_bulk_ctrl_delay
51 + 20000);
52
53 ret = usb_bulk_msg(d->udev, usb_rcvbulkpipe(d->udev,
54 d->props->generic_bulk_ctrl_endpoint_response),
55 rbuf, rlen, &actual_length, 2000);
56 if (ret)
57 dev_err(&d->udev->dev,
58 "%s: 2nd usb_bulk_msg() failed=%d\n",
59 KBUILD_MODNAME, ret);
60
61 dev_dbg(&d->udev->dev, "%s: <<< %*ph\n", __func__,
62 actual_length, rbuf);
63 }
64
65 return ret;
66}
67
68int dvb_usbv2_generic_rw(struct dvb_usb_device *d,
69 u8 *wbuf, u16 wlen, u8 *rbuf, u16 rlen)
70{
71 int ret;
72
73 mutex_lock(&d->usb_mutex);
74 ret = dvb_usb_v2_generic_io(d, wbuf, wlen, rbuf, rlen);
75 mutex_unlock(&d->usb_mutex);
76
77 return ret;
78}
79EXPORT_SYMBOL(dvb_usbv2_generic_rw);
80
81int dvb_usbv2_generic_write(struct dvb_usb_device *d, u8 *buf, u16 len)
82{
83 int ret;
84
85 mutex_lock(&d->usb_mutex);
86 ret = dvb_usb_v2_generic_io(d, buf, len, NULL, 0);
87 mutex_unlock(&d->usb_mutex);
88
89 return ret;
90}
91EXPORT_SYMBOL(dvb_usbv2_generic_write);
92
93int dvb_usbv2_generic_rw_locked(struct dvb_usb_device *d,
94 u8 *wbuf, u16 wlen, u8 *rbuf, u16 rlen)
95{
96 return dvb_usb_v2_generic_io(d, wbuf, wlen, rbuf, rlen);
97}
98EXPORT_SYMBOL(dvb_usbv2_generic_rw_locked);
99
100int dvb_usbv2_generic_write_locked(struct dvb_usb_device *d, u8 *buf, u16 len)
101{
102 return dvb_usb_v2_generic_io(d, buf, len, NULL, 0);
103}
104EXPORT_SYMBOL(dvb_usbv2_generic_write_locked);
105