/* Copyright (c) 2010-2011, Code Aurora Forum. All rights reserved.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 and
 * only version 2 as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 */

/*
 *  SDIO DMUX module.
 */

#define DEBUG

#include <linux/delay.h>
#include <linux/module.h>
#include <linux/netdevice.h>
#include <linux/platform_device.h>
#include <linux/sched.h>
#include <linux/skbuff.h>
#include <linux/wakelock.h>
#include <linux/debugfs.h>
#include <linux/smp.h>
#include <linux/cpumask.h>

#include <mach/sdio_al.h>
#include <mach/sdio_dmux.h>

#define SDIO_CH_LOCAL_OPEN       0x1
#define SDIO_CH_REMOTE_OPEN      0x2
#define SDIO_CH_IN_RESET         0x4

#define SDIO_MUX_HDR_MAGIC_NO    0x33fc

#define SDIO_MUX_HDR_CMD_DATA    0
#define SDIO_MUX_HDR_CMD_OPEN    1
#define SDIO_MUX_HDR_CMD_CLOSE   2

#define LOW_WATERMARK            2
#define HIGH_WATERMARK           4

static int msm_sdio_dmux_debug_enable;
module_param_named(debug_enable, msm_sdio_dmux_debug_enable,
		   int, S_IRUGO | S_IWUSR | S_IWGRP);

#if defined(DEBUG)
static uint32_t sdio_dmux_read_cnt;
static uint32_t sdio_dmux_write_cnt;
static uint32_t sdio_dmux_write_cpy_cnt;
static uint32_t sdio_dmux_write_cpy_bytes;

#define DBG(x...) do {		                 \
		if (msm_sdio_dmux_debug_enable)  \
			pr_debug(x);	         \
	} while (0)

#define DBG_INC_READ_CNT(x) do {	                               \
		sdio_dmux_read_cnt += (x);                             \
		if (msm_sdio_dmux_debug_enable)                        \
			pr_debug("%s: total read bytes %u\n",          \
				 __func__, sdio_dmux_read_cnt);        \
	} while (0)

#define DBG_INC_WRITE_CNT(x)  do {	                               \
		sdio_dmux_write_cnt += (x);                            \
		if (msm_sdio_dmux_debug_enable)                        \
			pr_debug("%s: total written bytes %u\n",       \
				 __func__, sdio_dmux_write_cnt);       \
	} while (0)

#define DBG_INC_WRITE_CPY(x)  do {	                                     \
		sdio_dmux_write_cpy_bytes += (x);                            \
		sdio_dmux_write_cpy_cnt++;                                   \
		if (msm_sdio_dmux_debug_enable)                              \
			pr_debug("%s: total write copy cnt %u, bytes %u\n",  \
				 __func__, sdio_dmux_write_cpy_cnt,          \
				 sdio_dmux_write_cpy_bytes);                 \
	} while (0)
#else
#define DBG(x...) do { } while (0)
#define DBG_INC_READ_CNT(x...) do { } while (0)
#define DBG_INC_WRITE_CNT(x...) do { } while (0)
#define DBG_INC_WRITE_CPY(x...) do { } while (0)
#endif

struct sdio_ch_info {
	uint32_t status;
	void (*receive_cb)(void *, struct sk_buff *);
	void (*write_done)(void *, struct sk_buff *);
	void *priv;
	spinlock_t lock;
	int num_tx_pkts;
	int use_wm;
};

static struct sk_buff_head sdio_mux_write_pool;
static spinlock_t sdio_mux_write_lock;

static struct sdio_channel *sdio_mux_ch;
static struct sdio_ch_info sdio_ch[SDIO_DMUX_NUM_CHANNELS];
struct wake_lock sdio_mux_ch_wakelock;
static int sdio_mux_initialized;
static int fatal_error;

struct sdio_mux_hdr {
	uint16_t magic_num;
	uint8_t reserved;
	uint8_t cmd;
	uint8_t pad_len;
	uint8_t ch_id;
	uint16_t pkt_len;
};

struct sdio_partial_pkt_info {
	uint32_t valid;
	struct sk_buff *skb;
	struct sdio_mux_hdr *hdr;
};

static void sdio_mux_read_data(struct work_struct *work);
static void sdio_mux_write_data(struct work_struct *work);
static void sdio_mux_send_open_cmd(uint32_t id);

static DEFINE_MUTEX(sdio_mux_lock);
static DECLARE_WORK(work_sdio_mux_read, sdio_mux_read_data);
static DECLARE_WORK(work_sdio_mux_write, sdio_mux_write_data);
static DECLARE_DELAYED_WORK(delayed_work_sdio_mux_write, sdio_mux_write_data);

static struct workqueue_struct *sdio_mux_workqueue;
static struct sdio_partial_pkt_info sdio_partial_pkt;

#define sdio_ch_is_open(x)						\
	(sdio_ch[(x)].status == (SDIO_CH_LOCAL_OPEN | SDIO_CH_REMOTE_OPEN))

#define sdio_ch_is_local_open(x)			\
	(sdio_ch[(x)].status & SDIO_CH_LOCAL_OPEN)

#define sdio_ch_is_remote_open(x)			\
	(sdio_ch[(x)].status & SDIO_CH_REMOTE_OPEN)

#define sdio_ch_is_in_reset(x)			\
	(sdio_ch[(x)].status & SDIO_CH_IN_RESET)

static inline void skb_set_data(struct sk_buff *skb,
				unsigned char *data,
				unsigned int len)
{
	/* panic if tail > end */
	skb->data = data;
	skb->tail = skb->data + len;
	skb->len  = len;
	skb->truesize = len + sizeof(struct sk_buff);
}

static void sdio_mux_save_partial_pkt(struct sdio_mux_hdr *hdr,
				      struct sk_buff *skb_mux)
{
	struct sk_buff *skb;

	/* i think we can avoid cloning here */
	skb =  skb_clone(skb_mux, GFP_KERNEL);
	if (!skb) {
		pr_err("%s: cannot clone skb\n", __func__);
		return;
	}

	/* protect? */
	skb_set_data(skb, (unsigned char *)hdr,
		     skb->tail - (unsigned char *)hdr);
	sdio_partial_pkt.skb = skb;
	sdio_partial_pkt.valid = 1;
	DBG("%s: head %p data %p tail %p end %p len %d\n", __func__,
	    skb->head, skb->data, skb->tail, skb->end, skb->len);
	return;
}

static void *handle_sdio_mux_data(struct sdio_mux_hdr *hdr,
				  struct sk_buff *skb_mux)
{
	struct sk_buff *skb;
	void *rp = (void *)hdr;
	unsigned long flags;

	/* protect? */
	rp += sizeof(*hdr);
	if (rp < (void *)skb_mux->tail)
		rp += (hdr->pkt_len + hdr->pad_len);

	if (rp > (void *)skb_mux->tail) {
		/* partial packet */
		sdio_mux_save_partial_pkt(hdr, skb_mux);
		goto packet_done;
	}

	DBG("%s: hdr %p next %p tail %p pkt_size %d\n",
	    __func__, hdr, rp, skb_mux->tail, hdr->pkt_len + hdr->pad_len);

	skb =  skb_clone(skb_mux, GFP_KERNEL);
	if (!skb) {
		pr_err("%s: cannot clone skb\n", __func__);
		goto packet_done;
	}

	skb_set_data(skb, (unsigned char *)(hdr + 1), hdr->pkt_len);
	DBG("%s: head %p data %p tail %p end %p len %d\n",
	    __func__, skb->head, skb->data, skb->tail, skb->end, skb->len);

	/* probably we should check channel status */
	/* discard packet early if local side not open */
	spin_lock_irqsave(&sdio_ch[hdr->ch_id].lock, flags);
	if (sdio_ch[hdr->ch_id].receive_cb)
		sdio_ch[hdr->ch_id].receive_cb(sdio_ch[hdr->ch_id].priv, skb);
	else
		dev_kfree_skb_any(skb);
	spin_unlock_irqrestore(&sdio_ch[hdr->ch_id].lock, flags);

packet_done:
	return rp;
}

static void *handle_sdio_mux_command(struct sdio_mux_hdr *hdr,
				     struct sk_buff *skb_mux)
{
	void *rp;
	unsigned long flags;
	int send_open = 0;

	DBG("%s: cmd %d ch %d\n", __func__, hdr->cmd, hdr->ch_id);
	switch (hdr->cmd) {
	case SDIO_MUX_HDR_CMD_DATA:
		rp = handle_sdio_mux_data(hdr, skb_mux);
		break;
	case SDIO_MUX_HDR_CMD_OPEN:
		spin_lock_irqsave(&sdio_ch[hdr->ch_id].lock, flags);
		sdio_ch[hdr->ch_id].status |= SDIO_CH_REMOTE_OPEN;
		sdio_ch[hdr->ch_id].num_tx_pkts = 0;

		if (sdio_ch_is_in_reset(hdr->ch_id)) {
			DBG("%s: in reset - sending open cmd\n", __func__);
			sdio_ch[hdr->ch_id].status &= ~SDIO_CH_IN_RESET;
			send_open = 1;
		}

		/* notify client so it can update its status */
		if (sdio_ch[hdr->ch_id].receive_cb)
			sdio_ch[hdr->ch_id].receive_cb(
					sdio_ch[hdr->ch_id].priv, NULL);

		if (sdio_ch[hdr->ch_id].write_done)
			sdio_ch[hdr->ch_id].write_done(
					sdio_ch[hdr->ch_id].priv, NULL);
		spin_unlock_irqrestore(&sdio_ch[hdr->ch_id].lock, flags);
		rp = hdr + 1;
		if (send_open)
			sdio_mux_send_open_cmd(hdr->ch_id);

		break;
	case SDIO_MUX_HDR_CMD_CLOSE:
		/* probably should drop pending write */
		spin_lock_irqsave(&sdio_ch[hdr->ch_id].lock, flags);
		sdio_ch[hdr->ch_id].status &= ~SDIO_CH_REMOTE_OPEN;
		spin_unlock_irqrestore(&sdio_ch[hdr->ch_id].lock, flags);
		rp = hdr + 1;
		break;
	default:
		rp = hdr + 1;
	}

	return rp;
}

static void *handle_sdio_partial_pkt(struct sk_buff *skb_mux)
{
	struct sk_buff *p_skb;
	struct sdio_mux_hdr *p_hdr;
	void *ptr, *rp = skb_mux->data;

	/* protoect? */
	if (sdio_partial_pkt.valid) {
		p_skb = sdio_partial_pkt.skb;

		ptr = skb_push(skb_mux, p_skb->len);
		memcpy(ptr, p_skb->data, p_skb->len);
		sdio_partial_pkt.skb = NULL;
		sdio_partial_pkt.valid = 0;
		dev_kfree_skb_any(p_skb);

		DBG("%s: head %p data %p tail %p end %p len %d\n", __func__,
		    skb_mux->head, skb_mux->data, skb_mux->tail,
		    skb_mux->end, skb_mux->len);

		p_hdr = (struct sdio_mux_hdr *)skb_mux->data;
		rp = handle_sdio_mux_command(p_hdr, skb_mux);
	}
	return rp;
}

static void sdio_mux_read_data(struct work_struct *work)
{
	struct sk_buff *skb_mux;
	void *ptr = 0;
	int sz, rc, len = 0;
	struct sdio_mux_hdr *hdr;
	static int workqueue_pinned;

	if (!workqueue_pinned) {
		struct cpumask cpus;

		cpumask_clear(&cpus);
		cpumask_set_cpu(0, &cpus);

		if (sched_setaffinity(current->pid, &cpus))
			pr_err("%s: sdio_dmux set CPU affinity failed\n",
					__func__);
		workqueue_pinned = 1;
	}

	DBG("%s: reading\n", __func__);
	/* should probably have a separate read lock */
	mutex_lock(&sdio_mux_lock);
	sz = sdio_read_avail(sdio_mux_ch);
	DBG("%s: read avail %d\n", __func__, sz);
	if (sz <= 0) {
		if (sz)
			pr_err("%s: read avail failed %d\n", __func__, sz);
		mutex_unlock(&sdio_mux_lock);
		return;
	}

	/* net_ip_aling is probably not required */
	if (sdio_partial_pkt.valid)
		len = sdio_partial_pkt.skb->len;

	/* If allocation fails attempt to get a smaller chunk of mem */
	do {
		skb_mux = __dev_alloc_skb(sz + NET_IP_ALIGN + len, GFP_KERNEL);
		if (skb_mux)
			break;

		pr_err("%s: cannot allocate skb of size:%d + "
			"%d (NET_SKB_PAD)\n", __func__,
			sz + NET_IP_ALIGN + len, NET_SKB_PAD);
		/* the skb structure adds NET_SKB_PAD bytes to the memory
		 * request, which may push the actual request above PAGE_SIZE
		 * in that case, we need to iterate one more time to make sure
		 * we get the memory request under PAGE_SIZE
		 */
		if (sz + NET_IP_ALIGN + len + NET_SKB_PAD <= PAGE_SIZE) {
			pr_err("%s: allocation failed\n", __func__);
			mutex_unlock(&sdio_mux_lock);
			return;
		}
		sz /= 2;
	} while (1);

	skb_reserve(skb_mux, NET_IP_ALIGN + len);
	ptr = skb_put(skb_mux, sz);

	/* half second wakelock is fine? */
	wake_lock_timeout(&sdio_mux_ch_wakelock, HZ / 2);
	rc = sdio_read(sdio_mux_ch, ptr, sz);
	DBG("%s: read %d\n", __func__, rc);
	if (rc) {
		pr_err("%s: sdio read failed %d\n", __func__, rc);
		dev_kfree_skb_any(skb_mux);
		mutex_unlock(&sdio_mux_lock);
		queue_work(sdio_mux_workqueue, &work_sdio_mux_read);
		return;
	}
	mutex_unlock(&sdio_mux_lock);

	DBG_INC_READ_CNT(sz);
	DBG("%s: head %p data %p tail %p end %p len %d\n", __func__,
	    skb_mux->head, skb_mux->data, skb_mux->tail,
	    skb_mux->end, skb_mux->len);

	/* move to a separate function */
	/* probably do skb_pull instead of pointer adjustment */
	hdr = handle_sdio_partial_pkt(skb_mux);
	while ((void *)hdr < (void *)skb_mux->tail) {

		if (((void *)hdr + sizeof(*hdr)) > (void *)skb_mux->tail) {
			/* handle partial header */
			sdio_mux_save_partial_pkt(hdr, skb_mux);
			break;
		}

		if (hdr->magic_num != SDIO_MUX_HDR_MAGIC_NO) {
			pr_err("%s: packet error\n", __func__);
			break;
		}

		hdr = handle_sdio_mux_command(hdr, skb_mux);
	}
	dev_kfree_skb_any(skb_mux);

	DBG("%s: read done\n", __func__);
	queue_work(sdio_mux_workqueue, &work_sdio_mux_read);
}

static int sdio_mux_write(struct sk_buff *skb)
{
	int rc, sz;

	mutex_lock(&sdio_mux_lock);
	sz = sdio_write_avail(sdio_mux_ch);
	DBG("%s: avail %d len %d\n", __func__, sz, skb->len);
	if (skb->len <= sz) {
		rc = sdio_write(sdio_mux_ch, skb->data, skb->len);
		DBG("%s: write returned %d\n", __func__, rc);
		if (rc == 0)
			DBG_INC_WRITE_CNT(skb->len);
	} else
		rc = -ENOMEM;

	mutex_unlock(&sdio_mux_lock);
	return rc;
}

static int sdio_mux_write_cmd(void *data, uint32_t len)
{
	int avail, rc;
	for (;;) {
		mutex_lock(&sdio_mux_lock);
		avail = sdio_write_avail(sdio_mux_ch);
		DBG("%s: avail %d len %d\n", __func__, avail, len);
		if (avail >= len) {
			rc = sdio_write(sdio_mux_ch, data, len);
			DBG("%s: write returned %d\n", __func__, rc);
			if (!rc) {
				DBG_INC_WRITE_CNT(len);
				break;
			}
		}
		mutex_unlock(&sdio_mux_lock);
		msleep(250);
	}
	mutex_unlock(&sdio_mux_lock);
	return 0;
}

static void sdio_mux_send_open_cmd(uint32_t id)
{
	struct sdio_mux_hdr hdr = {
		.magic_num = SDIO_MUX_HDR_MAGIC_NO,
		.cmd = SDIO_MUX_HDR_CMD_OPEN,
		.reserved = 0,
		.ch_id = id,
		.pkt_len = 0,
		.pad_len = 0
	};

	sdio_mux_write_cmd((void *)&hdr, sizeof(hdr));
}

static void sdio_mux_write_data(struct work_struct *work)
{
	int rc, reschedule = 0;
	int notify = 0;
	struct sk_buff *skb;
	unsigned long flags;
	int avail;
	int ch_id;

	spin_lock_irqsave(&sdio_mux_write_lock, flags);
	while ((skb = __skb_dequeue(&sdio_mux_write_pool))) {
		ch_id = ((struct sdio_mux_hdr *)skb->data)->ch_id;

		avail = sdio_write_avail(sdio_mux_ch);
		if (avail < skb->len) {
			/* we may have to wait for write avail
			 * notification from sdio al
			 */
			DBG("%s: sdio_write_avail(%d) < skb->len(%d)\n",
					__func__, avail, skb->len);

			reschedule = 1;
			break;
		}
		spin_unlock_irqrestore(&sdio_mux_write_lock, flags);
		rc = sdio_mux_write(skb);
		spin_lock_irqsave(&sdio_mux_write_lock, flags);
		if (rc == 0) {

			spin_lock(&sdio_ch[ch_id].lock);
			sdio_ch[ch_id].num_tx_pkts--;
			spin_unlock(&sdio_ch[ch_id].lock);

			if (sdio_ch[ch_id].write_done)
				sdio_ch[ch_id].write_done(
						sdio_ch[ch_id].priv, skb);
			else
				dev_kfree_skb_any(skb);
		} else if (rc == -EAGAIN || rc == -ENOMEM) {
			/* recoverable error - retry again later */
			reschedule = 1;
			break;
		} else if (rc == -ENODEV) {
			/*
			 * sdio_al suffered some kind of fatal error
			 * prevent future writes and clean up pending ones
			 */
			fatal_error = 1;
			do {
				ch_id = ((struct sdio_mux_hdr *)
						skb->data)->ch_id;
				spin_lock(&sdio_ch[ch_id].lock);
				sdio_ch[ch_id].num_tx_pkts--;
				spin_unlock(&sdio_ch[ch_id].lock);
				dev_kfree_skb_any(skb);
			} while ((skb = __skb_dequeue(&sdio_mux_write_pool)));
			spin_unlock_irqrestore(&sdio_mux_write_lock, flags);
			return;
		} else {
			/* unknown error condition - drop the
			 * skb and reschedule for the
			 * other skb's
			 */
			pr_err("%s: sdio_mux_write error %d"
				   " for ch %d, skb=%p\n",
				__func__, rc, ch_id, skb);
			notify = 1;
			break;
		}
	}

	if (reschedule) {
		if (sdio_ch_is_in_reset(ch_id)) {
			notify = 1;
		} else {
			__skb_queue_head(&sdio_mux_write_pool, skb);
			queue_delayed_work(sdio_mux_workqueue,
					&delayed_work_sdio_mux_write,
					msecs_to_jiffies(250)
					);
		}
	}

	if (notify) {
		spin_lock(&sdio_ch[ch_id].lock);
		sdio_ch[ch_id].num_tx_pkts--;
		spin_unlock(&sdio_ch[ch_id].lock);

		if (sdio_ch[ch_id].write_done)
			sdio_ch[ch_id].write_done(
				sdio_ch[ch_id].priv, skb);
		else
			dev_kfree_skb_any(skb);
	}
	spin_unlock_irqrestore(&sdio_mux_write_lock, flags);
}

int msm_sdio_is_channel_in_reset(uint32_t id)
{
	int rc = 0;

	if (id >= SDIO_DMUX_NUM_CHANNELS)
		return -EINVAL;

	if (sdio_ch_is_in_reset(id))
		rc = 1;

	return rc;
}

int msm_sdio_dmux_write(uint32_t id, struct sk_buff *skb)
{
	int rc = 0;
	struct sdio_mux_hdr *hdr;
	unsigned long flags;
	struct sk_buff *new_skb;

	if (id >= SDIO_DMUX_NUM_CHANNELS)
		return -EINVAL;
	if (!skb)
		return -EINVAL;
	if (!sdio_mux_initialized)
		return -ENODEV;
	if (fatal_error)
		return -ENODEV;

	DBG("%s: writing to ch %d len %d\n", __func__, id, skb->len);
	spin_lock_irqsave(&sdio_ch[id].lock, flags);
	if (sdio_ch_is_in_reset(id)) {
		spin_unlock_irqrestore(&sdio_ch[id].lock, flags);
		pr_err("%s: port is in reset: %d\n", __func__,
				sdio_ch[id].status);
		return -ENETRESET;
	}
	if (!sdio_ch_is_local_open(id)) {
		spin_unlock_irqrestore(&sdio_ch[id].lock, flags);
		pr_err("%s: port not open: %d\n", __func__, sdio_ch[id].status);
		return -ENODEV;
	}
	if (sdio_ch[id].use_wm &&
			(sdio_ch[id].num_tx_pkts >= HIGH_WATERMARK)) {
		spin_unlock_irqrestore(&sdio_ch[id].lock, flags);
		pr_err("%s: watermark exceeded: %d\n", __func__, id);
		return -EAGAIN;
	}
	spin_unlock_irqrestore(&sdio_ch[id].lock, flags);

	spin_lock_irqsave(&sdio_mux_write_lock, flags);
	/* if skb do not have any tailroom for padding,
	   copy the skb into a new expanded skb */
	if ((skb->len & 0x3) && (skb_tailroom(skb) < (4 - (skb->len & 0x3)))) {
		/* revisit, probably dev_alloc_skb and memcpy is effecient */
		new_skb = skb_copy_expand(skb, skb_headroom(skb),
					  4 - (skb->len & 0x3), GFP_ATOMIC);
		if (new_skb == NULL) {
			pr_err("%s: cannot allocate skb\n", __func__);
			rc = -ENOMEM;
			goto write_done;
		}
		dev_kfree_skb_any(skb);
		skb = new_skb;
		DBG_INC_WRITE_CPY(skb->len);
	}

	hdr = (struct sdio_mux_hdr *)skb_push(skb, sizeof(struct sdio_mux_hdr));

	/* caller should allocate for hdr and padding
	   hdr is fine, padding is tricky */
	hdr->magic_num = SDIO_MUX_HDR_MAGIC_NO;
	hdr->cmd = SDIO_MUX_HDR_CMD_DATA;
	hdr->reserved = 0;
	hdr->ch_id = id;
	hdr->pkt_len = skb->len - sizeof(struct sdio_mux_hdr);
	if (skb->len & 0x3)
		skb_put(skb, 4 - (skb->len & 0x3));

	hdr->pad_len = skb->len - (sizeof(struct sdio_mux_hdr) + hdr->pkt_len);

	DBG("%s: data %p, tail %p skb len %d pkt len %d pad len %d\n",
	    __func__, skb->data, skb->tail, skb->len,
	    hdr->pkt_len, hdr->pad_len);
	__skb_queue_tail(&sdio_mux_write_pool, skb);

	spin_lock(&sdio_ch[id].lock);
	sdio_ch[id].num_tx_pkts++;
	spin_unlock(&sdio_ch[id].lock);

	queue_work(sdio_mux_workqueue, &work_sdio_mux_write);

write_done:
	spin_unlock_irqrestore(&sdio_mux_write_lock, flags);
	return rc;
}

int msm_sdio_dmux_open(uint32_t id, void *priv,
			void (*receive_cb)(void *, struct sk_buff *),
			void (*write_done)(void *, struct sk_buff *))
{
	unsigned long flags;

	DBG("%s: opening ch %d\n", __func__, id);
	if (!sdio_mux_initialized)
		return -ENODEV;
	if (id >= SDIO_DMUX_NUM_CHANNELS)
		return -EINVAL;

	spin_lock_irqsave(&sdio_ch[id].lock, flags);
	if (sdio_ch_is_local_open(id)) {
		pr_info("%s: Already opened %d\n", __func__, id);
		spin_unlock_irqrestore(&sdio_ch[id].lock, flags);
		goto open_done;
	}

	sdio_ch[id].receive_cb = receive_cb;
	sdio_ch[id].write_done = write_done;
	sdio_ch[id].priv = priv;
	sdio_ch[id].status |= SDIO_CH_LOCAL_OPEN;
	sdio_ch[id].num_tx_pkts = 0;
	sdio_ch[id].use_wm = 0;
	spin_unlock_irqrestore(&sdio_ch[id].lock, flags);

	sdio_mux_send_open_cmd(id);

open_done:
	pr_info("%s: opened ch %d\n", __func__, id);
	return 0;
}

int msm_sdio_dmux_close(uint32_t id)
{
	struct sdio_mux_hdr hdr;
	unsigned long flags;

	if (id >= SDIO_DMUX_NUM_CHANNELS)
		return -EINVAL;
	DBG("%s: closing ch %d\n", __func__, id);
	if (!sdio_mux_initialized)
		return -ENODEV;
	spin_lock_irqsave(&sdio_ch[id].lock, flags);

	sdio_ch[id].receive_cb = NULL;
	sdio_ch[id].priv = NULL;
	sdio_ch[id].status &= ~SDIO_CH_LOCAL_OPEN;
	sdio_ch[id].status &= ~SDIO_CH_IN_RESET;
	spin_unlock_irqrestore(&sdio_ch[id].lock, flags);

	hdr.magic_num = SDIO_MUX_HDR_MAGIC_NO;
	hdr.cmd = SDIO_MUX_HDR_CMD_CLOSE;
	hdr.reserved = 0;
	hdr.ch_id = id;
	hdr.pkt_len = 0;
	hdr.pad_len = 0;

	sdio_mux_write_cmd((void *)&hdr, sizeof(hdr));

	pr_info("%s: closed ch %d\n", __func__, id);
	return 0;
}

static void sdio_mux_notify(void *_dev, unsigned event)
{
	DBG("%s: event %d notified\n", __func__, event);

	/* write avail may not be enouogh for a packet, but should be fine */
	if ((event == SDIO_EVENT_DATA_WRITE_AVAIL) &&
	    sdio_write_avail(sdio_mux_ch))
		queue_work(sdio_mux_workqueue, &work_sdio_mux_write);

	if ((event == SDIO_EVENT_DATA_READ_AVAIL) &&
	    sdio_read_avail(sdio_mux_ch))
		queue_work(sdio_mux_workqueue, &work_sdio_mux_read);
}

int msm_sdio_dmux_is_ch_full(uint32_t id)
{
	unsigned long flags;
	int ret;

	if (id >= SDIO_DMUX_NUM_CHANNELS)
		return -EINVAL;

	spin_lock_irqsave(&sdio_ch[id].lock, flags);
	sdio_ch[id].use_wm = 1;
	ret = sdio_ch[id].num_tx_pkts >= HIGH_WATERMARK;
	DBG("%s: ch %d num tx pkts=%d, HWM=%d\n", __func__,
			id, sdio_ch[id].num_tx_pkts, ret);
	if (!sdio_ch_is_local_open(id)) {
		ret = -ENODEV;
		pr_err("%s: port not open: %d\n", __func__, sdio_ch[id].status);
	}
	spin_unlock_irqrestore(&sdio_ch[id].lock, flags);

	return ret;
}

int msm_sdio_dmux_is_ch_low(uint32_t id)
{
	int ret;

	if (id >= SDIO_DMUX_NUM_CHANNELS)
		return -EINVAL;

	sdio_ch[id].use_wm = 1;
	ret = sdio_ch[id].num_tx_pkts <= LOW_WATERMARK;
	DBG("%s: ch %d num tx pkts=%d, LWM=%d\n", __func__,
			id, sdio_ch[id].num_tx_pkts, ret);
	if (!sdio_ch_is_local_open(id)) {
		ret = -ENODEV;
		pr_err("%s: port not open: %d\n", __func__, sdio_ch[id].status);
	}

	return ret;
}

#ifdef CONFIG_DEBUG_FS

static int debug_tbl(char *buf, int max)
{
	int i = 0;
	int j;

	for (j = 0; j < SDIO_DMUX_NUM_CHANNELS; ++j) {
		i += scnprintf(buf + i, max - i,
			"ch%02d  local open=%s  remote open=%s\n",
			j, sdio_ch_is_local_open(j) ? "Y" : "N",
			sdio_ch_is_remote_open(j) ? "Y" : "N");
	}

	return i;
}

#define DEBUG_BUFMAX 4096
static char debug_buffer[DEBUG_BUFMAX];

static ssize_t debug_read(struct file *file, char __user *buf,
				size_t count, loff_t *ppos)
{
	int (*fill)(char *buf, int max) = file->private_data;
	int bsize = fill(debug_buffer, DEBUG_BUFMAX);
	return simple_read_from_buffer(buf, count, ppos, debug_buffer, bsize);
}

static int debug_open(struct inode *inode, struct file *file)
{
	file->private_data = inode->i_private;
	return 0;
}


static const struct file_operations debug_ops = {
	.read = debug_read,
	.open = debug_open,
};

static void debug_create(const char *name, mode_t mode,
				struct dentry *dent,
				int (*fill)(char *buf, int max))
{
	debugfs_create_file(name, mode, dent, fill, &debug_ops);
}

#endif

static int sdio_dmux_probe(struct platform_device *pdev)
{
	int rc;

	DBG("%s probe called\n", __func__);

	if (!sdio_mux_initialized) {
		sdio_mux_workqueue = create_singlethread_workqueue("sdio_dmux");
		if (!sdio_mux_workqueue)
			return -ENOMEM;

		skb_queue_head_init(&sdio_mux_write_pool);
		spin_lock_init(&sdio_mux_write_lock);

		for (rc = 0; rc < SDIO_DMUX_NUM_CHANNELS; ++rc)
			spin_lock_init(&sdio_ch[rc].lock);


		wake_lock_init(&sdio_mux_ch_wakelock, WAKE_LOCK_SUSPEND,
				   "sdio_dmux");
	}

	rc = sdio_open("SDIO_RMNT", &sdio_mux_ch, NULL, sdio_mux_notify);
	if (rc < 0) {
		pr_err("%s: sido open failed %d\n", __func__, rc);
		wake_lock_destroy(&sdio_mux_ch_wakelock);
		destroy_workqueue(sdio_mux_workqueue);
		sdio_mux_initialized = 0;
		return rc;
	}

	fatal_error = 0;
	sdio_mux_initialized = 1;
	return 0;
}

static int sdio_dmux_remove(struct platform_device *pdev)
{
	int i;
	unsigned long ch_lock_flags;
	unsigned long write_lock_flags;
	struct sk_buff *skb;

	DBG("%s remove called\n", __func__);
	if (!sdio_mux_initialized)
		return 0;

	/* set reset state for any open channels */
	for (i = 0; i < SDIO_DMUX_NUM_CHANNELS; ++i) {
		spin_lock_irqsave(&sdio_ch[i].lock, ch_lock_flags);
		if (sdio_ch_is_open(i)) {
			sdio_ch[i].status |= SDIO_CH_IN_RESET;
			sdio_ch[i].status &= ~SDIO_CH_REMOTE_OPEN;

			/* notify client so it can update its status */
			if (sdio_ch[i].receive_cb)
				sdio_ch[i].receive_cb(
						sdio_ch[i].priv, NULL);
		}
		spin_unlock_irqrestore(&sdio_ch[i].lock, ch_lock_flags);
	}

	/* cancel any pending writes */
	spin_lock_irqsave(&sdio_mux_write_lock, write_lock_flags);
	while ((skb = __skb_dequeue(&sdio_mux_write_pool))) {
		i = ((struct sdio_mux_hdr *)skb->data)->ch_id;
		if (sdio_ch[i].write_done)
			sdio_ch[i].write_done(
					sdio_ch[i].priv, skb);
		else
			dev_kfree_skb_any(skb);
	}
	spin_unlock_irqrestore(&sdio_mux_write_lock,
			write_lock_flags);

	return 0;
}

static struct platform_driver sdio_dmux_driver = {
	.probe		= sdio_dmux_probe,
	.remove   = sdio_dmux_remove,
	.driver		= {
		.name	= "SDIO_RMNT",
		.owner	= THIS_MODULE,
	},
};

static int __init sdio_dmux_init(void)
{
#ifdef CONFIG_DEBUG_FS
	struct dentry *dent;

	dent = debugfs_create_dir("sdio_dmux", 0);
	if (!IS_ERR(dent))
		debug_create("tbl", 0444, dent, debug_tbl);
#endif
	return platform_driver_register(&sdio_dmux_driver);
}

module_init(sdio_dmux_init);
MODULE_DESCRIPTION("MSM SDIO DMUX");
MODULE_LICENSE("GPL v2");
