Deleted Added
full compact
usb_request.c (217265) usb_request.c (222786)
1/* $FreeBSD: head/sys/dev/usb/usb_request.c 217265 2011-01-11 13:59:06Z jhb $ */
1/* $FreeBSD: head/sys/dev/usb/usb_request.c 222786 2011-06-06 21:45:09Z hselasky $ */
2/*-
3 * Copyright (c) 1998 The NetBSD Foundation, Inc. All rights reserved.
4 * Copyright (c) 1998 Lennart Augustsson. All rights reserved.
5 * Copyright (c) 2008 Hans Petter Selasky. All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:

--- 223 unchanged lines hidden (view full) ---

233
234 ep = udev->ep_curr;
235 ep_end = udev->endpoints + udev->endpoints_max;
236 ep_first = udev->endpoints;
237 to = udev->endpoints_max;
238
239 switch (USB_GET_STATE(xfer)) {
240 case USB_ST_TRANSFERRED:
2/*-
3 * Copyright (c) 1998 The NetBSD Foundation, Inc. All rights reserved.
4 * Copyright (c) 1998 Lennart Augustsson. All rights reserved.
5 * Copyright (c) 2008 Hans Petter Selasky. All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:

--- 223 unchanged lines hidden (view full) ---

233
234 ep = udev->ep_curr;
235 ep_end = udev->endpoints + udev->endpoints_max;
236 ep_first = udev->endpoints;
237 to = udev->endpoints_max;
238
239 switch (USB_GET_STATE(xfer)) {
240 case USB_ST_TRANSFERRED:
241
242 /* reset error counter */
243 udev->clear_stall_errors = 0;
244
241 if (ep == NULL)
242 goto tr_setup; /* device was unconfigured */
243 if (ep->edesc &&
244 ep->is_stalled) {
245 ep->toggle_next = 0;
246 ep->is_stalled = 0;
247 /* some hardware needs a callback to clear the data toggle */
248 usbd_clear_stall_locked(udev, ep);

--- 35 unchanged lines hidden (view full) ---

284 USB_BUS_LOCK(udev->bus);
285 break;
286 }
287 ep++;
288 to--;
289 goto tr_setup;
290
291 default:
245 if (ep == NULL)
246 goto tr_setup; /* device was unconfigured */
247 if (ep->edesc &&
248 ep->is_stalled) {
249 ep->toggle_next = 0;
250 ep->is_stalled = 0;
251 /* some hardware needs a callback to clear the data toggle */
252 usbd_clear_stall_locked(udev, ep);

--- 35 unchanged lines hidden (view full) ---

288 USB_BUS_LOCK(udev->bus);
289 break;
290 }
291 ep++;
292 to--;
293 goto tr_setup;
294
295 default:
292 if (xfer->error == USB_ERR_CANCELLED) {
296 if (error == USB_ERR_CANCELLED)
293 break;
297 break;
298
299 DPRINTF("Clear stall failed.\n");
300 if (udev->clear_stall_errors == USB_CS_RESET_LIMIT)
301 goto tr_setup;
302
303 if (error == USB_ERR_TIMEOUT) {
304 udev->clear_stall_errors = USB_CS_RESET_LIMIT;
305 DPRINTF("Trying to re-enumerate.\n");
306 usbd_start_re_enumerate(udev);
307 } else {
308 udev->clear_stall_errors++;
309 if (udev->clear_stall_errors == USB_CS_RESET_LIMIT) {
310 DPRINTF("Trying to re-enumerate.\n");
311 usbd_start_re_enumerate(udev);
312 }
294 }
295 goto tr_setup;
296 }
297
298 /* store current endpoint */
299 udev->ep_curr = ep;
300 USB_BUS_UNLOCK(udev->bus);
301}

--- 1629 unchanged lines hidden (view full) ---

1931 return (USB_ERR_INVAL);
1932 }
1933 old_addr = udev->address;
1934 parent_hub = udev->parent_hub;
1935 if (parent_hub == NULL) {
1936 return (USB_ERR_INVAL);
1937 }
1938retry:
313 }
314 goto tr_setup;
315 }
316
317 /* store current endpoint */
318 udev->ep_curr = ep;
319 USB_BUS_UNLOCK(udev->bus);
320}

--- 1629 unchanged lines hidden (view full) ---

1950 return (USB_ERR_INVAL);
1951 }
1952 old_addr = udev->address;
1953 parent_hub = udev->parent_hub;
1954 if (parent_hub == NULL) {
1955 return (USB_ERR_INVAL);
1956 }
1957retry:
1958 /*
1959 * Try to reset the High Speed parent HUB of a LOW- or FULL-
1960 * speed device, if any.
1961 */
1962 if (udev->parent_hs_hub != NULL &&
1963 udev->speed != USB_SPEED_HIGH) {
1964 DPRINTF("Trying to reset parent High Speed TT.\n");
1965 err = usbd_req_reset_tt(udev->parent_hs_hub, NULL,
1966 udev->hs_port_no);
1967 if (err) {
1968 DPRINTF("Resetting parent High "
1969 "Speed TT failed (%s).\n",
1970 usbd_errstr(err));
1971 }
1972 }
1973
1974 /* Try to reset the parent HUB port. */
1939 err = usbd_req_reset_port(parent_hub, mtx, udev->port_no);
1940 if (err) {
1941 DPRINTFN(0, "addr=%d, port reset failed, %s\n",
1942 old_addr, usbd_errstr(err));
1943 goto done;
1944 }
1945
1946 /*

--- 81 unchanged lines hidden (view full) ---

2028
2029 req.bmRequestType = UT_WRITE_DEVICE;
2030 req.bRequest = UR_SET_FEATURE;
2031 USETW(req.wValue, sel);
2032 USETW(req.wIndex, 0);
2033 USETW(req.wLength, 0);
2034 return (usbd_do_request(udev, mtx, &req, 0));
2035}
1975 err = usbd_req_reset_port(parent_hub, mtx, udev->port_no);
1976 if (err) {
1977 DPRINTFN(0, "addr=%d, port reset failed, %s\n",
1978 old_addr, usbd_errstr(err));
1979 goto done;
1980 }
1981
1982 /*

--- 81 unchanged lines hidden (view full) ---

2064
2065 req.bmRequestType = UT_WRITE_DEVICE;
2066 req.bRequest = UR_SET_FEATURE;
2067 USETW(req.wValue, sel);
2068 USETW(req.wIndex, 0);
2069 USETW(req.wLength, 0);
2070 return (usbd_do_request(udev, mtx, &req, 0));
2071}
2072
2073/*------------------------------------------------------------------------*
2074 * usbd_req_reset_tt
2075 *
2076 * Returns:
2077 * 0: Success
2078 * Else: Failure
2079 *------------------------------------------------------------------------*/
2080usb_error_t
2081usbd_req_reset_tt(struct usb_device *udev, struct mtx *mtx,
2082 uint8_t port)
2083{
2084 struct usb_device_request req;
2085
2086 /* For single TT HUBs the port should be 1 */
2087
2088 if (udev->ddesc.bDeviceClass == UDCLASS_HUB &&
2089 udev->ddesc.bDeviceProtocol == UDPROTO_HSHUBSTT)
2090 port = 1;
2091
2092 req.bmRequestType = UT_WRITE_CLASS_OTHER;
2093 req.bRequest = UR_RESET_TT;
2094 USETW(req.wValue, 0);
2095 req.wIndex[0] = port;
2096 req.wIndex[1] = 0;
2097 USETW(req.wLength, 0);
2098 return (usbd_do_request(udev, mtx, &req, 0));
2099}
2100
2101/*------------------------------------------------------------------------*
2102 * usbd_req_clear_tt_buffer
2103 *
2104 * For single TT HUBs the port should be 1.
2105 *
2106 * Returns:
2107 * 0: Success
2108 * Else: Failure
2109 *------------------------------------------------------------------------*/
2110usb_error_t
2111usbd_req_clear_tt_buffer(struct usb_device *udev, struct mtx *mtx,
2112 uint8_t port, uint8_t addr, uint8_t type, uint8_t endpoint)
2113{
2114 struct usb_device_request req;
2115 uint16_t wValue;
2116
2117 /* For single TT HUBs the port should be 1 */
2118
2119 if (udev->ddesc.bDeviceClass == UDCLASS_HUB &&
2120 udev->ddesc.bDeviceProtocol == UDPROTO_HSHUBSTT)
2121 port = 1;
2122
2123 wValue = (endpoint & 0xF) | ((addr & 0x7F) << 4) |
2124 ((endpoint & 0x80) << 8) | ((type & 3) << 12);
2125
2126 req.bmRequestType = UT_WRITE_CLASS_OTHER;
2127 req.bRequest = UR_CLEAR_TT_BUFFER;
2128 USETW(req.wValue, wValue);
2129 req.wIndex[0] = port;
2130 req.wIndex[1] = 0;
2131 USETW(req.wLength, 0);
2132 return (usbd_do_request(udev, mtx, &req, 0));
2133}