mirror of
https://github.com/projectacrn/acrn-hypervisor.git
synced 2025-08-10 20:43:48 +00:00
DM USB: introduce helper functions: index_inc and index_valid
Introduce helper functions to make code shorter and cleaner. Tracked-On: #3628 Signed-off-by: Xiaoguang Wu <xiaoguang.wu@intel.com> Acked-by: Yu Wang <yu1.wang@intel.com>
This commit is contained in:
parent
d58a766556
commit
1352eca224
@ -2663,13 +2663,13 @@ pci_xhci_xfer_complete(struct pci_xhci_vdev *xdev, struct usb_xfer *xfer,
|
||||
|
||||
xfer->data[i].stat = USB_BLOCK_FREE;
|
||||
xfer->ndata--;
|
||||
xfer->head = (xfer->head + 1) % USB_MAX_XFER_BLOCKS;
|
||||
xfer->head = index_inc(xfer->head, USB_MAX_XFER_BLOCKS);
|
||||
edtla += xfer->data[i].bdone;
|
||||
|
||||
trb->dwTrb3 = (trb->dwTrb3 & ~0x1) | (xfer->data[i].ccs);
|
||||
if (xfer->data[i].type == USB_DATA_PART) {
|
||||
rem_len += xfer->data[i].blen;
|
||||
i = (i + 1) % USB_MAX_XFER_BLOCKS;
|
||||
i = index_inc(i, USB_MAX_XFER_BLOCKS);
|
||||
|
||||
/* This 'continue' will delay the IOC behavior which
|
||||
* could decrease the number of virtual interrupts.
|
||||
@ -2688,7 +2688,7 @@ pci_xhci_xfer_complete(struct pci_xhci_vdev *xdev, struct usb_xfer *xfer,
|
||||
!((err == XHCI_TRB_ERROR_SHORT_PKT) &&
|
||||
(trb->dwTrb3 & XHCI_TRB_3_ISP_BIT))) {
|
||||
|
||||
i = (i + 1) % USB_MAX_XFER_BLOCKS;
|
||||
i = index_inc(i, USB_MAX_XFER_BLOCKS);
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -2713,7 +2713,7 @@ pci_xhci_xfer_complete(struct pci_xhci_vdev *xdev, struct usb_xfer *xfer,
|
||||
if (err != XHCI_TRB_ERROR_SUCCESS)
|
||||
break;
|
||||
|
||||
i = (i + 1) % USB_MAX_XFER_BLOCKS;
|
||||
i = index_inc(i, USB_MAX_XFER_BLOCKS);
|
||||
rem_len = 0;
|
||||
}
|
||||
|
||||
|
@ -336,7 +336,7 @@ umouse_request(void *scarg, struct usb_xfer *xfer)
|
||||
}
|
||||
|
||||
xfer->data[idx].stat = USB_BLOCK_HANDLED;
|
||||
idx = (idx + 1) % USB_MAX_XFER_BLOCKS;
|
||||
idx = index_inc(idx, USB_MAX_XFER_BLOCKS);
|
||||
}
|
||||
|
||||
err = USB_ERR_NORMAL_COMPLETION;
|
||||
@ -716,7 +716,7 @@ umouse_data_handler(void *scarg, struct usb_xfer *xfer, int dir,
|
||||
|
||||
data->stat = USB_BLOCK_HANDLED;
|
||||
data = NULL;
|
||||
idx = (idx + 1) % USB_MAX_XFER_BLOCKS;
|
||||
idx = index_inc(idx, USB_MAX_XFER_BLOCKS);
|
||||
}
|
||||
if (!data)
|
||||
goto done;
|
||||
|
@ -246,11 +246,8 @@ usb_dev_comp_cb(struct libusb_transfer *trn)
|
||||
idx = r->blk_head;
|
||||
buf_idx = 0;
|
||||
done = trn->actual_length;
|
||||
|
||||
while ((r->blk_head <= r->blk_tail && idx >= r->blk_head &&
|
||||
idx < r->blk_tail) || ((r->blk_head > r->blk_tail) &&
|
||||
((idx >= r->blk_head && idx < USB_MAX_XFER_BLOCKS) ||
|
||||
(idx >= 0 && idx < r->blk_tail)))) {
|
||||
while (index_valid(r->blk_head, r->blk_tail, USB_MAX_XFER_BLOCKS, idx))
|
||||
{
|
||||
if (trn->type == LIBUSB_TRANSFER_TYPE_ISOCHRONOUS) {
|
||||
buf_idx = 0;
|
||||
buf = libusb_get_iso_packet_buffer_simple(trn, i);
|
||||
@ -284,7 +281,7 @@ usb_dev_comp_cb(struct libusb_transfer *trn)
|
||||
block->blen -= d;
|
||||
block->bdone = d;
|
||||
block->stat = USB_BLOCK_HANDLED;
|
||||
idx = (idx + 1) % USB_MAX_XFER_BLOCKS;
|
||||
idx = index_inc(idx, USB_MAX_XFER_BLOCKS);
|
||||
|
||||
} while (block->type == USB_DATA_PART);
|
||||
}
|
||||
@ -292,14 +289,11 @@ usb_dev_comp_cb(struct libusb_transfer *trn)
|
||||
stall_out:
|
||||
if (is_stalled) {
|
||||
idx = r->blk_head;
|
||||
|
||||
while ((r->blk_head <= r->blk_tail && idx >= r->blk_head &&
|
||||
idx < r->blk_tail) || ((r->blk_head > r->blk_tail) &&
|
||||
((idx >= r->blk_head && idx < USB_MAX_XFER_BLOCKS) ||
|
||||
(idx >= 0 && idx < r->blk_tail)))) {
|
||||
while (index_valid(r->blk_head, r->blk_tail,
|
||||
USB_MAX_XFER_BLOCKS, idx)) {
|
||||
block = &xfer->data[idx];
|
||||
block->stat = USB_BLOCK_HANDLED;
|
||||
idx = (idx + 1) % USB_MAX_XFER_BLOCKS;
|
||||
idx = index_inc(idx, USB_MAX_XFER_BLOCKS);
|
||||
}
|
||||
}
|
||||
|
||||
@ -377,8 +371,8 @@ usb_dev_prepare_xfer(struct usb_xfer *xfer, int *head, int *tail)
|
||||
if (idx < 0 || idx >= USB_MAX_XFER_BLOCKS)
|
||||
return -1;
|
||||
|
||||
for (i = 0; i < xfer->ndata; i++, idx = (idx + 1) % USB_MAX_XFER_BLOCKS)
|
||||
{
|
||||
for (i = 0; i < xfer->ndata;
|
||||
i++, idx = index_inc(idx, USB_MAX_XFER_BLOCKS)) {
|
||||
block = &xfer->data[idx];
|
||||
if (block->stat == USB_BLOCK_HANDLED ||
|
||||
block->stat == USB_BLOCK_HANDLING)
|
||||
@ -720,7 +714,7 @@ usb_dev_prepare_ctrl_xfer(struct usb_xfer *xfer)
|
||||
ret = blk;
|
||||
|
||||
blk->stat = USB_BLOCK_HANDLED;
|
||||
idx = (idx + 1) % USB_MAX_XFER_BLOCKS;
|
||||
idx = index_inc(idx, USB_MAX_XFER_BLOCKS);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
@ -781,12 +775,10 @@ usb_dev_data(void *pdata, struct usb_xfer *xfer, int dir, int epctx)
|
||||
framelen = USB_EP_MAXP_SZ(maxp) * (1 + USB_EP_MAXP_MT(maxp));
|
||||
UPRINTF(LDBG, "iso maxp %u framelen %d\r\n", maxp, framelen);
|
||||
|
||||
idx = head;
|
||||
while (((head <= tail && idx >= head && idx < tail) ||
|
||||
((idx >= head && idx < USB_MAX_XFER_BLOCKS) ||
|
||||
(idx >= 0 && idx < tail)))) {
|
||||
for (idx = head;
|
||||
index_valid(head, tail, USB_MAX_XFER_BLOCKS, idx);
|
||||
idx = index_inc(idx, USB_MAX_XFER_BLOCKS)) {
|
||||
|
||||
idx = (idx + 1) % USB_MAX_XFER_BLOCKS;
|
||||
if (xfer->data[idx].blen > framelen)
|
||||
UPRINTF(LFTL, "err framelen %d\r\n", framelen);
|
||||
|
||||
@ -821,13 +813,9 @@ usb_dev_data(void *pdata, struct usb_xfer *xfer, int dir, int epctx)
|
||||
type_str[type]);
|
||||
|
||||
if (!dir) {
|
||||
idx = head;
|
||||
buf_idx = 0;
|
||||
while (((head <= tail && idx >= head && idx < tail) ||
|
||||
((idx >= head && idx < USB_MAX_XFER_BLOCKS) ||
|
||||
(idx >= 0 && idx < tail)))) {
|
||||
|
||||
idx = (idx + 1) % USB_MAX_XFER_BLOCKS;
|
||||
for (idx = head, buf_idx = 0;
|
||||
index_valid(head, tail, USB_MAX_XFER_BLOCKS, idx);
|
||||
idx = index_inc(idx, USB_MAX_XFER_BLOCKS)) {
|
||||
b = &xfer->data[idx];
|
||||
if (b->type == USB_DATA_PART ||
|
||||
b->type == USB_DATA_FULL) {
|
||||
@ -838,15 +826,10 @@ usb_dev_data(void *pdata, struct usb_xfer *xfer, int dir, int epctx)
|
||||
}
|
||||
|
||||
if (type == USB_ENDPOINT_ISOC) {
|
||||
idx = head;
|
||||
while ((head <= tail && idx >= head && idx < tail) ||
|
||||
((idx >= head && idx < USB_MAX_XFER_BLOCKS) ||
|
||||
(idx >= 0 && idx < tail))) {
|
||||
int len;
|
||||
|
||||
i = 0;
|
||||
idx = (idx + 1) % USB_MAX_XFER_BLOCKS;
|
||||
len = xfer->data[idx].blen;
|
||||
for (i = 0, idx = head;
|
||||
index_valid(head, tail, USB_MAX_XFER_BLOCKS, idx);
|
||||
idx = index_inc(idx, USB_MAX_XFER_BLOCKS)) {
|
||||
int len = xfer->data[idx].blen;
|
||||
|
||||
if (xfer->data[idx].type == USB_DATA_NONE) {
|
||||
continue;
|
||||
|
@ -118,7 +118,7 @@ usb_block_append(struct usb_xfer *xfer, void *buf, int blen,
|
||||
xb->bdone = 0;
|
||||
xb->type = USB_DATA_NONE;
|
||||
xfer->ndata++;
|
||||
xfer->tail = (xfer->tail + 1) % USB_MAX_XFER_BLOCKS;
|
||||
xfer->tail = index_inc(xfer->tail, USB_MAX_XFER_BLOCKS);
|
||||
return xb;
|
||||
}
|
||||
|
||||
|
@ -230,6 +230,21 @@ enum USB_ERRCODE {
|
||||
|
||||
#define USB_DROPPED_XFER_MAGIC 0xaaaaaaaa55555555
|
||||
|
||||
inline bool
|
||||
index_valid(int head, int tail, int maxcnt, int idx) {
|
||||
if (head <= tail)
|
||||
return (idx >= head && idx < tail);
|
||||
else
|
||||
return (idx >= head && idx < maxcnt) ||
|
||||
(idx >= 0 && idx < tail);
|
||||
}
|
||||
|
||||
inline int
|
||||
index_inc(int idx, int maxcnt)
|
||||
{
|
||||
return (idx + 1) % maxcnt;
|
||||
}
|
||||
|
||||
extern int usb_log_level;
|
||||
static inline int usb_get_log_level(void) { return usb_log_level; }
|
||||
static inline void usb_set_log_level(int level) { usb_log_level = level; }
|
||||
|
Loading…
Reference in New Issue
Block a user