usb: rename usb_drv_recv() to usb_recv_recv_nonblocking()

IMHO the current name is somewhat misleading:

- usb_drv_send() is blocking and we have usb_drv_send_nonblocking()
  for the non-blocking case. This inconsistent naming can only
  promote confusion. (And what would we call a blocking receive?)

- Other hardware abstraction APIs in Rockbox are usually blocking:
  storage, LCD, backlight, audio... in other words, blocking is the
  default expected behavior, with non-blocking calls being a rarity.

Change-Id: I05b41088d09eab582697674f4f06fdca0c8950af
This commit is contained in:
Aidan MacDonald 2021-09-19 10:54:26 +01:00
parent 99f333c64f
commit 672bbe434b
16 changed files with 36 additions and 38 deletions

View File

@ -531,9 +531,9 @@ static void in_callback(int ep, unsigned char *buf, int len)
usb_core_transfer_complete(ep, false, 0, len); usb_core_transfer_complete(ep, false, 0, len);
} }
int usb_drv_recv(int ep, void* ptr, int length) int usb_drv_recv_nonblocking(int ep, void* ptr, int length)
{ {
logf("usb_drv_recv(%d, 0x%x, %d)", ep, (int)ptr, length); logf("usb_drv_recv_nonblocking(%d, 0x%x, %d)", ep, (int)ptr, length);
if(ep == EP_CONTROL && length == 0 && ptr == NULL) if(ep == EP_CONTROL && length == 0 && ptr == NULL)
{ {
usb_status_ack(ep, DIR_TX); usb_status_ack(ep, DIR_TX);

View File

@ -869,7 +869,7 @@ int usb_drv_send(int endpoint, void* ptr, int length)
/* This function begins a receive (on an OUT endpoint), it should not block /* This function begins a receive (on an OUT endpoint), it should not block
* so the actual receive is done in the interrupt handler. * so the actual receive is done in the interrupt handler.
*/ */
int usb_drv_recv(int endpoint, void* ptr, int length) int usb_drv_recv_nonblocking(int endpoint, void* ptr, int length)
{ {
return mxx_queue(endpoint, ptr, length, false, false); return mxx_queue(endpoint, ptr, length, false, false);
} }

View File

@ -1333,7 +1333,7 @@ void usb_drv_release_endpoint(int endpoint)
usb_dw_target_enable_irq(); usb_dw_target_enable_irq();
} }
int usb_drv_recv(int endpoint, void* ptr, int length) int usb_drv_recv_nonblocking(int endpoint, void* ptr, int length)
{ {
int epnum = EP_NUM(endpoint); int epnum = EP_NUM(endpoint);
struct usb_dw_ep* dw_ep = usb_dw_get_ep(epnum, USB_DW_EPDIR_OUT); struct usb_dw_ep* dw_ep = usb_dw_get_ep(epnum, USB_DW_EPDIR_OUT);

View File

@ -68,8 +68,7 @@ void usb_drv_stall(int endpoint, bool stall,bool in);
bool usb_drv_stalled(int endpoint,bool in); bool usb_drv_stalled(int endpoint,bool in);
int usb_drv_send(int endpoint, void* ptr, int length); int usb_drv_send(int endpoint, void* ptr, int length);
int usb_drv_send_nonblocking(int endpoint, void* ptr, int length); int usb_drv_send_nonblocking(int endpoint, void* ptr, int length);
int usb_drv_recv(int endpoint, void* ptr, int length); int usb_drv_recv_nonblocking(int endpoint, void* ptr, int length);
void usb_drv_ack(struct usb_ctrlrequest* req);
void usb_drv_set_address(int address); void usb_drv_set_address(int address);
void usb_drv_reset_endpoint(int endpoint, bool send); void usb_drv_reset_endpoint(int endpoint, bool send);
bool usb_drv_powered(void); bool usb_drv_powered(void);

View File

@ -412,12 +412,12 @@ void usb_drv_cancel_all_transfers(void)
restore_irq(flags); restore_irq(flags);
} }
int usb_drv_recv(int ep, void *ptr, int len) int usb_drv_recv_nonblocking(int ep, void *ptr, int len)
{ {
struct usb_dev_dma_desc *uc_desc = endpoints[ep][1].uc_desc; struct usb_dev_dma_desc *uc_desc = endpoints[ep][1].uc_desc;
ep &= 0x7f; ep &= 0x7f;
logf("usb_drv_recv(%d,%x,%d)\n", ep, (int)ptr, len); logf("usb_drv_recv_nonblocking(%d,%x,%d)\n", ep, (int)ptr, len);
if (len > USB_DMA_DESC_RXTX_BYTES) if (len > USB_DMA_DESC_RXTX_BYTES)
panicf("usb_recv: len=%d > %d", len, USB_DMA_DESC_RXTX_BYTES); panicf("usb_recv: len=%d > %d", len, USB_DMA_DESC_RXTX_BYTES);
@ -674,7 +674,8 @@ static void handle_out_ep(int ep)
* The usb_storage buffer is 63KB, but Linux sends 120KB. * The usb_storage buffer is 63KB, but Linux sends 120KB.
* We get the first part, but upon re-enabling receive dma we * We get the first part, but upon re-enabling receive dma we
* get a 'buffer not available' error from the hardware, since * get a 'buffer not available' error from the hardware, since
* we haven't gotten the next usb_drv_recv() from the stack yet. * we haven't gotten the next usb_drv_recv_nonblocking() from
* the stack yet.
* It seems the NAK bit is ignored here and the HW tries to dma * It seems the NAK bit is ignored here and the HW tries to dma
* the incoming data anyway. * the incoming data anyway.
* In theory I think the BNA error should be recoverable, but * In theory I think the BNA error should be recoverable, but

View File

@ -355,7 +355,7 @@ int usb_drv_send_nonblocking(int endpoint, void *ptr, int length)
} }
/* Setup a receive transfer. (non blocking) */ /* Setup a receive transfer. (non blocking) */
int usb_drv_recv(int endpoint, void* ptr, int length) int usb_drv_recv_nonblocking(int endpoint, void* ptr, int length)
{ {
logf("udc: recv(%x)", endpoint); logf("udc: recv(%x)", endpoint);
struct endpoint_t *ep; struct endpoint_t *ep;

View File

@ -1026,8 +1026,8 @@ static bool tnetv_handle_cppi(void)
if (rx_intstatus || tx_intstatus || rcv_sched) if (rx_intstatus || tx_intstatus || rcv_sched)
{ {
/* Request calling again after short delay /* Request calling again after short delay
* Needed when for example when OUT endpoint has pending * Needed when for example when OUT endpoint has pending data
* data but the USB task did not call usb_drv_recv() yet. * but the USB task did not call usb_drv_recv_nonblocking() yet.
*/ */
return true; return true;
} }
@ -1371,7 +1371,7 @@ int usb_drv_send_nonblocking(int endpoint, void* ptr, int length)
return _usb_drv_send(endpoint, ptr, length, false); return _usb_drv_send(endpoint, ptr, length, false);
} }
int usb_drv_recv(int endpoint, void* ptr, int length) int usb_drv_recv_nonblocking(int endpoint, void* ptr, int length)
{ {
int epn = EP_NUM(endpoint); int epn = EP_NUM(endpoint);
struct ep_runtime_t *ep; struct ep_runtime_t *ep;
@ -1388,8 +1388,6 @@ int usb_drv_recv(int endpoint, void* ptr, int length)
return 0; return 0;
} }
void usb_drv_ack(struct usb_ctrlrequest* req);
void usb_drv_set_address(int address) void usb_drv_set_address(int address)
{ {
UsbCtrlType usbCtrl; UsbCtrlType usbCtrl;

View File

@ -593,7 +593,7 @@ int usb_drv_send(int endpoint, void* ptr, int length)
return prime_transfer(EP_NUM(endpoint), ptr, length, true, true); return prime_transfer(EP_NUM(endpoint), ptr, length, true, true);
} }
int usb_drv_recv(int endpoint, void* ptr, int length) int usb_drv_recv_nonblocking(int endpoint, void* ptr, int length)
{ {
//logf("usbrecv(%x, %d)", ptr, length); //logf("usbrecv(%x, %d)", ptr, length);
return prime_transfer(EP_NUM(endpoint), ptr, length, false, false); return prime_transfer(EP_NUM(endpoint), ptr, length, false, false);

View File

@ -166,7 +166,7 @@ int usb_drv_send_nonblocking(int endpoint, void *ptr, int length)
return 0; return 0;
} }
int usb_drv_recv(int endpoint, void* ptr, int length) int usb_drv_recv_nonblocking(int endpoint, void* ptr, int length)
{ {
ep_transfer(EP_NUM(endpoint), ptr, length, true); ep_transfer(EP_NUM(endpoint), ptr, length, true);
return 0; return 0;

View File

@ -609,7 +609,7 @@ int usb_drv_send_nonblocking(int endpoint, void *ptr, int length)
return rc; return rc;
} }
int usb_drv_recv(int endpoint, void* ptr, int length) int usb_drv_recv_nonblocking(int endpoint, void* ptr, int length)
{ {
volatile struct tcc_ep *tcc_ep = &tcc_endpoints[endpoint & 0x7f]; volatile struct tcc_ep *tcc_ep = &tcc_endpoints[endpoint & 0x7f];
int flags; int flags;

View File

@ -743,7 +743,7 @@ int usb_drv_send(int endpoint, void* ptr, int length)
return 0; return 0;
} }
int usb_drv_recv(int endpoint, void* ptr, int length) int usb_drv_recv_nonblocking(int endpoint, void* ptr, int length)
{ {
int flags; int flags;
struct usb_endpoint *ep; struct usb_endpoint *ep;

View File

@ -1118,7 +1118,7 @@ int usb_drv_send(int endpoint, void* ptr, int length)
return -1; return -1;
} }
int usb_drv_recv(int endpoint, void* ptr, int length) int usb_drv_recv_nonblocking(int endpoint, void* ptr, int length)
{ {
int flags; int flags;
struct usb_endpoint *ep; struct usb_endpoint *ep;

View File

@ -674,7 +674,7 @@ static void request_handler_device_get_descriptor(struct usb_ctrlrequest* req)
if (ptr != response_data) if (ptr != response_data)
memcpy(response_data, ptr, length); memcpy(response_data, ptr, length);
usb_drv_recv(EP_CONTROL, NULL, 0); usb_drv_recv_nonblocking(EP_CONTROL, NULL, 0);
usb_drv_send(EP_CONTROL, response_data, length); usb_drv_send(EP_CONTROL, response_data, length);
} }
} }
@ -725,7 +725,7 @@ static void request_handler_device(struct usb_ctrlrequest* req)
case USB_REQ_GET_CONFIGURATION: { case USB_REQ_GET_CONFIGURATION: {
logf("usb_core: GET_CONFIG"); logf("usb_core: GET_CONFIG");
response_data[0] = (usb_state == ADDRESS ? 0 : 1); response_data[0] = (usb_state == ADDRESS ? 0 : 1);
usb_drv_recv(EP_CONTROL, NULL, 0); usb_drv_recv_nonblocking(EP_CONTROL, NULL, 0);
usb_drv_send(EP_CONTROL, response_data, 1); usb_drv_send(EP_CONTROL, response_data, 1);
break; break;
} }
@ -759,7 +759,7 @@ static void request_handler_device(struct usb_ctrlrequest* req)
case USB_REQ_GET_STATUS: case USB_REQ_GET_STATUS:
response_data[0] = 0; response_data[0] = 0;
response_data[1] = 0; response_data[1] = 0;
usb_drv_recv(EP_CONTROL, NULL, 0); usb_drv_recv_nonblocking(EP_CONTROL, NULL, 0);
usb_drv_send(EP_CONTROL, response_data, 2); usb_drv_send(EP_CONTROL, response_data, 2);
break; break;
default: default:
@ -781,7 +781,7 @@ static void request_handler_interface_standard(struct usb_ctrlrequest* req)
case USB_REQ_GET_INTERFACE: case USB_REQ_GET_INTERFACE:
logf("usb_core: GET_INTERFACE"); logf("usb_core: GET_INTERFACE");
response_data[0] = 0; response_data[0] = 0;
usb_drv_recv(EP_CONTROL, NULL, 0); usb_drv_recv_nonblocking(EP_CONTROL, NULL, 0);
usb_drv_send(EP_CONTROL, response_data, 1); usb_drv_send(EP_CONTROL, response_data, 1);
break; break;
case USB_REQ_CLEAR_FEATURE: case USB_REQ_CLEAR_FEATURE:
@ -791,7 +791,7 @@ static void request_handler_interface_standard(struct usb_ctrlrequest* req)
case USB_REQ_GET_STATUS: case USB_REQ_GET_STATUS:
response_data[0] = 0; response_data[0] = 0;
response_data[1] = 0; response_data[1] = 0;
usb_drv_recv(EP_CONTROL, NULL, 0); usb_drv_recv_nonblocking(EP_CONTROL, NULL, 0);
usb_drv_send(EP_CONTROL, response_data, 2); usb_drv_send(EP_CONTROL, response_data, 2);
break; break;
default: default:
@ -860,7 +860,7 @@ static void request_handler_endpoint_standard(struct usb_ctrlrequest* req)
response_data[0] = usb_drv_stalled(EP_NUM(req->wIndex), response_data[0] = usb_drv_stalled(EP_NUM(req->wIndex),
EP_DIR(req->wIndex)); EP_DIR(req->wIndex));
usb_drv_recv(EP_CONTROL, NULL, 0); usb_drv_recv_nonblocking(EP_CONTROL, NULL, 0);
usb_drv_send(EP_CONTROL, response_data, 2); usb_drv_send(EP_CONTROL, response_data, 2);
break; break;
default: default:

View File

@ -693,7 +693,7 @@ static int usb_hid_set_report(struct usb_ctrlrequest *req)
} }
memset(buf, 0, length); memset(buf, 0, length);
usb_drv_recv(EP_CONTROL, buf, length); usb_drv_recv_nonblocking(EP_CONTROL, buf, length);
#ifdef LOGF_ENABLE #ifdef LOGF_ENABLE
if (buf[1] & 0x01) if (buf[1] & 0x01)
@ -772,7 +772,7 @@ bool usb_hid_control_request(struct usb_ctrlrequest *req, unsigned char *dest)
if (dest != orig_dest) if (dest != orig_dest)
{ {
usb_drv_recv(EP_CONTROL, NULL, 0); /* ack */ usb_drv_recv_nonblocking(EP_CONTROL, NULL, 0); /* ack */
usb_drv_send(EP_CONTROL, orig_dest, dest - orig_dest); usb_drv_send(EP_CONTROL, orig_dest, dest - orig_dest);
return true; return true;
} }
@ -809,7 +809,7 @@ bool usb_hid_control_request(struct usb_ctrlrequest *req, unsigned char *dest)
if (dest != orig_dest) if (dest != orig_dest)
{ {
usb_drv_recv(EP_CONTROL, NULL, 0); /* ack */ usb_drv_recv_nonblocking(EP_CONTROL, NULL, 0); /* ack */
usb_drv_send(EP_CONTROL, orig_dest, dest - orig_dest); usb_drv_send(EP_CONTROL, orig_dest, dest - orig_dest);
} }
else else

View File

@ -294,7 +294,7 @@ bool usb_serial_control_request(struct usb_ctrlrequest* req, unsigned char* dest
if (req->wLength == sizeof(line_coding)) if (req->wLength == sizeof(line_coding))
{ {
/* Receive line coding into local copy */ /* Receive line coding into local copy */
usb_drv_recv(EP_CONTROL, &line_coding, sizeof(line_coding)); usb_drv_recv_nonblocking(EP_CONTROL, &line_coding, sizeof(line_coding));
usb_drv_send(EP_CONTROL, NULL, 0); /* ack */ usb_drv_send(EP_CONTROL, NULL, 0); /* ack */
handled = true; handled = true;
} }
@ -316,7 +316,7 @@ bool usb_serial_control_request(struct usb_ctrlrequest* req, unsigned char* dest
if (req->wLength == sizeof(line_coding)) if (req->wLength == sizeof(line_coding))
{ {
/* Send back line coding so host is happy */ /* Send back line coding so host is happy */
usb_drv_recv(EP_CONTROL, NULL, 0); /* ack */ usb_drv_recv_nonblocking(EP_CONTROL, NULL, 0); /* ack */
usb_drv_send(EP_CONTROL, &line_coding, sizeof(line_coding)); usb_drv_send(EP_CONTROL, &line_coding, sizeof(line_coding));
handled = true; handled = true;
} }
@ -329,7 +329,7 @@ bool usb_serial_control_request(struct usb_ctrlrequest* req, unsigned char* dest
void usb_serial_init_connection(void) void usb_serial_init_connection(void)
{ {
/* prime rx endpoint */ /* prime rx endpoint */
usb_drv_recv(ep_out, receive_buffer, sizeof receive_buffer); usb_drv_recv_nonblocking(ep_out, receive_buffer, sizeof receive_buffer);
/* we come here too after a bus reset, so reset some data */ /* we come here too after a bus reset, so reset some data */
buffer_transitlength = 0; buffer_transitlength = 0;
@ -420,7 +420,7 @@ void usb_serial_transfer_complete(int ep,int dir, int status, int length)
/* Data received. TODO : Do something with it ? */ /* Data received. TODO : Do something with it ? */
/* Get the next bit */ /* Get the next bit */
usb_drv_recv(ep_out, receive_buffer, sizeof receive_buffer); usb_drv_recv_nonblocking(ep_out, receive_buffer, sizeof receive_buffer);
break; break;
case USB_DIR_IN: case USB_DIR_IN:

View File

@ -470,7 +470,7 @@ void usb_storage_init_connection(void)
ramdisk_buffer = tb.transfer_buffer + ALLOCATE_BUFFER_SIZE; ramdisk_buffer = tb.transfer_buffer + ALLOCATE_BUFFER_SIZE;
#endif #endif
#endif #endif
usb_drv_recv(ep_out, cbw_buffer, MAX_CBW_SIZE); usb_drv_recv_nonblocking(ep_out, cbw_buffer, MAX_CBW_SIZE);
int i; int i;
for(i=0;i<storage_num_drives();i++) { for(i=0;i<storage_num_drives();i++) {
@ -685,7 +685,7 @@ bool usb_storage_control_request(struct usb_ctrlrequest* req, unsigned char* des
if(skip_first) (*tb.max_lun) --; if(skip_first) (*tb.max_lun) --;
#endif #endif
logf("ums: getmaxlun"); logf("ums: getmaxlun");
usb_drv_recv(EP_CONTROL, NULL, 0); /* ack */ usb_drv_recv_nonblocking(EP_CONTROL, NULL, 0); /* ack */
usb_drv_send(EP_CONTROL, tb.max_lun, 1); usb_drv_send(EP_CONTROL, tb.max_lun, 1);
handled = true; handled = true;
break; break;
@ -1187,14 +1187,14 @@ static void send_command_failed_result(void)
#if CONFIG_RTC #if CONFIG_RTC
static void receive_time(void) static void receive_time(void)
{ {
usb_drv_recv(ep_out, tb.transfer_buffer, 12); usb_drv_recv_nonblocking(ep_out, tb.transfer_buffer, 12);
state = RECEIVING_TIME; state = RECEIVING_TIME;
} }
#endif /* CONFIG_RTC */ #endif /* CONFIG_RTC */
static void receive_block_data(void *data,int size) static void receive_block_data(void *data,int size)
{ {
usb_drv_recv(ep_out, data, size); usb_drv_recv_nonblocking(ep_out, data, size);
state = RECEIVING_BLOCKS; state = RECEIVING_BLOCKS;
} }
@ -1210,7 +1210,7 @@ static void send_csw(int status)
state = WAITING_FOR_CSW_COMPLETION_OR_COMMAND; state = WAITING_FOR_CSW_COMPLETION_OR_COMMAND;
//logf("CSW: %X",status); //logf("CSW: %X",status);
/* Already start waiting for the next command */ /* Already start waiting for the next command */
usb_drv_recv(ep_out, cbw_buffer, MAX_CBW_SIZE); usb_drv_recv_nonblocking(ep_out, cbw_buffer, MAX_CBW_SIZE);
/* The next completed transfer will be either the CSW one /* The next completed transfer will be either the CSW one
* or the new command */ * or the new command */