/* return number of bytes in unsent transmit DMA buffers and the serial controller tx FIFO  */
static unsigned int tbuf_bytes(struct slgt_info *info)
/* return number of bytes in unsent transmit DMA buffers and the serial controller tx FIFO  */
static unsigned int tbuf_bytes(struct slgt_info *info)
{
	unsigned int total_count = 0;
	unsigned int i = info->tbuf_current;
	unsigned int reg_value;
	unsigned int count;
	unsigned int active_buf_count = 0;
	do {
		count = desc_count(info->tbufs[i]);
		if (count)
			total_count += count;
		else if (!total_count)
			active_buf_count = info->tbufs[i].buf_count;
		if (++i == info->tbuf_count)
			i = 0;
	} while (i != info->tbuf_current);
	reg_value = rd_reg32(info, TDCSR);
	if (reg_value & BIT0)
		total_count += active_buf_count;
	total_count += (reg_value >> 8) & 0xff;
	if (info->tx_active)
		total_count++;
	return total_count;
}