Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit f5dcb3e0 authored by Vijayavardhan Vennapusa's avatar Vijayavardhan Vennapusa
Browse files

usb_bam: Allocate 512 bytes more than actual data fifo size



On some platforms which uses USB 2.0 Chip idea controller, AXI
prefetch feature(APF) is added to support higher data rates. This
APF feature requires additional 128 bytes alloactated at the end of
circular buffer which is not used. Hence allocate additional 512
bytes than required data fifo size as per hardware programming guide.

Change-Id: I9d45d4aabfd3b163ffd2cd05939c8c2db7adfdd9
Signed-off-by: default avatarVijayavardhan Vennapusa <vvreddy@codeaurora.org>
parent e0110676
Loading
Loading
Loading
Loading
+42 −9
Original line number Diff line number Diff line
@@ -38,6 +38,9 @@

#define USB_BAM_NR_PORTS	4

/* Additional memory to be allocated than required data fifo size */
#define DATA_FIFO_EXTRA_MEM_ALLOC_SIZE 512

#define ARRAY_INDEX_FROM_ADDR(base, addr) ((addr) - (base))

#define ENABLE_EVENT_LOG 1
@@ -367,7 +370,21 @@ static int usb_bam_alloc_buffer(struct usb_bam_pipe_connect *pipe_connect)
		log_event(1, "%s: USB BAM using system memory\n", __func__);
		/* BAM would use system memory, allocate FIFOs */
		data_buf->size = pipe_connect->data_fifo_size;
		data_buf->base = dma_alloc_coherent(&ctx->usb_bam_pdev->dev,
		/* On platforms which use CI controller, USB HW can fetch
		 * additional 128 bytes at the end of circular buffer when
		 * AXI prefetch is enabled and hence requirement is to
		 * allocate 512 bytes more than required length.
		 */
		if (pipe_connect->bam_type == CI_CTRL)
			data_buf->base =
				dma_alloc_coherent(&ctx->usb_bam_pdev->dev,
				(pipe_connect->data_fifo_size +
					DATA_FIFO_EXTRA_MEM_ALLOC_SIZE),
				&(data_buf->phys_base),
				GFP_KERNEL);
		else
			data_buf->base =
				dma_alloc_coherent(&ctx->usb_bam_pdev->dev,
				pipe_connect->data_fifo_size,
				&(data_buf->phys_base),
				GFP_KERNEL);
@@ -387,8 +404,16 @@ static int usb_bam_alloc_buffer(struct usb_bam_pipe_connect *pipe_connect)
		if (!desc_buf->base) {
			pr_err("%s: dma_alloc_coherent failed for desc fifo\n",
								__func__);
			if (pipe_connect->bam_type == CI_CTRL)
				dma_free_coherent(&ctx->usb_bam_pdev->dev,
			pipe_connect->data_fifo_size, data_buf->base,
				(pipe_connect->data_fifo_size +
					DATA_FIFO_EXTRA_MEM_ALLOC_SIZE),
				data_buf->base,
				data_buf->phys_base);
			else
				dma_free_coherent(&ctx->usb_bam_pdev->dev,
				pipe_connect->data_fifo_size,
				data_buf->base,
				data_buf->phys_base);
			ret = -ENOMEM;
			goto err_exit;
@@ -709,11 +734,19 @@ static int disconnect_pipe(enum usb_ctrl cur_bam, u8 idx)
	case SYSTEM_MEM:
		log_event(1, "%s: Freeing system memory used by PIPE\n",
				__func__);
		if (sps_connection->data.phys_base)
		if (sps_connection->data.phys_base) {
			if (cur_bam == CI_CTRL)
				dma_free_coherent(&ctx->usb_bam_pdev->dev,
					(sps_connection->data.size +
						DATA_FIFO_EXTRA_MEM_ALLOC_SIZE),
					sps_connection->data.base,
					sps_connection->data.phys_base);
			else
				dma_free_coherent(&ctx->usb_bam_pdev->dev,
					sps_connection->data.size,
					sps_connection->data.base,
					sps_connection->data.phys_base);
		}
		if (sps_connection->desc.phys_base)
			dma_free_coherent(&ctx->usb_bam_pdev->dev,
					sps_connection->desc.size,