/* For IN transfers where halt_status is DWC2_HC_XFER_COMPLETE, *short_read is set to 1 upon return if less than the requested number of bytes were transferred. short_read may also be NULL on entry, in which case it remains unchanged.  */
static u32 dwc2_get_actual_xfer_length(struct dwc2_hsotg *hsotg, struct dwc2_host_chan *chan, int chnum, struct dwc2_qtd *qtd, enum dwc2_halt_status halt_status, int *short_read)
/* For IN transfers where halt_status is DWC2_HC_XFER_COMPLETE, *short_read is set to 1 upon return if less than the requested number of bytes were transferred. short_read may also be NULL on entry, in which case it remains unchanged.  */
static u32 dwc2_get_actual_xfer_length(struct dwc2_hsotg *hsotg, struct dwc2_host_chan *chan, int chnum, struct dwc2_qtd *qtd, enum dwc2_halt_status halt_status, int *short_read)
{
	u32 hctsiz, count, length;
	hctsiz = readl(hsotg->regs + HCTSIZ(chnum));
	if (halt_status == DWC2_HC_XFER_COMPLETE) {
		if (chan->ep_is_in) {
			count = (hctsiz & TSIZ_XFERSIZE_MASK) >>
				TSIZ_XFERSIZE_SHIFT;
			length = chan->xfer_len - count;
			if (short_read != NULL)
				*short_read = (count != 0);
		} else if (chan->qh->do_split) {
			length = qtd->ssplit_out_xfer_count;
		} else {
			length = chan->xfer_len;
		}
	} else {
		count = (hctsiz & TSIZ_PKTCNT_MASK) >> TSIZ_PKTCNT_SHIFT;
		length = (chan->start_pkt_count - count) * chan->max_packet;
	}
	return length;
}