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

Commit 88e1ac5c authored by Arun Kumar Neelakantam's avatar Arun Kumar Neelakantam
Browse files

soc: qcom: smd: Support multiple of 32 SMD fifo size



In current code the SMD FIFO size is expect to be power of two
and the read_avail and write_avail calculation are based on
fifo_mask which will not work if the SMD FIFO size is not power
of two.

Add code to support SMD FIFO sizes which are multiple of 32 and
update the read_avial and write_avail code accordingly.

CRs-Fixed: 688362
Change-Id: I4425166aace6509e5f5ce75c9f949bc30a56a54a
Signed-off-by: default avatarArun Kumar Neelakantam <aneela@codeaurora.org>
parent 3dda8f02
Loading
Loading
Loading
Loading
+36 −15
Original line number Diff line number Diff line
@@ -1134,22 +1134,34 @@ void smd_channel_reset(uint32_t restart_pid)
/* how many bytes are available for reading */
static int smd_stream_read_avail(struct smd_channel *ch)
{
	return (ch->half_ch->get_head(ch->recv) -
			ch->half_ch->get_tail(ch->recv)) & ch->fifo_mask;
	unsigned head = ch->half_ch->get_head(ch->recv);
	unsigned tail = ch->half_ch->get_tail(ch->recv);
	unsigned fifo_size = ch->fifo_size;
	unsigned bytes_avail = head - tail;

	if (head < tail)
		bytes_avail += fifo_size;

	BUG_ON(bytes_avail >= fifo_size);
	return bytes_avail;
}

/* how many bytes we are free to write */
static int smd_stream_write_avail(struct smd_channel *ch)
{
	int bytes_avail;

	bytes_avail = ch->fifo_mask - ((ch->half_ch->get_head(ch->send) -
			ch->half_ch->get_tail(ch->send)) & ch->fifo_mask) + 1;
	unsigned head = ch->half_ch->get_head(ch->send);
	unsigned tail = ch->half_ch->get_tail(ch->send);
	unsigned fifo_size = ch->fifo_size;
	unsigned bytes_avail = tail - head;

	if (tail <= head)
		bytes_avail += fifo_size;
	if (bytes_avail < SMD_FIFO_FULL_RESERVE)
		bytes_avail = 0;
	else
		bytes_avail -= SMD_FIFO_FULL_RESERVE;

	BUG_ON(bytes_avail >= fifo_size);
	return bytes_avail;
}

@@ -1205,9 +1217,15 @@ static int read_intr_blocked(struct smd_channel *ch)
/* advance the fifo read pointer after data from ch_read_buffer is consumed */
static void ch_read_done(struct smd_channel *ch, unsigned count)
{
	unsigned tail = ch->half_ch->get_tail(ch->recv);
	unsigned fifo_size = ch->fifo_size;

	BUG_ON(count > smd_stream_read_avail(ch));
	ch->half_ch->set_tail(ch->recv,
		(ch->half_ch->get_tail(ch->recv) + count) & ch->fifo_mask);

	tail += count;
	if (tail >= fifo_size)
		tail -= fifo_size;
	ch->half_ch->set_tail(ch->recv, tail);
	wmb();
	ch->half_ch->set_fTAIL(ch->send,  1);
}
@@ -1319,9 +1337,14 @@ static unsigned ch_write_buffer(struct smd_channel *ch, void **ptr)
 */
static void ch_write_done(struct smd_channel *ch, unsigned count)
{
	unsigned head = ch->half_ch->get_head(ch->send);
	unsigned fifo_size = ch->fifo_size;

	BUG_ON(count > smd_stream_write_avail(ch));
	ch->half_ch->set_head(ch->send,
		(ch->half_ch->get_head(ch->send) + count) & ch->fifo_mask);
	head += count;
	if (head >= fifo_size)
		head -= fifo_size;
	ch->half_ch->set_head(ch->send, head);
	wmb();
	ch->half_ch->set_fHEAD(ch->send, 1);
}
@@ -1794,9 +1817,9 @@ static int smd_alloc(struct smd_channel *ch, int table_id,
		return -EINVAL;
	}

	/* buffer must be a power-of-two size */
	if (buffer_sz & (buffer_sz - 1)) {
		SMD_INFO("Buffer size: %u not power of two\n", buffer_sz);
	/* buffer must be a multiple of 32 size */
	if ((buffer_sz & (SZ_32 - 1)) != 0) {
		SMD_INFO("Buffer size: %u not multiple of 32\n", buffer_sz);
		return -EINVAL;
	}
	buffer_sz /= 2;
@@ -1835,8 +1858,6 @@ static int smd_alloc_channel(struct smd_alloc_elm *alloc_elm, int table_id,
		return -ENODEV;
	}

	ch->fifo_mask = ch->fifo_size - 1;

	/* probe_worker guarentees ch->type will be a valid type */
	if (ch->type == SMD_APPS_MODEM)
		ch->notify_other_cpu = notify_modem_smd;
+0 −1
Original line number Diff line number Diff line
@@ -134,7 +134,6 @@ struct smd_channel {
	unsigned char *send_data;
	unsigned char *recv_data;
	unsigned fifo_size;
	unsigned fifo_mask;
	struct list_head ch_list;

	unsigned current_packet;