DM USB: clean-up: give shorter names to libusb_xfer and req

The names for the two variables are too long, change to shorter
name. This patch doesn't change any logic, just clean up.

Tracked-On: #3054
Signed-off-by: Xiaoguang Wu <xiaoguang.wu@intel.com>
Acked-by: Yu Wang <yu1.wang@intel.com>
This commit is contained in:
Xiaoguang Wu 2019-04-29 11:50:47 +08:00 committed by ACRN System Integration
parent adaed5c0e3
commit b57f6f9243
2 changed files with 60 additions and 69 deletions

View File

@ -170,9 +170,9 @@ libusb_speed_to_usb_speed(int libusb_speed)
} }
static void static void
usb_dev_comp_req(struct libusb_transfer *libusb_xfer) usb_dev_comp_req(struct libusb_transfer *trn)
{ {
struct usb_dev_req *req; struct usb_dev_req *r;
struct usb_data_xfer *xfer; struct usb_data_xfer *xfer;
struct usb_data_xfer_block *block; struct usb_data_xfer_block *block;
int len, do_intr = 0, short_data = 0; int len, do_intr = 0, short_data = 0;
@ -180,42 +180,33 @@ usb_dev_comp_req(struct libusb_transfer *libusb_xfer)
int bstart, bcount; int bstart, bcount;
int is_stalled = 0; int is_stalled = 0;
assert(libusb_xfer); assert(trn);
/* async request */ /* async request */
req = libusb_xfer->user_data; r = trn->user_data;
len = libusb_xfer->actual_length; len = trn->actual_length;
assert(req); assert(r);
assert(req->udev); assert(r->udev);
/* async transfer */ /* async transfer */
xfer = req->xfer; xfer = r->xfer;
if (xfer->magic != USB_DROPPED_XFER_MAGIC)
/* FIXME: if magic is not what we expected, which means it is
* reset by Disable Endpoint command, hence this xfer from
* callback function should be discarded. This is a workaround
* and a formal implementation for Disable Endpoint command
* will replace this WA.
*/
goto out;
assert(xfer); assert(xfer);
assert(xfer->dev); assert(xfer->dev);
bstart = req->blk_start; bstart = r->blk_start;
bcount = req->blk_count; bcount = r->blk_count;
UPRINTF(LDBG, "%s: actual_length %d ep%d-transfer (%d-%d %d) request-%d" UPRINTF(LDBG, "%s: actual_length %d ep%d-transfer (%d-%d %d) request-%d"
" (%d-%d %d) status %d\r\n", __func__, len, xfer->epid, " (%d-%d %d) status %d\r\n", __func__, len, xfer->epid,
xfer->head, (xfer->tail - 1) % USB_MAX_XFER_BLOCKS, xfer->head, (xfer->tail - 1) % USB_MAX_XFER_BLOCKS,
xfer->ndata, req->seq, bstart, (bstart + bcount - 1) % xfer->ndata, r->seq, bstart, (bstart + bcount - 1) %
USB_MAX_XFER_BLOCKS, req->buf_length, USB_MAX_XFER_BLOCKS, r->buf_length,
libusb_xfer->status); trn->status);
/* lock for protecting the transfer */ /* lock for protecting the transfer */
USB_DATA_XFER_LOCK(xfer); USB_DATA_XFER_LOCK(xfer);
xfer->status = USB_ERR_NORMAL_COMPLETION; xfer->status = USB_ERR_NORMAL_COMPLETION;
switch (libusb_xfer->status) { switch (trn->status) {
case LIBUSB_TRANSFER_STALL: case LIBUSB_TRANSFER_STALL:
xfer->status = USB_ERR_STALLED; xfer->status = USB_ERR_STALLED;
is_stalled = 1; is_stalled = 1;
@ -240,14 +231,14 @@ usb_dev_comp_req(struct libusb_transfer *libusb_xfer)
case LIBUSB_TRANSFER_COMPLETED: case LIBUSB_TRANSFER_COMPLETED:
break; break;
default: default:
UPRINTF(LWRN, "unknown failure: %x\r\n", libusb_xfer->status); UPRINTF(LWRN, "unknown failure: %x\r\n", trn->status);
break; break;
} }
if (libusb_xfer->type == LIBUSB_TRANSFER_TYPE_ISOCHRONOUS) { if (trn->type == LIBUSB_TRANSFER_TYPE_ISOCHRONOUS) {
for (i = 0; i < libusb_xfer->num_iso_packets; i++) { for (i = 0; i < trn->num_iso_packets; i++) {
struct libusb_iso_packet_descriptor *p = struct libusb_iso_packet_descriptor *p =
&libusb_xfer->iso_packet_desc[i]; &trn->iso_packet_desc[i];
len += p->actual_length; len += p->actual_length;
UPRINTF(LDBG, "packet%u length %u actual_length %u\n", UPRINTF(LDBG, "packet%u length %u actual_length %u\n",
@ -258,8 +249,8 @@ usb_dev_comp_req(struct libusb_transfer *libusb_xfer)
/* handle the blocks belong to this request */ /* handle the blocks belong to this request */
i = 0; i = 0;
buf_idx = 0; buf_idx = 0;
idx = req->blk_start; idx = r->blk_start;
while (i < req->blk_count) { while (i < r->blk_count) {
done = 0; done = 0;
block = &xfer->data[idx % USB_MAX_XFER_BLOCKS]; block = &xfer->data[idx % USB_MAX_XFER_BLOCKS];
@ -278,8 +269,8 @@ usb_dev_comp_req(struct libusb_transfer *libusb_xfer)
done = len - buf_idx; done = len - buf_idx;
short_data = 1; short_data = 1;
} }
if (req->in) if (r->in)
memcpy(block->buf, &req->buffer[buf_idx], done); memcpy(block->buf, &r->buffer[buf_idx], done);
} }
assert(block->processed); assert(block->processed);
@ -289,13 +280,13 @@ usb_dev_comp_req(struct libusb_transfer *libusb_xfer)
block->processed = USB_XFER_BLK_HANDLED; block->processed = USB_XFER_BLK_HANDLED;
idx = (idx + 1) % USB_MAX_XFER_BLOCKS; idx = (idx + 1) % USB_MAX_XFER_BLOCKS;
if (libusb_xfer->type == LIBUSB_TRANSFER_TYPE_ISOCHRONOUS) { if (trn->type == LIBUSB_TRANSFER_TYPE_ISOCHRONOUS) {
/* For isoc OUT transfer, the libusb_xfer->actual_length /* For isoc OUT transfer, the libusb_xfer->actual_length
* always return zero, so here set block->blen = 0 * always return zero, so here set block->blen = 0
* forcely and native xhci driver will not complain * forcely and native xhci driver will not complain
* about short packet. * about short packet.
*/ */
if (!req->in) { if (!r->in) {
block->bdone = done; block->bdone = done;
block->blen = 0; block->blen = 0;
} }
@ -305,7 +296,7 @@ usb_dev_comp_req(struct libusb_transfer *libusb_xfer)
stall_out: stall_out:
if (is_stalled) { if (is_stalled) {
for (i = 0, idx = req->blk_start; i < req->blk_count; ++i) { for (i = 0, idx = r->blk_start; i < r->blk_count; ++i) {
block = &xfer->data[idx % USB_MAX_XFER_BLOCKS]; block = &xfer->data[idx % USB_MAX_XFER_BLOCKS];
block->processed = USB_XFER_BLK_HANDLED; block->processed = USB_XFER_BLK_HANDLED;
} }
@ -325,11 +316,11 @@ out:
/* unlock and release memory */ /* unlock and release memory */
USB_DATA_XFER_UNLOCK(xfer); USB_DATA_XFER_UNLOCK(xfer);
libusb_free_transfer(libusb_xfer); libusb_free_transfer(trn);
if (req && req->buffer) if (r && r->buffer)
free(req->buffer); free(r->buffer);
free(req); free(r);
} }
static struct usb_dev_req * static struct usb_dev_req *
@ -350,8 +341,8 @@ usb_dev_alloc_req(struct usb_dev *udev, struct usb_data_xfer *xfer, int in,
req->in = in; req->in = in;
req->xfer = xfer; req->xfer = xfer;
req->seq = seq++; req->seq = seq++;
req->libusb_xfer = libusb_alloc_transfer(count); req->trn = libusb_alloc_transfer(count);
if (!req->libusb_xfer) if (!req->trn)
goto errout; goto errout;
if (size) if (size)
@ -365,8 +356,8 @@ usb_dev_alloc_req(struct usb_dev *udev, struct usb_data_xfer *xfer, int in,
errout: errout:
if (req && req->buffer) if (req && req->buffer)
free(req->buffer); free(req->buffer);
if (req && req->libusb_xfer) if (req && req->trn)
libusb_free_transfer(req->libusb_xfer); libusb_free_transfer(req->trn);
if (req) if (req)
free(req); free(req);
return NULL; return NULL;
@ -778,7 +769,7 @@ int
usb_dev_data(void *pdata, struct usb_data_xfer *xfer, int dir, int epctx) usb_dev_data(void *pdata, struct usb_data_xfer *xfer, int dir, int epctx)
{ {
struct usb_dev *udev; struct usb_dev *udev;
struct usb_dev_req *req; struct usb_dev_req *r;
int rc = 0, epid; int rc = 0, epid;
uint8_t type; uint8_t type;
int blk_start, data_size, blk_count; int blk_start, data_size, blk_count;
@ -819,20 +810,20 @@ usb_dev_data(void *pdata, struct usb_data_xfer *xfer, int dir, int epctx)
* Currently, this design works fine for playback and record of USB * Currently, this design works fine for playback and record of USB
* headset, need to do more analysis. * headset, need to do more analysis.
*/ */
req = usb_dev_alloc_req(udev, xfer, dir, data_size, type == r = usb_dev_alloc_req(udev, xfer, dir, data_size, type ==
USB_ENDPOINT_ISOC ? 1 : 0); USB_ENDPOINT_ISOC ? 1 : 0);
if (!req) { if (!r) {
xfer->status = USB_ERR_IOERROR; xfer->status = USB_ERR_IOERROR;
goto done; goto done;
} }
req->buf_length = data_size; r->buf_length = data_size;
req->blk_start = blk_start; r->blk_start = blk_start;
req->blk_count = blk_count; r->blk_count = blk_count;
UPRINTF(LDBG, "%s: transfer_length %d ep%d-transfer (%d-%d %d) request" UPRINTF(LDBG, "%s: transfer_length %d ep%d-transfer (%d-%d %d) request"
"-%d (%d-%d %d) direction %s type %s\r\n", __func__, "-%d (%d-%d %d) direction %s type %s\r\n", __func__,
data_size, epctx, xfer->head, (xfer->tail - 1) % data_size, epctx, xfer->head, (xfer->tail - 1) %
USB_MAX_XFER_BLOCKS, xfer->ndata, req->seq, blk_start, USB_MAX_XFER_BLOCKS, xfer->ndata, r->seq, blk_start,
(blk_start + blk_count - 1) % USB_MAX_XFER_BLOCKS, (blk_start + blk_count - 1) % USB_MAX_XFER_BLOCKS,
data_size, dir_str[dir], type_str[type]); data_size, dir_str[dir], type_str[type]);
@ -840,7 +831,7 @@ usb_dev_data(void *pdata, struct usb_data_xfer *xfer, int dir, int epctx)
for (i = 0, j = 0, buf_idx = 0; j < blk_count; ++i) { for (i = 0, j = 0, buf_idx = 0; j < blk_count; ++i) {
b = &xfer->data[(blk_start + i) % USB_MAX_XFER_BLOCKS]; b = &xfer->data[(blk_start + i) % USB_MAX_XFER_BLOCKS];
if (b->buf) { if (b->buf) {
memcpy(&req->buffer[buf_idx], b->buf, b->blen); memcpy(&r->buffer[buf_idx], b->buf, b->blen);
buf_idx += b->blen; buf_idx += b->blen;
j++; j++;
} }
@ -859,47 +850,47 @@ usb_dev_data(void *pdata, struct usb_data_xfer *xfer, int dir, int epctx)
/* /*
* TODO: Is there any risk of data missing? * TODO: Is there any risk of data missing?
*/ */
libusb_fill_bulk_transfer(req->libusb_xfer, libusb_fill_bulk_transfer(r->trn,
udev->handle, epid, udev->handle, epid,
req->buffer, r->buffer,
data_size, data_size,
usb_dev_comp_req, usb_dev_comp_req,
req, r,
0); 0);
do { do {
rc = libusb_submit_transfer(req->libusb_xfer); rc = libusb_submit_transfer(r->trn);
} while (rc && retries--); } while (rc && retries--);
} else if (type == USB_ENDPOINT_INT) { } else if (type == USB_ENDPOINT_INT) {
/* give data to physical device through libusb */ /* give data to physical device through libusb */
libusb_fill_interrupt_transfer(req->libusb_xfer, libusb_fill_interrupt_transfer(r->trn,
udev->handle, udev->handle,
epid, epid,
req->buffer, r->buffer,
data_size, data_size,
usb_dev_comp_req, usb_dev_comp_req,
req, r,
0); 0);
rc = libusb_submit_transfer(req->libusb_xfer); rc = libusb_submit_transfer(r->trn);
} else if (type == USB_ENDPOINT_ISOC) { } else if (type == USB_ENDPOINT_ISOC) {
/* TODO: Current design is to convert every UOS trb into SOS /* TODO: Current design is to convert every UOS trb into SOS
* urb. It works fine, but potential issues and performance * urb. It works fine, but potential issues and performance
* effect should be investigated in detail. * effect should be investigated in detail.
*/ */
libusb_fill_iso_transfer(req->libusb_xfer, udev->handle, libusb_fill_iso_transfer(r->trn, udev->handle,
epid, req->buffer, data_size, 1, epid, r->buffer, data_size, 1,
usb_dev_comp_req, req, 0); usb_dev_comp_req, r, 0);
libusb_set_iso_packet_lengths(req->libusb_xfer, data_size); libusb_set_iso_packet_lengths(r->trn, data_size);
rc = libusb_submit_transfer(req->libusb_xfer); rc = libusb_submit_transfer(r->trn);
} else { } else {
UPRINTF(LFTL, "%s: wrong endpoint type %d\r\n", __func__, type); UPRINTF(LFTL, "%s: wrong endpoint type %d\r\n", __func__, type);
if (req->buffer) if (r->buffer)
free(req->buffer); free(r->buffer);
if (req->libusb_xfer) if (r->trn)
libusb_free_transfer(req->libusb_xfer); libusb_free_transfer(r->trn);
free(req); free(r);
xfer->status = USB_ERR_INVAL; xfer->status = USB_ERR_INVAL;
} }

View File

@ -79,7 +79,7 @@ struct usb_dev_req {
int blk_count; int blk_count;
struct usb_data_xfer *xfer; struct usb_data_xfer *xfer;
struct libusb_transfer *libusb_xfer; struct libusb_transfer *trn;
struct usb_data_xfer_block *setup_blk; struct usb_data_xfer_block *setup_blk;
}; };