aboutsummaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2018-06-05 19:14:12 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2018-06-05 19:14:12 -0400
commit07c4dd3435aa387d3b58f4e941dc516513f14507 (patch)
tree26ebc60562ba573ec499f850c53ffd48f2bfdf72 /tools
parentf60342fac9fae20ada2cd5faadbc2a1337cae03f (diff)
parentc2ef60fea2dc7f903450926aee1f9c282ea529ca (diff)
Merge tag 'usb-4.18-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb
Pull USB and PHY updates from Greg KH: "Here is the big USB pull request for 4.18-rc1. Lots of stuff here, the highlights are: - phy driver updates and new additions - usual set of xhci driver updates - normal set of musb updates - gadget driver updates and new controllers - typec work, it's getting closer to getting fully out of the staging portion of the tree. - lots of minor cleanups and bugfixes. All of these have been in linux-next for a while with no reported issues" * tag 'usb-4.18-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb: (263 commits) Revert "xhci: Reset Renesas uPD72020x USB controller for 32-bit DMA issue" xhci: Add quirk to zero 64bit registers on Renesas PCIe controllers xhci: Allow more than 32 quirks usb: xhci: force all memory allocations to node selftests: add test for USB over IP driver USB: typec: fsusb302: no need to check return value of debugfs_create_dir() USB: gadget: udc: s3c2410_udc: no need to check return value of debugfs_create functions USB: gadget: udc: renesas_usb3: no need to check return value of debugfs_create functions USB: gadget: udc: pxa27x_udc: no need to check return value of debugfs_create functions USB: gadget: udc: gr_udc: no need to check return value of debugfs_create functions USB: gadget: udc: bcm63xx_udc: no need to check return value of debugfs_create functions USB: udc: atmel_usba_udc: no need to check return value of debugfs_create functions USB: dwc3: no need to check return value of debugfs_create functions USB: dwc2: no need to check return value of debugfs_create functions USB: core: no need to check return value of debugfs_create functions USB: chipidea: no need to check return value of debugfs_create functions USB: ehci-hcd: no need to check return value of debugfs_create functions USB: fhci-hcd: no need to check return value of debugfs_create functions USB: fotg210-hcd: no need to check return value of debugfs_create functions USB: imx21-hcd: no need to check return value of debugfs_create functions ...
Diffstat (limited to 'tools')
-rwxr-xr-xtools/testing/selftests/drivers/usb/usbip/usbip_test.sh198
-rw-r--r--tools/usb/usbip/libsrc/vhci_driver.c32
-rw-r--r--tools/usb/usbip/libsrc/vhci_driver.h3
-rw-r--r--tools/usb/usbip/src/usbip_detach.c46
4 files changed, 253 insertions, 26 deletions
diff --git a/tools/testing/selftests/drivers/usb/usbip/usbip_test.sh b/tools/testing/selftests/drivers/usb/usbip/usbip_test.sh
new file mode 100755
index 000000000000..1893d0f59ad7
--- /dev/null
+++ b/tools/testing/selftests/drivers/usb/usbip/usbip_test.sh
@@ -0,0 +1,198 @@
1#!/bin/bash
2# SPDX-License-Identifier: GPL-2.0
3
4# Kselftest framework requirement - SKIP code is 4.
5ksft_skip=4
6
7usage() { echo "usbip_test.sh -b <busid> -p <usbip tools path>"; exit 1; }
8
9while getopts "h:b:p:" arg; do
10 case "${arg}" in
11 h)
12 usage
13 ;;
14 b)
15 busid=${OPTARG}
16 ;;
17 p)
18 tools_path=${OPTARG}
19 ;;
20 *)
21 usage
22 ;;
23 esac
24done
25shift $((OPTIND-1))
26
27if [ -z "${busid}" ]; then
28 usage
29fi
30
31echo "Running USB over IP Testing on $busid";
32
33test_end_msg="End of USB over IP Testing on $busid"
34
35if [ $UID != 0 ]; then
36 echo "Please run usbip_test as root [SKIP]"
37 echo $test_end_msg
38 exit $ksft_skip
39fi
40
41echo "Load usbip_host module"
42if ! /sbin/modprobe -q -n usbip_host; then
43 echo "usbip_test: module usbip_host is not found [SKIP]"
44 echo $test_end_msg
45 exit $ksft_skip
46fi
47
48if /sbin/modprobe -q usbip_host; then
49 /sbin/modprobe -q -r test_bitmap
50 echo "usbip_test: module usbip_host is loaded [OK]"
51else
52 echo "usbip_test: module usbip_host failed to load [FAIL]"
53 echo $test_end_msg
54 exit 1
55fi
56
57echo "Load vhci_hcd module"
58if /sbin/modprobe -q vhci_hcd; then
59 /sbin/modprobe -q -r test_bitmap
60 echo "usbip_test: module vhci_hcd is loaded [OK]"
61else
62 echo "usbip_test: module vhci_hcd failed to load [FAIL]"
63 echo $test_end_msg
64 exit 1
65fi
66echo "=============================================================="
67
68cd $tools_path;
69
70if [ ! -f src/usbip ]; then
71 echo "Please build usbip tools"
72 echo $test_end_msg
73 exit $ksft_skip
74fi
75
76echo "Expect to see export-able devices";
77src/usbip list -l;
78echo "=============================================================="
79
80echo "Run lsusb to see all usb devices"
81lsusb -t;
82echo "=============================================================="
83
84src/usbipd -D;
85
86echo "Get exported devices from localhost - expect to see none";
87src/usbip list -r localhost;
88echo "=============================================================="
89
90echo "bind devices";
91src/usbip bind -b $busid;
92echo "=============================================================="
93
94echo "Run lsusb - bound devices should be under usbip_host control"
95lsusb -t;
96echo "=============================================================="
97
98echo "bind devices - expect already bound messages"
99src/usbip bind -b $busid;
100echo "=============================================================="
101
102echo "Get exported devices from localhost - expect to see exported devices";
103src/usbip list -r localhost;
104echo "=============================================================="
105
106echo "unbind devices";
107src/usbip unbind -b $busid;
108echo "=============================================================="
109
110echo "Run lsusb - bound devices should be rebound to original drivers"
111lsusb -t;
112echo "=============================================================="
113
114echo "unbind devices - expect no devices bound message";
115src/usbip unbind -b $busid;
116echo "=============================================================="
117
118echo "Get exported devices from localhost - expect to see none";
119src/usbip list -r localhost;
120echo "=============================================================="
121
122echo "List imported devices - expect to see none";
123src/usbip port;
124echo "=============================================================="
125
126echo "Import devices from localhost - should fail with no devices"
127src/usbip attach -r localhost -b $busid;
128echo "=============================================================="
129
130echo "bind devices";
131src/usbip bind -b $busid;
132echo "=============================================================="
133
134echo "List imported devices - expect to see exported devices";
135src/usbip list -r localhost;
136echo "=============================================================="
137
138echo "List imported devices - expect to see none";
139src/usbip port;
140echo "=============================================================="
141
142echo "Import devices from localhost - should work"
143src/usbip attach -r localhost -b $busid;
144echo "=============================================================="
145
146echo "List imported devices - expect to see imported devices";
147src/usbip port;
148echo "=============================================================="
149
150echo "Import devices from localhost - expect already imported messages"
151src/usbip attach -r localhost -b $busid;
152echo "=============================================================="
153
154echo "Un-import devices";
155src/usbip detach -p 00;
156src/usbip detach -p 01;
157echo "=============================================================="
158
159echo "List imported devices - expect to see none";
160src/usbip port;
161echo "=============================================================="
162
163echo "Un-import devices - expect no devices to detach messages";
164src/usbip detach -p 00;
165src/usbip detach -p 01;
166echo "=============================================================="
167
168echo "Detach invalid port tests - expect invalid port error message";
169src/usbip detach -p 100;
170echo "=============================================================="
171
172echo "Expect to see export-able devices";
173src/usbip list -l;
174echo "=============================================================="
175
176echo "Remove usbip_host module";
177rmmod usbip_host;
178
179echo "Run lsusb - bound devices should be rebound to original drivers"
180lsusb -t;
181echo "=============================================================="
182
183echo "Run bind without usbip_host - expect fail"
184src/usbip bind -b $busid;
185echo "=============================================================="
186
187echo "Run lsusb - devices that failed to bind aren't bound to any driver"
188lsusb -t;
189echo "=============================================================="
190
191echo "modprobe usbip_host - does it work?"
192/sbin/modprobe usbip_host
193echo "Should see -busid- is not in match_busid table... skip! dmesg"
194echo "=============================================================="
195dmesg | grep "is not in match_busid table"
196echo "=============================================================="
197
198echo $test_end_msg
diff --git a/tools/usb/usbip/libsrc/vhci_driver.c b/tools/usb/usbip/libsrc/vhci_driver.c
index c9c81614a66a..4204359c9fee 100644
--- a/tools/usb/usbip/libsrc/vhci_driver.c
+++ b/tools/usb/usbip/libsrc/vhci_driver.c
@@ -135,11 +135,11 @@ static int refresh_imported_device_list(void)
135 return 0; 135 return 0;
136} 136}
137 137
138static int get_nports(void) 138static int get_nports(struct udev_device *hc_device)
139{ 139{
140 const char *attr_nports; 140 const char *attr_nports;
141 141
142 attr_nports = udev_device_get_sysattr_value(vhci_driver->hc_device, "nports"); 142 attr_nports = udev_device_get_sysattr_value(hc_device, "nports");
143 if (!attr_nports) { 143 if (!attr_nports) {
144 err("udev_device_get_sysattr_value nports failed"); 144 err("udev_device_get_sysattr_value nports failed");
145 return -1; 145 return -1;
@@ -242,35 +242,41 @@ static int read_record(int rhport, char *host, unsigned long host_len,
242 242
243int usbip_vhci_driver_open(void) 243int usbip_vhci_driver_open(void)
244{ 244{
245 int nports;
246 struct udev_device *hc_device;
247
245 udev_context = udev_new(); 248 udev_context = udev_new();
246 if (!udev_context) { 249 if (!udev_context) {
247 err("udev_new failed"); 250 err("udev_new failed");
248 return -1; 251 return -1;
249 } 252 }
250 253
251 vhci_driver = calloc(1, sizeof(struct usbip_vhci_driver));
252
253 /* will be freed in usbip_driver_close() */ 254 /* will be freed in usbip_driver_close() */
254 vhci_driver->hc_device = 255 hc_device =
255 udev_device_new_from_subsystem_sysname(udev_context, 256 udev_device_new_from_subsystem_sysname(udev_context,
256 USBIP_VHCI_BUS_TYPE, 257 USBIP_VHCI_BUS_TYPE,
257 USBIP_VHCI_DEVICE_NAME); 258 USBIP_VHCI_DEVICE_NAME);
258 if (!vhci_driver->hc_device) { 259 if (!hc_device) {
259 err("udev_device_new_from_subsystem_sysname failed"); 260 err("udev_device_new_from_subsystem_sysname failed");
260 goto err; 261 goto err;
261 } 262 }
262 263
263 vhci_driver->nports = get_nports(); 264 nports = get_nports(hc_device);
264 dbg("available ports: %d", vhci_driver->nports); 265 if (nports <= 0) {
265
266 if (vhci_driver->nports <= 0) {
267 err("no available ports"); 266 err("no available ports");
268 goto err; 267 goto err;
269 } else if (vhci_driver->nports > MAXNPORT) { 268 }
270 err("port number exceeds %d", MAXNPORT); 269 dbg("available ports: %d", nports);
270
271 vhci_driver = calloc(1, sizeof(struct usbip_vhci_driver) +
272 nports * sizeof(struct usbip_imported_device));
273 if (!vhci_driver) {
274 err("vhci_driver allocation failed");
271 goto err; 275 goto err;
272 } 276 }
273 277
278 vhci_driver->nports = nports;
279 vhci_driver->hc_device = hc_device;
274 vhci_driver->ncontrollers = get_ncontrollers(); 280 vhci_driver->ncontrollers = get_ncontrollers();
275 dbg("available controllers: %d", vhci_driver->ncontrollers); 281 dbg("available controllers: %d", vhci_driver->ncontrollers);
276 282
@@ -285,7 +291,7 @@ int usbip_vhci_driver_open(void)
285 return 0; 291 return 0;
286 292
287err: 293err:
288 udev_device_unref(vhci_driver->hc_device); 294 udev_device_unref(hc_device);
289 295
290 if (vhci_driver) 296 if (vhci_driver)
291 free(vhci_driver); 297 free(vhci_driver);
diff --git a/tools/usb/usbip/libsrc/vhci_driver.h b/tools/usb/usbip/libsrc/vhci_driver.h
index 418b404d5121..6c9aca216705 100644
--- a/tools/usb/usbip/libsrc/vhci_driver.h
+++ b/tools/usb/usbip/libsrc/vhci_driver.h
@@ -13,7 +13,6 @@
13 13
14#define USBIP_VHCI_BUS_TYPE "platform" 14#define USBIP_VHCI_BUS_TYPE "platform"
15#define USBIP_VHCI_DEVICE_NAME "vhci_hcd.0" 15#define USBIP_VHCI_DEVICE_NAME "vhci_hcd.0"
16#define MAXNPORT 128
17 16
18enum hub_speed { 17enum hub_speed {
19 HUB_SPEED_HIGH = 0, 18 HUB_SPEED_HIGH = 0,
@@ -41,7 +40,7 @@ struct usbip_vhci_driver {
41 40
42 int ncontrollers; 41 int ncontrollers;
43 int nports; 42 int nports;
44 struct usbip_imported_device idev[MAXNPORT]; 43 struct usbip_imported_device idev[];
45}; 44};
46 45
47 46
diff --git a/tools/usb/usbip/src/usbip_detach.c b/tools/usb/usbip/src/usbip_detach.c
index 9db9d21bb2ec..777f7286a0c5 100644
--- a/tools/usb/usbip/src/usbip_detach.c
+++ b/tools/usb/usbip/src/usbip_detach.c
@@ -43,9 +43,12 @@ void usbip_detach_usage(void)
43 43
44static int detach_port(char *port) 44static int detach_port(char *port)
45{ 45{
46 int ret; 46 int ret = 0;
47 uint8_t portnum; 47 uint8_t portnum;
48 char path[PATH_MAX+1]; 48 char path[PATH_MAX+1];
49 int i;
50 struct usbip_imported_device *idev;
51 int found = 0;
49 52
50 unsigned int port_len = strlen(port); 53 unsigned int port_len = strlen(port);
51 54
@@ -55,27 +58,48 @@ static int detach_port(char *port)
55 return -1; 58 return -1;
56 } 59 }
57 60
58 /* check max port */
59
60 portnum = atoi(port); 61 portnum = atoi(port);
61 62
62 /* remove the port state file */ 63 ret = usbip_vhci_driver_open();
64 if (ret < 0) {
65 err("open vhci_driver");
66 return -1;
67 }
68
69 /* check for invalid port */
70 for (i = 0; i < vhci_driver->nports; i++) {
71 idev = &vhci_driver->idev[i];
72
73 if (idev->port == portnum) {
74 found = 1;
75 if (idev->status != VDEV_ST_NULL)
76 break;
77 info("Port %d is already detached!\n", idev->port);
78 goto call_driver_close;
79 }
80 }
63 81
82 if (!found) {
83 err("Invalid port %s > maxports %d",
84 port, vhci_driver->nports);
85 goto call_driver_close;
86 }
87
88 /* remove the port state file */
64 snprintf(path, PATH_MAX, VHCI_STATE_PATH"/port%d", portnum); 89 snprintf(path, PATH_MAX, VHCI_STATE_PATH"/port%d", portnum);
65 90
66 remove(path); 91 remove(path);
67 rmdir(VHCI_STATE_PATH); 92 rmdir(VHCI_STATE_PATH);
68 93
69 ret = usbip_vhci_driver_open(); 94 ret = usbip_vhci_detach_device(portnum);
70 if (ret < 0) { 95 if (ret < 0) {
71 err("open vhci_driver"); 96 ret = -1;
72 return -1; 97 err("Port %d detach request failed!\n", portnum);
98 goto call_driver_close;
73 } 99 }
100 info("Port %d is now detached!\n", portnum);
74 101
75 ret = usbip_vhci_detach_device(portnum); 102call_driver_close:
76 if (ret < 0)
77 return -1;
78
79 usbip_vhci_driver_close(); 103 usbip_vhci_driver_close();
80 104
81 return ret; 105 return ret;