^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0+
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * Copyright (C) 2015 Karol Kosik <karo9@interia.eu>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) * Copyright (C) 2015-2016 Samsung Electronics
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Igor Kotrasinski <i.kotrasinsk@samsung.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * Based on dummy_hcd.c, which is:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) * Copyright (C) 2003 David Brownell
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) * Copyright (C) 2003-2005 Alan Stern
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/usb.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/timer.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <linux/usb/ch9.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include "vudc.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #define DEV_REQUEST (USB_TYPE_STANDARD | USB_RECIP_DEVICE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #define DEV_INREQUEST (DEV_REQUEST | USB_DIR_IN)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #define INTF_REQUEST (USB_TYPE_STANDARD | USB_RECIP_INTERFACE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #define INTF_INREQUEST (INTF_REQUEST | USB_DIR_IN)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #define EP_REQUEST (USB_TYPE_STANDARD | USB_RECIP_ENDPOINT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #define EP_INREQUEST (EP_REQUEST | USB_DIR_IN)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) static int get_frame_limit(enum usb_device_speed speed)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) switch (speed) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) case USB_SPEED_LOW:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) return 8 /*bytes*/ * 12 /*packets*/;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) case USB_SPEED_FULL:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) return 64 /*bytes*/ * 19 /*packets*/;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) case USB_SPEED_HIGH:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) return 512 /*bytes*/ * 13 /*packets*/ * 8 /*uframes*/;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) case USB_SPEED_SUPER:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) /* Bus speed is 500000 bytes/ms, so use a little less */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) return 490000;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) /* error */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) * handle_control_request() - handles all control transfers
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) * @udc: pointer to vudc
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) * @urb: the urb request to handle
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) * @setup: pointer to the setup data for a USB device control
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) * request
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) * @status: pointer to request handling status
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) * Return 0 - if the request was handled
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) * 1 - if the request wasn't handles
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) * error code on error
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) * Adapted from drivers/usb/gadget/udc/dummy_hcd.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) static int handle_control_request(struct vudc *udc, struct urb *urb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) struct usb_ctrlrequest *setup,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) int *status)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) struct vep *ep2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) int ret_val = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) unsigned int w_index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) unsigned int w_value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) w_index = le16_to_cpu(setup->wIndex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) w_value = le16_to_cpu(setup->wValue);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) switch (setup->bRequest) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) case USB_REQ_SET_ADDRESS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) if (setup->bRequestType != DEV_REQUEST)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) udc->address = w_value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) ret_val = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) *status = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) case USB_REQ_SET_FEATURE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) if (setup->bRequestType == DEV_REQUEST) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) ret_val = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) switch (w_value) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) case USB_DEVICE_REMOTE_WAKEUP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) case USB_DEVICE_B_HNP_ENABLE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) udc->gadget.b_hnp_enable = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) case USB_DEVICE_A_HNP_SUPPORT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) udc->gadget.a_hnp_support = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) case USB_DEVICE_A_ALT_HNP_SUPPORT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) udc->gadget.a_alt_hnp_support = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) ret_val = -EOPNOTSUPP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) if (ret_val == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) udc->devstatus |= (1 << w_value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) *status = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) } else if (setup->bRequestType == EP_REQUEST) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) /* endpoint halt */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) ep2 = vudc_find_endpoint(udc, w_index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) if (!ep2 || ep2->ep.name == udc->ep[0].ep.name) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) ret_val = -EOPNOTSUPP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) ep2->halted = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) ret_val = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) *status = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) case USB_REQ_CLEAR_FEATURE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) if (setup->bRequestType == DEV_REQUEST) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) ret_val = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) switch (w_value) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) case USB_DEVICE_REMOTE_WAKEUP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) w_value = USB_DEVICE_REMOTE_WAKEUP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) case USB_DEVICE_U1_ENABLE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) case USB_DEVICE_U2_ENABLE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) case USB_DEVICE_LTM_ENABLE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) ret_val = -EOPNOTSUPP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) ret_val = -EOPNOTSUPP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) if (ret_val == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) udc->devstatus &= ~(1 << w_value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) *status = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) } else if (setup->bRequestType == EP_REQUEST) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) /* endpoint halt */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) ep2 = vudc_find_endpoint(udc, w_index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) if (!ep2) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) ret_val = -EOPNOTSUPP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) if (!ep2->wedged)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) ep2->halted = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) ret_val = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) *status = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) case USB_REQ_GET_STATUS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) if (setup->bRequestType == DEV_INREQUEST
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) || setup->bRequestType == INTF_INREQUEST
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) || setup->bRequestType == EP_INREQUEST) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) char *buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) * device: remote wakeup, selfpowered
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) * interface: nothing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) * endpoint: halt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) buf = (char *)urb->transfer_buffer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) if (urb->transfer_buffer_length > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) if (setup->bRequestType == EP_INREQUEST) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) ep2 = vudc_find_endpoint(udc, w_index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) if (!ep2) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) ret_val = -EOPNOTSUPP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) buf[0] = ep2->halted;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) } else if (setup->bRequestType ==
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) DEV_INREQUEST) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) buf[0] = (u8)udc->devstatus;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) } else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) buf[0] = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) if (urb->transfer_buffer_length > 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) buf[1] = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) urb->actual_length = min_t(u32, 2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) urb->transfer_buffer_length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) ret_val = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) *status = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) return ret_val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) /* Adapted from dummy_hcd.c ; caller must hold lock */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) static int transfer(struct vudc *udc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) struct urb *urb, struct vep *ep, int limit)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) struct vrequest *req;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) int sent = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) top:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) /* if there's no request queued, the device is NAKing; return */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) list_for_each_entry(req, &ep->req_queue, req_entry) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) unsigned int host_len, dev_len, len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) void *ubuf_pos, *rbuf_pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) int is_short, to_host;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) int rescan = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) * 1..N packets of ep->ep.maxpacket each ... the last one
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) * may be short (including zero length).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) * writer can send a zlp explicitly (length 0) or implicitly
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) * (length mod maxpacket zero, and 'zero' flag); they always
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) * terminate reads.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) host_len = urb->transfer_buffer_length - urb->actual_length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) dev_len = req->req.length - req->req.actual;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) len = min(host_len, dev_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) to_host = usb_pipein(urb->pipe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) if (unlikely(len == 0))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) is_short = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) /* send multiple of maxpacket first, then remainder */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) if (len >= ep->ep.maxpacket) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) is_short = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) if (len % ep->ep.maxpacket > 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) rescan = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) len -= len % ep->ep.maxpacket;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) is_short = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) ubuf_pos = urb->transfer_buffer + urb->actual_length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) rbuf_pos = req->req.buf + req->req.actual;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) if (urb->pipe & USB_DIR_IN)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) memcpy(ubuf_pos, rbuf_pos, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) memcpy(rbuf_pos, ubuf_pos, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) urb->actual_length += len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) req->req.actual += len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) sent += len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) * short packets terminate, maybe with overflow/underflow.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) * it's only really an error to write too much.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) * partially filling a buffer optionally blocks queue advances
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) * (so completion handlers can clean up the queue) but we don't
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) * need to emulate such data-in-flight.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) if (is_short) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) if (host_len == dev_len) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) req->req.status = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) urb->status = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) } else if (to_host) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) req->req.status = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) if (dev_len > host_len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) urb->status = -EOVERFLOW;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) urb->status = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) urb->status = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) if (host_len > dev_len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) req->req.status = -EOVERFLOW;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) req->req.status = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) /* many requests terminate without a short packet */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) /* also check if we need to send zlp */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) if (req->req.length == req->req.actual) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) if (req->req.zero && to_host)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) rescan = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) req->req.status = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) if (urb->transfer_buffer_length == urb->actual_length) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) if (urb->transfer_flags & URB_ZERO_PACKET &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) !to_host)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) rescan = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) urb->status = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) /* device side completion --> continuable */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) if (req->req.status != -EINPROGRESS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) list_del_init(&req->req_entry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) spin_unlock(&udc->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) usb_gadget_giveback_request(&ep->ep, &req->req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) spin_lock(&udc->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) /* requests might have been unlinked... */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) rescan = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) /* host side completion --> terminate */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) if (urb->status != -EINPROGRESS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) /* rescan to continue with any other queued i/o */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) if (rescan)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) goto top;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) return sent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) static void v_timer(struct timer_list *t)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) struct vudc *udc = from_timer(udc, t, tr_timer.timer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) struct transfer_timer *timer = &udc->tr_timer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) struct urbp *urb_p, *tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) struct usb_ep *_ep;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) struct vep *ep;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) int total, limit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) spin_lock_irqsave(&udc->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) total = get_frame_limit(udc->gadget.speed);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) if (total < 0) { /* unknown speed, or not set yet */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) timer->state = VUDC_TR_IDLE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) spin_unlock_irqrestore(&udc->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) /* is it next frame now? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) if (time_after(jiffies, timer->frame_start + msecs_to_jiffies(1))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) timer->frame_limit = total;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) /* FIXME: how to make it accurate? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) timer->frame_start = jiffies;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) total = timer->frame_limit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) /* We have to clear ep0 flags separately as it's not on the list */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) udc->ep[0].already_seen = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) list_for_each_entry(_ep, &udc->gadget.ep_list, ep_list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) ep = to_vep(_ep);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) ep->already_seen = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) restart:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) list_for_each_entry_safe(urb_p, tmp, &udc->urb_queue, urb_entry) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) struct urb *urb = urb_p->urb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) ep = urb_p->ep;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) if (urb->unlinked)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) goto return_urb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) if (timer->state != VUDC_TR_RUNNING)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) if (!ep) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) urb->status = -EPROTO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) goto return_urb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) /* Used up bandwidth? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) if (total <= 0 && ep->type == USB_ENDPOINT_XFER_BULK)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) if (ep->already_seen)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) ep->already_seen = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) if (ep == &udc->ep[0] && urb_p->new) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) ep->setup_stage = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) urb_p->new = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) if (ep->halted && !ep->setup_stage) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) urb->status = -EPIPE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) goto return_urb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) if (ep == &udc->ep[0] && ep->setup_stage) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) /* TODO - flush any stale requests */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) ep->setup_stage = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) ep->halted = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) ret = handle_control_request(udc, urb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) (struct usb_ctrlrequest *) urb->setup_packet,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) (&urb->status));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) if (ret > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) spin_unlock(&udc->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) ret = udc->driver->setup(&udc->gadget,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) (struct usb_ctrlrequest *)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) urb->setup_packet);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) spin_lock(&udc->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) if (ret >= 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) /* no delays (max 64kb data stage) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) limit = 64 * 1024;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) goto treat_control_like_bulk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) urb->status = -EPIPE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) urb->actual_length = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) goto return_urb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) limit = total;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) switch (ep->type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) case USB_ENDPOINT_XFER_ISOC:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) /* TODO: support */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) urb->status = -EXDEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) case USB_ENDPOINT_XFER_INT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) * TODO: figure out bandwidth guarantees
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) * for now, give unlimited bandwidth
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) limit += urb->transfer_buffer_length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) fallthrough;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) treat_control_like_bulk:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) total -= transfer(udc, urb, ep, limit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) if (urb->status == -EINPROGRESS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) return_urb:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) if (ep)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) ep->already_seen = ep->setup_stage = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) spin_lock(&udc->lock_tx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) list_del(&urb_p->urb_entry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) if (!urb->unlinked) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) v_enqueue_ret_submit(udc, urb_p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) v_enqueue_ret_unlink(udc, urb_p->seqnum,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) urb->unlinked);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) free_urbp_and_urb(urb_p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) wake_up(&udc->tx_waitq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) spin_unlock(&udc->lock_tx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) goto restart;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) /* TODO - also wait on empty usb_request queues? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) if (list_empty(&udc->urb_queue))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) timer->state = VUDC_TR_IDLE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) mod_timer(&timer->timer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) timer->frame_start + msecs_to_jiffies(1));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) spin_unlock_irqrestore(&udc->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) /* All timer functions are run with udc->lock held */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) void v_init_timer(struct vudc *udc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) struct transfer_timer *t = &udc->tr_timer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) timer_setup(&t->timer, v_timer, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) t->state = VUDC_TR_STOPPED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) void v_start_timer(struct vudc *udc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) struct transfer_timer *t = &udc->tr_timer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) dev_dbg(&udc->pdev->dev, "timer start");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) switch (t->state) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) case VUDC_TR_RUNNING:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) case VUDC_TR_IDLE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) return v_kick_timer(udc, jiffies);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) case VUDC_TR_STOPPED:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) t->state = VUDC_TR_IDLE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) t->frame_start = jiffies;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) t->frame_limit = get_frame_limit(udc->gadget.speed);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) return v_kick_timer(udc, jiffies);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) void v_kick_timer(struct vudc *udc, unsigned long time)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) struct transfer_timer *t = &udc->tr_timer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) dev_dbg(&udc->pdev->dev, "timer kick");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) switch (t->state) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) case VUDC_TR_RUNNING:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) case VUDC_TR_IDLE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) t->state = VUDC_TR_RUNNING;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) fallthrough;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) case VUDC_TR_STOPPED:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) /* we may want to kick timer to unqueue urbs */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) mod_timer(&t->timer, time);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) void v_stop_timer(struct vudc *udc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) struct transfer_timer *t = &udc->tr_timer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) /* timer itself will take care of stopping */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) dev_dbg(&udc->pdev->dev, "timer stop");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) t->state = VUDC_TR_STOPPED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) }