/*
 * Copyright (c) 2005 Ammasso, Inc. All rights reserved.
 * Copyright (c) 2005 Open Grid Computing, Inc. All rights reserved.
 *
 * This software is available to you under a choice of one of two
 * licenses.  You may choose to be licensed under the terms of the GNU
 * General Public License (GPL) Version 2, available from the file
 * COPYING in the main directory of this source tree, or the
 * OpenIB.org BSD license below:
 *
 *     Redistribution and use in source and binary forms, with or
 *     without modification, are permitted provided that the following
 *     conditions are met:
 *
 *      - Redistributions of source code must retain the above
 *        copyright notice, this list of conditions and the following
 *        disclaimer.
 *
 *      - Redistributions in binary form must reproduce the above
 *        copyright notice, this list of conditions and the following
 *        disclaimer in the documentation and/or other materials
 *        provided with the distribution.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */
#include "c2.h"
#include "c2_mq.h"

void *c2_mq_alloc(struct c2_mq *q)
{
	BUG_ON(q->magic != C2_MQ_MAGIC);
	BUG_ON(q->type != C2_MQ_ADAPTER_TARGET);

	if (c2_mq_full(q)) {
		return NULL;
	} else {
#ifdef DEBUG
		struct c2wr_hdr *m =
		    (struct c2wr_hdr *) (q->msg_pool.host + q->priv * q->msg_size);
#ifdef CCMSGMAGIC
		BUG_ON(m->magic != be32_to_cpu(~CCWR_MAGIC));
		m->magic = cpu_to_be32(CCWR_MAGIC);
#endif
		return m;
#else
		return q->msg_pool.host + q->priv * q->msg_size;
#endif
	}
}

void c2_mq_produce(struct c2_mq *q)
{
	BUG_ON(q->magic != C2_MQ_MAGIC);
	BUG_ON(q->type != C2_MQ_ADAPTER_TARGET);

	if (!c2_mq_full(q)) {
		q->priv = (q->priv + 1) % q->q_size;
		q->hint_count++;
		/* Update peer's offset. */
		__raw_writew(cpu_to_be16(q->priv), &q->peer->shared);
	}
}

void *c2_mq_consume(struct c2_mq *q)
{
	BUG_ON(q->magic != C2_MQ_MAGIC);
	BUG_ON(q->type != C2_MQ_HOST_TARGET);

	if (c2_mq_empty(q)) {
		return NULL;
	} else {
#ifdef DEBUG
		struct c2wr_hdr *m = (struct c2wr_hdr *)
		    (q->msg_pool.host + q->priv * q->msg_size);
#ifdef CCMSGMAGIC
		BUG_ON(m->magic != be32_to_cpu(CCWR_MAGIC));
#endif
		return m;
#else
		return q->msg_pool.host + q->priv * q->msg_size;
#endif
	}
}

void c2_mq_free(struct c2_mq *q)
{
	BUG_ON(q->magic != C2_MQ_MAGIC);
	BUG_ON(q->type != C2_MQ_HOST_TARGET);

	if (!c2_mq_empty(q)) {

#ifdef CCMSGMAGIC
		{
			struct c2wr_hdr __iomem *m = (struct c2wr_hdr __iomem *)
			    (q->msg_pool.adapter + q->priv * q->msg_size);
			__raw_writel(cpu_to_be32(~CCWR_MAGIC), &m->magic);
		}
#endif
		q->priv = (q->priv + 1) % q->q_size;
		/* Update peer's offset. */
		__raw_writew(cpu_to_be16(q->priv), &q->peer->shared);
	}
}


void c2_mq_lconsume(struct c2_mq *q, u32 wqe_count)
{
	BUG_ON(q->magic != C2_MQ_MAGIC);
	BUG_ON(q->type != C2_MQ_ADAPTER_TARGET);

	while (wqe_count--) {
		BUG_ON(c2_mq_empty(q));
		*q->shared = cpu_to_be16((be16_to_cpu(*q->shared)+1) % q->q_size);
	}
}

#if 0
u32 c2_mq_count(struct c2_mq *q)
{
	s32 count;

	if (q->type == C2_MQ_HOST_TARGET)
		count = be16_to_cpu(*q->shared) - q->priv;
	else
		count = q->priv - be16_to_cpu(*q->shared);

	if (count < 0)
		count += q->q_size;

	return (u32) count;
}
#endif  /*  0  */

void c2_mq_req_init(struct c2_mq *q, u32 index, u32 q_size, u32 msg_size,
		    u8 __iomem *pool_start, u16 __iomem *peer, u32 type)
{
	BUG_ON(!q->shared);

	/* This code assumes the byte swapping has already been done! */
	q->index = index;
	q->q_size = q_size;
	q->msg_size = msg_size;
	q->msg_pool.adapter = pool_start;
	q->peer = (struct c2_mq_shared __iomem *) peer;
	q->magic = C2_MQ_MAGIC;
	q->type = type;
	q->priv = 0;
	q->hint_count = 0;
	return;
}
void c2_mq_rep_init(struct c2_mq *q, u32 index, u32 q_size, u32 msg_size,
		    u8 *pool_start, u16 __iomem *peer, u32 type)
{
	BUG_ON(!q->shared);

	/* This code assumes the byte swapping has already been done! */
	q->index = index;
	q->q_size = q_size;
	q->msg_size = msg_size;
	q->msg_pool.host = pool_start;
	q->peer = (struct c2_mq_shared __iomem *) peer;
	q->magic = C2_MQ_MAGIC;
	q->type = type;
	q->priv = 0;
	q->hint_count = 0;
	return;
}
