vhci_hcd.c 30 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288
  1. /*
  2. * Copyright (C) 2003-2008 Takahiro Hirofuchi
  3. * Copyright (C) 2015-2016 Nobuo Iwata
  4. *
  5. * This is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, write to the Free Software
  17. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
  18. * USA.
  19. */
  20. #include <linux/init.h>
  21. #include <linux/file.h>
  22. #include <linux/kernel.h>
  23. #include <linux/kthread.h>
  24. #include <linux/module.h>
  25. #include <linux/platform_device.h>
  26. #include <linux/slab.h>
  27. #include "usbip_common.h"
  28. #include "vhci.h"
  29. #define DRIVER_AUTHOR "Takahiro Hirofuchi"
  30. #define DRIVER_DESC "USB/IP 'Virtual' Host Controller (VHCI) Driver"
  31. /*
  32. * TODO
  33. * - update root hub emulation
  34. * - move the emulation code to userland ?
  35. * porting to other operating systems
  36. * minimize kernel code
  37. * - add suspend/resume code
  38. * - clean up everything
  39. */
  40. /* See usb gadget dummy hcd */
  41. static int vhci_hub_status(struct usb_hcd *hcd, char *buff);
  42. static int vhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
  43. u16 wIndex, char *buff, u16 wLength);
  44. static int vhci_urb_enqueue(struct usb_hcd *hcd, struct urb *urb,
  45. gfp_t mem_flags);
  46. static int vhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status);
  47. static int vhci_start(struct usb_hcd *vhci_hcd);
  48. static void vhci_stop(struct usb_hcd *hcd);
  49. static int vhci_get_frame_number(struct usb_hcd *hcd);
  50. static const char driver_name[] = "vhci_hcd";
  51. static const char driver_desc[] = "USB/IP Virtual Host Controller";
  52. int vhci_num_controllers = VHCI_NR_HCS;
  53. struct platform_device **vhci_pdevs;
  54. static const char * const bit_desc[] = {
  55. "CONNECTION", /*0*/
  56. "ENABLE", /*1*/
  57. "SUSPEND", /*2*/
  58. "OVER_CURRENT", /*3*/
  59. "RESET", /*4*/
  60. "R5", /*5*/
  61. "R6", /*6*/
  62. "R7", /*7*/
  63. "POWER", /*8*/
  64. "LOWSPEED", /*9*/
  65. "HIGHSPEED", /*10*/
  66. "PORT_TEST", /*11*/
  67. "INDICATOR", /*12*/
  68. "R13", /*13*/
  69. "R14", /*14*/
  70. "R15", /*15*/
  71. "C_CONNECTION", /*16*/
  72. "C_ENABLE", /*17*/
  73. "C_SUSPEND", /*18*/
  74. "C_OVER_CURRENT", /*19*/
  75. "C_RESET", /*20*/
  76. "R21", /*21*/
  77. "R22", /*22*/
  78. "R23", /*23*/
  79. "R24", /*24*/
  80. "R25", /*25*/
  81. "R26", /*26*/
  82. "R27", /*27*/
  83. "R28", /*28*/
  84. "R29", /*29*/
  85. "R30", /*30*/
  86. "R31", /*31*/
  87. };
  88. static void dump_port_status_diff(u32 prev_status, u32 new_status)
  89. {
  90. int i = 0;
  91. u32 bit = 1;
  92. pr_debug("status prev -> new: %08x -> %08x\n", prev_status, new_status);
  93. while (bit) {
  94. u32 prev = prev_status & bit;
  95. u32 new = new_status & bit;
  96. char change;
  97. if (!prev && new)
  98. change = '+';
  99. else if (prev && !new)
  100. change = '-';
  101. else
  102. change = ' ';
  103. if (prev || new)
  104. pr_debug(" %c%s\n", change, bit_desc[i]);
  105. bit <<= 1;
  106. i++;
  107. }
  108. pr_debug("\n");
  109. }
  110. void rh_port_connect(struct vhci_device *vdev, enum usb_device_speed speed)
  111. {
  112. struct vhci_hcd *vhci = vdev_to_vhci(vdev);
  113. int rhport = vdev->rhport;
  114. u32 status;
  115. unsigned long flags;
  116. usbip_dbg_vhci_rh("rh_port_connect %d\n", rhport);
  117. spin_lock_irqsave(&vhci->lock, flags);
  118. status = vhci->port_status[rhport];
  119. status |= USB_PORT_STAT_CONNECTION | (1 << USB_PORT_FEAT_C_CONNECTION);
  120. switch (speed) {
  121. case USB_SPEED_HIGH:
  122. status |= USB_PORT_STAT_HIGH_SPEED;
  123. break;
  124. case USB_SPEED_LOW:
  125. status |= USB_PORT_STAT_LOW_SPEED;
  126. break;
  127. default:
  128. break;
  129. }
  130. vhci->port_status[rhport] = status;
  131. spin_unlock_irqrestore(&vhci->lock, flags);
  132. usb_hcd_poll_rh_status(vhci_to_hcd(vhci));
  133. }
  134. static void rh_port_disconnect(struct vhci_device *vdev)
  135. {
  136. struct vhci_hcd *vhci = vdev_to_vhci(vdev);
  137. int rhport = vdev->rhport;
  138. u32 status;
  139. unsigned long flags;
  140. usbip_dbg_vhci_rh("rh_port_disconnect %d\n", rhport);
  141. spin_lock_irqsave(&vhci->lock, flags);
  142. status = vhci->port_status[rhport];
  143. status &= ~USB_PORT_STAT_CONNECTION;
  144. status |= (1 << USB_PORT_FEAT_C_CONNECTION);
  145. vhci->port_status[rhport] = status;
  146. spin_unlock_irqrestore(&vhci->lock, flags);
  147. usb_hcd_poll_rh_status(vhci_to_hcd(vhci));
  148. }
  149. #define PORT_C_MASK \
  150. ((USB_PORT_STAT_C_CONNECTION \
  151. | USB_PORT_STAT_C_ENABLE \
  152. | USB_PORT_STAT_C_SUSPEND \
  153. | USB_PORT_STAT_C_OVERCURRENT \
  154. | USB_PORT_STAT_C_RESET) << 16)
  155. /*
  156. * Returns 0 if the status hasn't changed, or the number of bytes in buf.
  157. * Ports are 0-indexed from the HCD point of view,
  158. * and 1-indexed from the USB core pointer of view.
  159. *
  160. * @buf: a bitmap to show which port status has been changed.
  161. * bit 0: reserved
  162. * bit 1: the status of port 0 has been changed.
  163. * bit 2: the status of port 1 has been changed.
  164. * ...
  165. */
  166. static int vhci_hub_status(struct usb_hcd *hcd, char *buf)
  167. {
  168. struct vhci_hcd *vhci;
  169. int retval;
  170. int rhport;
  171. int changed = 0;
  172. unsigned long flags;
  173. retval = DIV_ROUND_UP(VHCI_HC_PORTS + 1, 8);
  174. memset(buf, 0, retval);
  175. vhci = hcd_to_vhci(hcd);
  176. spin_lock_irqsave(&vhci->lock, flags);
  177. if (!HCD_HW_ACCESSIBLE(hcd)) {
  178. usbip_dbg_vhci_rh("hw accessible flag not on?\n");
  179. goto done;
  180. }
  181. /* check pseudo status register for each port */
  182. for (rhport = 0; rhport < VHCI_HC_PORTS; rhport++) {
  183. if ((vhci->port_status[rhport] & PORT_C_MASK)) {
  184. /* The status of a port has been changed, */
  185. usbip_dbg_vhci_rh("port %d status changed\n", rhport);
  186. buf[(rhport + 1) / 8] |= 1 << (rhport + 1) % 8;
  187. changed = 1;
  188. }
  189. }
  190. if ((hcd->state == HC_STATE_SUSPENDED) && (changed == 1))
  191. usb_hcd_resume_root_hub(hcd);
  192. done:
  193. spin_unlock_irqrestore(&vhci->lock, flags);
  194. return changed ? retval : 0;
  195. }
  196. static inline void hub_descriptor(struct usb_hub_descriptor *desc)
  197. {
  198. int width;
  199. memset(desc, 0, sizeof(*desc));
  200. desc->bDescriptorType = USB_DT_HUB;
  201. desc->wHubCharacteristics = cpu_to_le16(
  202. HUB_CHAR_INDV_PORT_LPSM | HUB_CHAR_COMMON_OCPM);
  203. desc->bNbrPorts = VHCI_HC_PORTS;
  204. BUILD_BUG_ON(VHCI_HC_PORTS > USB_MAXCHILDREN);
  205. width = desc->bNbrPorts / 8 + 1;
  206. desc->bDescLength = USB_DT_HUB_NONVAR_SIZE + 2 * width;
  207. memset(&desc->u.hs.DeviceRemovable[0], 0, width);
  208. memset(&desc->u.hs.DeviceRemovable[width], 0xff, width);
  209. }
  210. static int vhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
  211. u16 wIndex, char *buf, u16 wLength)
  212. {
  213. struct vhci_hcd *dum;
  214. int retval = 0;
  215. int rhport;
  216. unsigned long flags;
  217. u32 prev_port_status[VHCI_HC_PORTS];
  218. if (!HCD_HW_ACCESSIBLE(hcd))
  219. return -ETIMEDOUT;
  220. /*
  221. * NOTE:
  222. * wIndex shows the port number and begins from 1.
  223. */
  224. usbip_dbg_vhci_rh("typeReq %x wValue %x wIndex %x\n", typeReq, wValue,
  225. wIndex);
  226. if (wIndex > VHCI_HC_PORTS)
  227. pr_err("invalid port number %d\n", wIndex);
  228. rhport = ((__u8)(wIndex & 0x00ff)) - 1;
  229. dum = hcd_to_vhci(hcd);
  230. spin_lock_irqsave(&dum->lock, flags);
  231. /* store old status and compare now and old later */
  232. if (usbip_dbg_flag_vhci_rh) {
  233. memcpy(prev_port_status, dum->port_status,
  234. sizeof(prev_port_status));
  235. }
  236. switch (typeReq) {
  237. case ClearHubFeature:
  238. usbip_dbg_vhci_rh(" ClearHubFeature\n");
  239. break;
  240. case ClearPortFeature:
  241. switch (wValue) {
  242. case USB_PORT_FEAT_SUSPEND:
  243. if (dum->port_status[rhport] & USB_PORT_STAT_SUSPEND) {
  244. /* 20msec signaling */
  245. dum->resuming = 1;
  246. dum->re_timeout =
  247. jiffies + msecs_to_jiffies(20);
  248. }
  249. break;
  250. case USB_PORT_FEAT_POWER:
  251. usbip_dbg_vhci_rh(
  252. " ClearPortFeature: USB_PORT_FEAT_POWER\n");
  253. dum->port_status[rhport] = 0;
  254. dum->resuming = 0;
  255. break;
  256. case USB_PORT_FEAT_C_RESET:
  257. usbip_dbg_vhci_rh(
  258. " ClearPortFeature: USB_PORT_FEAT_C_RESET\n");
  259. switch (dum->vdev[rhport].speed) {
  260. case USB_SPEED_HIGH:
  261. dum->port_status[rhport] |=
  262. USB_PORT_STAT_HIGH_SPEED;
  263. break;
  264. case USB_SPEED_LOW:
  265. dum->port_status[rhport] |=
  266. USB_PORT_STAT_LOW_SPEED;
  267. break;
  268. default:
  269. break;
  270. }
  271. default:
  272. usbip_dbg_vhci_rh(" ClearPortFeature: default %x\n",
  273. wValue);
  274. dum->port_status[rhport] &= ~(1 << wValue);
  275. break;
  276. }
  277. break;
  278. case GetHubDescriptor:
  279. usbip_dbg_vhci_rh(" GetHubDescriptor\n");
  280. hub_descriptor((struct usb_hub_descriptor *) buf);
  281. break;
  282. case GetHubStatus:
  283. usbip_dbg_vhci_rh(" GetHubStatus\n");
  284. *(__le32 *) buf = cpu_to_le32(0);
  285. break;
  286. case GetPortStatus:
  287. usbip_dbg_vhci_rh(" GetPortStatus port %x\n", wIndex);
  288. if (wIndex > VHCI_HC_PORTS || wIndex < 1) {
  289. pr_err("invalid port number %d\n", wIndex);
  290. retval = -EPIPE;
  291. }
  292. /* we do not care about resume. */
  293. /* whoever resets or resumes must GetPortStatus to
  294. * complete it!!
  295. */
  296. if (dum->resuming && time_after(jiffies, dum->re_timeout)) {
  297. dum->port_status[rhport] |=
  298. (1 << USB_PORT_FEAT_C_SUSPEND);
  299. dum->port_status[rhport] &=
  300. ~(1 << USB_PORT_FEAT_SUSPEND);
  301. dum->resuming = 0;
  302. dum->re_timeout = 0;
  303. }
  304. if ((dum->port_status[rhport] & (1 << USB_PORT_FEAT_RESET)) !=
  305. 0 && time_after(jiffies, dum->re_timeout)) {
  306. dum->port_status[rhport] |=
  307. (1 << USB_PORT_FEAT_C_RESET);
  308. dum->port_status[rhport] &=
  309. ~(1 << USB_PORT_FEAT_RESET);
  310. dum->re_timeout = 0;
  311. if (dum->vdev[rhport].ud.status ==
  312. VDEV_ST_NOTASSIGNED) {
  313. usbip_dbg_vhci_rh(
  314. " enable rhport %d (status %u)\n",
  315. rhport,
  316. dum->vdev[rhport].ud.status);
  317. dum->port_status[rhport] |=
  318. USB_PORT_STAT_ENABLE;
  319. }
  320. }
  321. ((__le16 *) buf)[0] = cpu_to_le16(dum->port_status[rhport]);
  322. ((__le16 *) buf)[1] =
  323. cpu_to_le16(dum->port_status[rhport] >> 16);
  324. usbip_dbg_vhci_rh(" GetPortStatus bye %x %x\n", ((u16 *)buf)[0],
  325. ((u16 *)buf)[1]);
  326. break;
  327. case SetHubFeature:
  328. usbip_dbg_vhci_rh(" SetHubFeature\n");
  329. retval = -EPIPE;
  330. break;
  331. case SetPortFeature:
  332. switch (wValue) {
  333. case USB_PORT_FEAT_SUSPEND:
  334. usbip_dbg_vhci_rh(
  335. " SetPortFeature: USB_PORT_FEAT_SUSPEND\n");
  336. break;
  337. case USB_PORT_FEAT_RESET:
  338. usbip_dbg_vhci_rh(
  339. " SetPortFeature: USB_PORT_FEAT_RESET\n");
  340. /* if it's already running, disconnect first */
  341. if (dum->port_status[rhport] & USB_PORT_STAT_ENABLE) {
  342. dum->port_status[rhport] &=
  343. ~(USB_PORT_STAT_ENABLE |
  344. USB_PORT_STAT_LOW_SPEED |
  345. USB_PORT_STAT_HIGH_SPEED);
  346. /* FIXME test that code path! */
  347. }
  348. /* 50msec reset signaling */
  349. dum->re_timeout = jiffies + msecs_to_jiffies(50);
  350. /* FALLTHROUGH */
  351. default:
  352. usbip_dbg_vhci_rh(" SetPortFeature: default %d\n",
  353. wValue);
  354. dum->port_status[rhport] |= (1 << wValue);
  355. break;
  356. }
  357. break;
  358. default:
  359. pr_err("default: no such request\n");
  360. /* "protocol stall" on error */
  361. retval = -EPIPE;
  362. }
  363. if (usbip_dbg_flag_vhci_rh) {
  364. pr_debug("port %d\n", rhport);
  365. /* Only dump valid port status */
  366. if (rhport >= 0) {
  367. dump_port_status_diff(prev_port_status[rhport],
  368. dum->port_status[rhport]);
  369. }
  370. }
  371. usbip_dbg_vhci_rh(" bye\n");
  372. spin_unlock_irqrestore(&dum->lock, flags);
  373. return retval;
  374. }
  375. static struct vhci_device *get_vdev(struct usb_device *udev)
  376. {
  377. struct platform_device *pdev;
  378. struct usb_hcd *hcd;
  379. struct vhci_hcd *vhci;
  380. int pdev_nr, rhport;
  381. if (!udev)
  382. return NULL;
  383. for (pdev_nr = 0; pdev_nr < vhci_num_controllers; pdev_nr++) {
  384. pdev = *(vhci_pdevs + pdev_nr);
  385. if (pdev == NULL)
  386. continue;
  387. hcd = platform_get_drvdata(pdev);
  388. if (hcd == NULL)
  389. continue;
  390. vhci = hcd_to_vhci(hcd);
  391. for (rhport = 0; rhport < VHCI_HC_PORTS; rhport++) {
  392. if (vhci->vdev[rhport].udev == udev)
  393. return &vhci->vdev[rhport];
  394. }
  395. }
  396. return NULL;
  397. }
  398. static void vhci_tx_urb(struct urb *urb)
  399. {
  400. struct vhci_device *vdev = get_vdev(urb->dev);
  401. struct vhci_priv *priv;
  402. struct vhci_hcd *vhci = vdev_to_vhci(vdev);
  403. unsigned long flags;
  404. if (!vdev) {
  405. pr_err("could not get virtual device");
  406. return;
  407. }
  408. priv = kzalloc(sizeof(struct vhci_priv), GFP_ATOMIC);
  409. if (!priv) {
  410. usbip_event_add(&vdev->ud, VDEV_EVENT_ERROR_MALLOC);
  411. return;
  412. }
  413. spin_lock_irqsave(&vdev->priv_lock, flags);
  414. priv->seqnum = atomic_inc_return(&vhci->seqnum);
  415. if (priv->seqnum == 0xffff)
  416. dev_info(&urb->dev->dev, "seqnum max\n");
  417. priv->vdev = vdev;
  418. priv->urb = urb;
  419. urb->hcpriv = (void *) priv;
  420. list_add_tail(&priv->list, &vdev->priv_tx);
  421. wake_up(&vdev->waitq_tx);
  422. spin_unlock_irqrestore(&vdev->priv_lock, flags);
  423. }
  424. static int vhci_urb_enqueue(struct usb_hcd *hcd, struct urb *urb,
  425. gfp_t mem_flags)
  426. {
  427. struct vhci_hcd *vhci = hcd_to_vhci(hcd);
  428. struct device *dev = &urb->dev->dev;
  429. u8 portnum = urb->dev->portnum;
  430. int ret = 0;
  431. struct vhci_device *vdev;
  432. unsigned long flags;
  433. usbip_dbg_vhci_hc("enter, usb_hcd %p urb %p mem_flags %d\n",
  434. hcd, urb, mem_flags);
  435. if (portnum > VHCI_HC_PORTS) {
  436. pr_err("invalid port number %d\n", portnum);
  437. return -ENODEV;
  438. }
  439. vdev = &vhci->vdev[portnum-1];
  440. /* patch to usb_sg_init() is in 2.5.60 */
  441. BUG_ON(!urb->transfer_buffer && urb->transfer_buffer_length);
  442. spin_lock_irqsave(&vhci->lock, flags);
  443. if (urb->status != -EINPROGRESS) {
  444. dev_err(dev, "URB already unlinked!, status %d\n", urb->status);
  445. spin_unlock_irqrestore(&vhci->lock, flags);
  446. return urb->status;
  447. }
  448. /* refuse enqueue for dead connection */
  449. spin_lock(&vdev->ud.lock);
  450. if (vdev->ud.status == VDEV_ST_NULL ||
  451. vdev->ud.status == VDEV_ST_ERROR) {
  452. dev_err(dev, "enqueue for inactive port %d\n", vdev->rhport);
  453. spin_unlock(&vdev->ud.lock);
  454. spin_unlock_irqrestore(&vhci->lock, flags);
  455. return -ENODEV;
  456. }
  457. spin_unlock(&vdev->ud.lock);
  458. ret = usb_hcd_link_urb_to_ep(hcd, urb);
  459. if (ret)
  460. goto no_need_unlink;
  461. /*
  462. * The enumeration process is as follows;
  463. *
  464. * 1. Get_Descriptor request to DevAddrs(0) EndPoint(0)
  465. * to get max packet length of default pipe
  466. *
  467. * 2. Set_Address request to DevAddr(0) EndPoint(0)
  468. *
  469. */
  470. if (usb_pipedevice(urb->pipe) == 0) {
  471. __u8 type = usb_pipetype(urb->pipe);
  472. struct usb_ctrlrequest *ctrlreq =
  473. (struct usb_ctrlrequest *) urb->setup_packet;
  474. if (type != PIPE_CONTROL || !ctrlreq) {
  475. dev_err(dev, "invalid request to devnum 0\n");
  476. ret = -EINVAL;
  477. goto no_need_xmit;
  478. }
  479. switch (ctrlreq->bRequest) {
  480. case USB_REQ_SET_ADDRESS:
  481. /* set_address may come when a device is reset */
  482. dev_info(dev, "SetAddress Request (%d) to port %d\n",
  483. ctrlreq->wValue, vdev->rhport);
  484. usb_put_dev(vdev->udev);
  485. vdev->udev = usb_get_dev(urb->dev);
  486. spin_lock(&vdev->ud.lock);
  487. vdev->ud.status = VDEV_ST_USED;
  488. spin_unlock(&vdev->ud.lock);
  489. if (urb->status == -EINPROGRESS) {
  490. /* This request is successfully completed. */
  491. /* If not -EINPROGRESS, possibly unlinked. */
  492. urb->status = 0;
  493. }
  494. goto no_need_xmit;
  495. case USB_REQ_GET_DESCRIPTOR:
  496. if (ctrlreq->wValue == cpu_to_le16(USB_DT_DEVICE << 8))
  497. usbip_dbg_vhci_hc(
  498. "Not yet?:Get_Descriptor to device 0 (get max pipe size)\n");
  499. usb_put_dev(vdev->udev);
  500. vdev->udev = usb_get_dev(urb->dev);
  501. goto out;
  502. default:
  503. /* NOT REACHED */
  504. dev_err(dev,
  505. "invalid request to devnum 0 bRequest %u, wValue %u\n",
  506. ctrlreq->bRequest,
  507. ctrlreq->wValue);
  508. ret = -EINVAL;
  509. goto no_need_xmit;
  510. }
  511. }
  512. out:
  513. vhci_tx_urb(urb);
  514. spin_unlock_irqrestore(&vhci->lock, flags);
  515. return 0;
  516. no_need_xmit:
  517. usb_hcd_unlink_urb_from_ep(hcd, urb);
  518. no_need_unlink:
  519. spin_unlock_irqrestore(&vhci->lock, flags);
  520. if (!ret)
  521. usb_hcd_giveback_urb(hcd, urb, urb->status);
  522. return ret;
  523. }
  524. /*
  525. * vhci_rx gives back the urb after receiving the reply of the urb. If an
  526. * unlink pdu is sent or not, vhci_rx receives a normal return pdu and gives
  527. * back its urb. For the driver unlinking the urb, the content of the urb is
  528. * not important, but the calling to its completion handler is important; the
  529. * completion of unlinking is notified by the completion handler.
  530. *
  531. *
  532. * CLIENT SIDE
  533. *
  534. * - When vhci_hcd receives RET_SUBMIT,
  535. *
  536. * - case 1a). the urb of the pdu is not unlinking.
  537. * - normal case
  538. * => just give back the urb
  539. *
  540. * - case 1b). the urb of the pdu is unlinking.
  541. * - usbip.ko will return a reply of the unlinking request.
  542. * => give back the urb now and go to case 2b).
  543. *
  544. * - When vhci_hcd receives RET_UNLINK,
  545. *
  546. * - case 2a). a submit request is still pending in vhci_hcd.
  547. * - urb was really pending in usbip.ko and urb_unlink_urb() was
  548. * completed there.
  549. * => free a pending submit request
  550. * => notify unlink completeness by giving back the urb
  551. *
  552. * - case 2b). a submit request is *not* pending in vhci_hcd.
  553. * - urb was already given back to the core driver.
  554. * => do not give back the urb
  555. *
  556. *
  557. * SERVER SIDE
  558. *
  559. * - When usbip receives CMD_UNLINK,
  560. *
  561. * - case 3a). the urb of the unlink request is now in submission.
  562. * => do usb_unlink_urb().
  563. * => after the unlink is completed, send RET_UNLINK.
  564. *
  565. * - case 3b). the urb of the unlink request is not in submission.
  566. * - may be already completed or never be received
  567. * => send RET_UNLINK
  568. *
  569. */
  570. static int vhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
  571. {
  572. struct vhci_hcd *vhci = hcd_to_vhci(hcd);
  573. struct vhci_priv *priv;
  574. struct vhci_device *vdev;
  575. unsigned long flags;
  576. pr_info("dequeue a urb %p\n", urb);
  577. spin_lock_irqsave(&vhci->lock, flags);
  578. priv = urb->hcpriv;
  579. if (!priv) {
  580. /* URB was never linked! or will be soon given back by
  581. * vhci_rx. */
  582. spin_unlock_irqrestore(&vhci->lock, flags);
  583. return -EIDRM;
  584. }
  585. {
  586. int ret = 0;
  587. ret = usb_hcd_check_unlink_urb(hcd, urb, status);
  588. if (ret) {
  589. spin_unlock_irqrestore(&vhci->lock, flags);
  590. return ret;
  591. }
  592. }
  593. /* send unlink request here? */
  594. vdev = priv->vdev;
  595. if (!vdev->ud.tcp_socket) {
  596. /* tcp connection is closed */
  597. spin_lock(&vdev->priv_lock);
  598. pr_info("device %p seems to be disconnected\n", vdev);
  599. list_del(&priv->list);
  600. kfree(priv);
  601. urb->hcpriv = NULL;
  602. spin_unlock(&vdev->priv_lock);
  603. /*
  604. * If tcp connection is alive, we have sent CMD_UNLINK.
  605. * vhci_rx will receive RET_UNLINK and give back the URB.
  606. * Otherwise, we give back it here.
  607. */
  608. pr_info("gives back urb %p\n", urb);
  609. usb_hcd_unlink_urb_from_ep(hcd, urb);
  610. spin_unlock_irqrestore(&vhci->lock, flags);
  611. usb_hcd_giveback_urb(vhci_to_hcd(vhci), urb, urb->status);
  612. spin_lock_irqsave(&vhci->lock, flags);
  613. } else {
  614. /* tcp connection is alive */
  615. struct vhci_unlink *unlink;
  616. spin_lock(&vdev->priv_lock);
  617. /* setup CMD_UNLINK pdu */
  618. unlink = kzalloc(sizeof(struct vhci_unlink), GFP_ATOMIC);
  619. if (!unlink) {
  620. spin_unlock(&vdev->priv_lock);
  621. spin_unlock_irqrestore(&vhci->lock, flags);
  622. usbip_event_add(&vdev->ud, VDEV_EVENT_ERROR_MALLOC);
  623. return -ENOMEM;
  624. }
  625. unlink->seqnum = atomic_inc_return(&vhci->seqnum);
  626. if (unlink->seqnum == 0xffff)
  627. pr_info("seqnum max\n");
  628. unlink->unlink_seqnum = priv->seqnum;
  629. pr_info("device %p seems to be still connected\n", vdev);
  630. /* send cmd_unlink and try to cancel the pending URB in the
  631. * peer */
  632. list_add_tail(&unlink->list, &vdev->unlink_tx);
  633. wake_up(&vdev->waitq_tx);
  634. spin_unlock(&vdev->priv_lock);
  635. }
  636. spin_unlock_irqrestore(&vhci->lock, flags);
  637. usbip_dbg_vhci_hc("leave\n");
  638. return 0;
  639. }
  640. static void vhci_device_unlink_cleanup(struct vhci_device *vdev)
  641. {
  642. struct vhci_hcd *vhci = vdev_to_vhci(vdev);
  643. struct usb_hcd *hcd = vhci_to_hcd(vhci);
  644. struct vhci_unlink *unlink, *tmp;
  645. unsigned long flags;
  646. spin_lock_irqsave(&vhci->lock, flags);
  647. spin_lock(&vdev->priv_lock);
  648. list_for_each_entry_safe(unlink, tmp, &vdev->unlink_tx, list) {
  649. pr_info("unlink cleanup tx %lu\n", unlink->unlink_seqnum);
  650. list_del(&unlink->list);
  651. kfree(unlink);
  652. }
  653. while (!list_empty(&vdev->unlink_rx)) {
  654. struct urb *urb;
  655. unlink = list_first_entry(&vdev->unlink_rx, struct vhci_unlink,
  656. list);
  657. /* give back URB of unanswered unlink request */
  658. pr_info("unlink cleanup rx %lu\n", unlink->unlink_seqnum);
  659. urb = pickup_urb_and_free_priv(vdev, unlink->unlink_seqnum);
  660. if (!urb) {
  661. pr_info("the urb (seqnum %lu) was already given back\n",
  662. unlink->unlink_seqnum);
  663. list_del(&unlink->list);
  664. kfree(unlink);
  665. continue;
  666. }
  667. urb->status = -ENODEV;
  668. usb_hcd_unlink_urb_from_ep(hcd, urb);
  669. list_del(&unlink->list);
  670. spin_unlock(&vdev->priv_lock);
  671. spin_unlock_irqrestore(&vhci->lock, flags);
  672. usb_hcd_giveback_urb(hcd, urb, urb->status);
  673. spin_lock_irqsave(&vhci->lock, flags);
  674. spin_lock(&vdev->priv_lock);
  675. kfree(unlink);
  676. }
  677. spin_unlock(&vdev->priv_lock);
  678. spin_unlock_irqrestore(&vhci->lock, flags);
  679. }
  680. /*
  681. * The important thing is that only one context begins cleanup.
  682. * This is why error handling and cleanup become simple.
  683. * We do not want to consider race condition as possible.
  684. */
  685. static void vhci_shutdown_connection(struct usbip_device *ud)
  686. {
  687. struct vhci_device *vdev = container_of(ud, struct vhci_device, ud);
  688. /* need this? see stub_dev.c */
  689. if (ud->tcp_socket) {
  690. pr_debug("shutdown tcp_socket %p\n", ud->tcp_socket);
  691. kernel_sock_shutdown(ud->tcp_socket, SHUT_RDWR);
  692. }
  693. /* kill threads related to this sdev */
  694. if (vdev->ud.tcp_rx) {
  695. kthread_stop_put(vdev->ud.tcp_rx);
  696. vdev->ud.tcp_rx = NULL;
  697. }
  698. if (vdev->ud.tcp_tx) {
  699. kthread_stop_put(vdev->ud.tcp_tx);
  700. vdev->ud.tcp_tx = NULL;
  701. }
  702. pr_info("stop threads\n");
  703. /* active connection is closed */
  704. if (vdev->ud.tcp_socket) {
  705. sockfd_put(vdev->ud.tcp_socket);
  706. vdev->ud.tcp_socket = NULL;
  707. }
  708. pr_info("release socket\n");
  709. vhci_device_unlink_cleanup(vdev);
  710. /*
  711. * rh_port_disconnect() is a trigger of ...
  712. * usb_disable_device():
  713. * disable all the endpoints for a USB device.
  714. * usb_disable_endpoint():
  715. * disable endpoints. pending urbs are unlinked(dequeued).
  716. *
  717. * NOTE: After calling rh_port_disconnect(), the USB device drivers of a
  718. * detached device should release used urbs in a cleanup function (i.e.
  719. * xxx_disconnect()). Therefore, vhci_hcd does not need to release
  720. * pushed urbs and their private data in this function.
  721. *
  722. * NOTE: vhci_dequeue() must be considered carefully. When shutting down
  723. * a connection, vhci_shutdown_connection() expects vhci_dequeue()
  724. * gives back pushed urbs and frees their private data by request of
  725. * the cleanup function of a USB driver. When unlinking a urb with an
  726. * active connection, vhci_dequeue() does not give back the urb which
  727. * is actually given back by vhci_rx after receiving its return pdu.
  728. *
  729. */
  730. rh_port_disconnect(vdev);
  731. pr_info("disconnect device\n");
  732. }
  733. static void vhci_device_reset(struct usbip_device *ud)
  734. {
  735. struct vhci_device *vdev = container_of(ud, struct vhci_device, ud);
  736. unsigned long flags;
  737. spin_lock_irqsave(&ud->lock, flags);
  738. vdev->speed = 0;
  739. vdev->devid = 0;
  740. usb_put_dev(vdev->udev);
  741. vdev->udev = NULL;
  742. if (ud->tcp_socket) {
  743. sockfd_put(ud->tcp_socket);
  744. ud->tcp_socket = NULL;
  745. }
  746. ud->status = VDEV_ST_NULL;
  747. spin_unlock_irqrestore(&ud->lock, flags);
  748. }
  749. static void vhci_device_unusable(struct usbip_device *ud)
  750. {
  751. unsigned long flags;
  752. spin_lock_irqsave(&ud->lock, flags);
  753. ud->status = VDEV_ST_ERROR;
  754. spin_unlock_irqrestore(&ud->lock, flags);
  755. }
  756. static void vhci_device_init(struct vhci_device *vdev)
  757. {
  758. memset(vdev, 0, sizeof(struct vhci_device));
  759. vdev->ud.side = USBIP_VHCI;
  760. vdev->ud.status = VDEV_ST_NULL;
  761. spin_lock_init(&vdev->ud.lock);
  762. INIT_LIST_HEAD(&vdev->priv_rx);
  763. INIT_LIST_HEAD(&vdev->priv_tx);
  764. INIT_LIST_HEAD(&vdev->unlink_tx);
  765. INIT_LIST_HEAD(&vdev->unlink_rx);
  766. spin_lock_init(&vdev->priv_lock);
  767. init_waitqueue_head(&vdev->waitq_tx);
  768. vdev->ud.eh_ops.shutdown = vhci_shutdown_connection;
  769. vdev->ud.eh_ops.reset = vhci_device_reset;
  770. vdev->ud.eh_ops.unusable = vhci_device_unusable;
  771. usbip_start_eh(&vdev->ud);
  772. }
  773. static int hcd_name_to_id(const char *name)
  774. {
  775. char *c;
  776. long val;
  777. int ret;
  778. c = strchr(name, '.');
  779. if (c == NULL)
  780. return 0;
  781. ret = kstrtol(c+1, 10, &val);
  782. if (ret < 0)
  783. return ret;
  784. return val;
  785. }
  786. static int vhci_start(struct usb_hcd *hcd)
  787. {
  788. struct vhci_hcd *vhci = hcd_to_vhci(hcd);
  789. int id, rhport;
  790. int err = 0;
  791. usbip_dbg_vhci_hc("enter vhci_start\n");
  792. /* initialize private data of usb_hcd */
  793. for (rhport = 0; rhport < VHCI_HC_PORTS; rhport++) {
  794. struct vhci_device *vdev = &vhci->vdev[rhport];
  795. vhci_device_init(vdev);
  796. vdev->rhport = rhport;
  797. }
  798. atomic_set(&vhci->seqnum, 0);
  799. spin_lock_init(&vhci->lock);
  800. hcd->power_budget = 0; /* no limit */
  801. hcd->uses_new_polling = 1;
  802. id = hcd_name_to_id(hcd_name(hcd));
  803. if (id < 0) {
  804. pr_err("invalid vhci name %s\n", hcd_name(hcd));
  805. return -EINVAL;
  806. }
  807. /* vhci_hcd is now ready to be controlled through sysfs */
  808. if (id == 0) {
  809. err = vhci_init_attr_group();
  810. if (err) {
  811. pr_err("init attr group\n");
  812. return err;
  813. }
  814. err = sysfs_create_group(&hcd_dev(hcd)->kobj, &vhci_attr_group);
  815. if (err) {
  816. pr_err("create sysfs files\n");
  817. vhci_finish_attr_group();
  818. return err;
  819. }
  820. pr_info("created sysfs %s\n", hcd_name(hcd));
  821. }
  822. return 0;
  823. }
  824. static void vhci_stop(struct usb_hcd *hcd)
  825. {
  826. struct vhci_hcd *vhci = hcd_to_vhci(hcd);
  827. int id, rhport;
  828. usbip_dbg_vhci_hc("stop VHCI controller\n");
  829. /* 1. remove the userland interface of vhci_hcd */
  830. id = hcd_name_to_id(hcd_name(hcd));
  831. if (id == 0) {
  832. sysfs_remove_group(&hcd_dev(hcd)->kobj, &vhci_attr_group);
  833. vhci_finish_attr_group();
  834. }
  835. /* 2. shutdown all the ports of vhci_hcd */
  836. for (rhport = 0; rhport < VHCI_HC_PORTS; rhport++) {
  837. struct vhci_device *vdev = &vhci->vdev[rhport];
  838. usbip_event_add(&vdev->ud, VDEV_EVENT_REMOVED);
  839. usbip_stop_eh(&vdev->ud);
  840. }
  841. }
  842. static int vhci_get_frame_number(struct usb_hcd *hcd)
  843. {
  844. dev_err_ratelimited(&hcd->self.root_hub->dev, "Not yet implemented\n");
  845. return 0;
  846. }
  847. #ifdef CONFIG_PM
  848. /* FIXME: suspend/resume */
  849. static int vhci_bus_suspend(struct usb_hcd *hcd)
  850. {
  851. struct vhci_hcd *vhci = hcd_to_vhci(hcd);
  852. unsigned long flags;
  853. dev_dbg(&hcd->self.root_hub->dev, "%s\n", __func__);
  854. spin_lock_irqsave(&vhci->lock, flags);
  855. hcd->state = HC_STATE_SUSPENDED;
  856. spin_unlock_irqrestore(&vhci->lock, flags);
  857. return 0;
  858. }
  859. static int vhci_bus_resume(struct usb_hcd *hcd)
  860. {
  861. struct vhci_hcd *vhci = hcd_to_vhci(hcd);
  862. int rc = 0;
  863. unsigned long flags;
  864. dev_dbg(&hcd->self.root_hub->dev, "%s\n", __func__);
  865. spin_lock_irqsave(&vhci->lock, flags);
  866. if (!HCD_HW_ACCESSIBLE(hcd))
  867. rc = -ESHUTDOWN;
  868. else
  869. hcd->state = HC_STATE_RUNNING;
  870. spin_unlock_irqrestore(&vhci->lock, flags);
  871. return rc;
  872. }
  873. #else
  874. #define vhci_bus_suspend NULL
  875. #define vhci_bus_resume NULL
  876. #endif
  877. static struct hc_driver vhci_hc_driver = {
  878. .description = driver_name,
  879. .product_desc = driver_desc,
  880. .hcd_priv_size = sizeof(struct vhci_hcd),
  881. .flags = HCD_USB2,
  882. .start = vhci_start,
  883. .stop = vhci_stop,
  884. .urb_enqueue = vhci_urb_enqueue,
  885. .urb_dequeue = vhci_urb_dequeue,
  886. .get_frame_number = vhci_get_frame_number,
  887. .hub_status_data = vhci_hub_status,
  888. .hub_control = vhci_hub_control,
  889. .bus_suspend = vhci_bus_suspend,
  890. .bus_resume = vhci_bus_resume,
  891. };
  892. static int vhci_hcd_probe(struct platform_device *pdev)
  893. {
  894. struct usb_hcd *hcd;
  895. int ret;
  896. usbip_dbg_vhci_hc("name %s id %d\n", pdev->name, pdev->id);
  897. /*
  898. * Allocate and initialize hcd.
  899. * Our private data is also allocated automatically.
  900. */
  901. hcd = usb_create_hcd(&vhci_hc_driver, &pdev->dev, dev_name(&pdev->dev));
  902. if (!hcd) {
  903. pr_err("create hcd failed\n");
  904. return -ENOMEM;
  905. }
  906. hcd->has_tt = 1;
  907. /*
  908. * Finish generic HCD structure initialization and register.
  909. * Call the driver's reset() and start() routines.
  910. */
  911. ret = usb_add_hcd(hcd, 0, 0);
  912. if (ret != 0) {
  913. pr_err("usb_add_hcd failed %d\n", ret);
  914. usb_put_hcd(hcd);
  915. return ret;
  916. }
  917. usbip_dbg_vhci_hc("bye\n");
  918. return 0;
  919. }
  920. static int vhci_hcd_remove(struct platform_device *pdev)
  921. {
  922. struct usb_hcd *hcd;
  923. hcd = platform_get_drvdata(pdev);
  924. if (!hcd)
  925. return 0;
  926. /*
  927. * Disconnects the root hub,
  928. * then reverses the effects of usb_add_hcd(),
  929. * invoking the HCD's stop() methods.
  930. */
  931. usb_remove_hcd(hcd);
  932. usb_put_hcd(hcd);
  933. return 0;
  934. }
  935. #ifdef CONFIG_PM
  936. /* what should happen for USB/IP under suspend/resume? */
  937. static int vhci_hcd_suspend(struct platform_device *pdev, pm_message_t state)
  938. {
  939. struct usb_hcd *hcd;
  940. struct vhci_hcd *vhci;
  941. int rhport;
  942. int connected = 0;
  943. int ret = 0;
  944. unsigned long flags;
  945. hcd = platform_get_drvdata(pdev);
  946. if (!hcd)
  947. return 0;
  948. vhci = hcd_to_vhci(hcd);
  949. spin_lock_irqsave(&vhci->lock, flags);
  950. for (rhport = 0; rhport < VHCI_HC_PORTS; rhport++)
  951. if (vhci->port_status[rhport] & USB_PORT_STAT_CONNECTION)
  952. connected += 1;
  953. spin_unlock_irqrestore(&vhci->lock, flags);
  954. if (connected > 0) {
  955. dev_info(&pdev->dev,
  956. "We have %d active connection%s. Do not suspend.\n",
  957. connected, (connected == 1 ? "" : "s"));
  958. ret = -EBUSY;
  959. } else {
  960. dev_info(&pdev->dev, "suspend vhci_hcd");
  961. clear_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags);
  962. }
  963. return ret;
  964. }
  965. static int vhci_hcd_resume(struct platform_device *pdev)
  966. {
  967. struct usb_hcd *hcd;
  968. dev_dbg(&pdev->dev, "%s\n", __func__);
  969. hcd = platform_get_drvdata(pdev);
  970. if (!hcd)
  971. return 0;
  972. set_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags);
  973. usb_hcd_poll_rh_status(hcd);
  974. return 0;
  975. }
  976. #else
  977. #define vhci_hcd_suspend NULL
  978. #define vhci_hcd_resume NULL
  979. #endif
  980. static struct platform_driver vhci_driver = {
  981. .probe = vhci_hcd_probe,
  982. .remove = vhci_hcd_remove,
  983. .suspend = vhci_hcd_suspend,
  984. .resume = vhci_hcd_resume,
  985. .driver = {
  986. .name = driver_name,
  987. },
  988. };
  989. static int add_platform_device(int id)
  990. {
  991. struct platform_device *pdev;
  992. int dev_nr;
  993. if (id == 0)
  994. dev_nr = -1;
  995. else
  996. dev_nr = id;
  997. pdev = platform_device_register_simple(driver_name, dev_nr, NULL, 0);
  998. if (IS_ERR(pdev))
  999. return PTR_ERR(pdev);
  1000. *(vhci_pdevs + id) = pdev;
  1001. return 0;
  1002. }
  1003. static void del_platform_devices(void)
  1004. {
  1005. struct platform_device *pdev;
  1006. int i;
  1007. for (i = 0; i < vhci_num_controllers; i++) {
  1008. pdev = *(vhci_pdevs + i);
  1009. if (pdev != NULL)
  1010. platform_device_unregister(pdev);
  1011. *(vhci_pdevs + i) = NULL;
  1012. }
  1013. sysfs_remove_link(&platform_bus.kobj, driver_name);
  1014. }
  1015. static int __init vhci_hcd_init(void)
  1016. {
  1017. int i, ret;
  1018. if (usb_disabled())
  1019. return -ENODEV;
  1020. if (vhci_num_controllers < 1)
  1021. vhci_num_controllers = 1;
  1022. vhci_pdevs = kcalloc(vhci_num_controllers, sizeof(void *), GFP_KERNEL);
  1023. if (vhci_pdevs == NULL)
  1024. return -ENOMEM;
  1025. ret = platform_driver_register(&vhci_driver);
  1026. if (ret)
  1027. goto err_driver_register;
  1028. for (i = 0; i < vhci_num_controllers; i++) {
  1029. ret = add_platform_device(i);
  1030. if (ret)
  1031. goto err_platform_device_register;
  1032. }
  1033. pr_info(DRIVER_DESC " v" USBIP_VERSION "\n");
  1034. return ret;
  1035. err_platform_device_register:
  1036. del_platform_devices();
  1037. platform_driver_unregister(&vhci_driver);
  1038. err_driver_register:
  1039. kfree(vhci_pdevs);
  1040. return ret;
  1041. }
  1042. static void __exit vhci_hcd_exit(void)
  1043. {
  1044. del_platform_devices();
  1045. platform_driver_unregister(&vhci_driver);
  1046. kfree(vhci_pdevs);
  1047. }
  1048. module_init(vhci_hcd_init);
  1049. module_exit(vhci_hcd_exit);
  1050. MODULE_AUTHOR(DRIVER_AUTHOR);
  1051. MODULE_DESCRIPTION(DRIVER_DESC);
  1052. MODULE_LICENSE("GPL");
  1053. MODULE_VERSION(USBIP_VERSION);