msm: bam_dmux: consolidate callback functions
Consolidate the multiple client callback function into a single callback
that is able to handle multiple event types. This minimizes API changes
for future event types.
Signed-off-by: Jeffrey Hugo <jhugo@codeaurora.org>
diff --git a/arch/arm/mach-msm/bam_dmux.c b/arch/arm/mach-msm/bam_dmux.c
index 667016d..62a3dded 100644
--- a/arch/arm/mach-msm/bam_dmux.c
+++ b/arch/arm/mach-msm/bam_dmux.c
@@ -87,8 +87,7 @@
struct bam_ch_info {
uint32_t status;
- void (*receive_cb)(void *, struct sk_buff *);
- void (*write_done)(void *, struct sk_buff *);
+ void (*notify)(void *, int, unsigned long);
void *priv;
spinlock_t lock;
};
@@ -188,6 +187,7 @@
{
unsigned long flags;
struct bam_mux_hdr *rx_hdr;
+ unsigned long event_data;
rx_hdr = (struct bam_mux_hdr *)rx_skb->data;
@@ -195,10 +195,13 @@
rx_skb->tail = rx_skb->data + rx_hdr->pkt_len;
rx_skb->len = rx_hdr->pkt_len;
+ event_data = (unsigned long)(rx_skb);
+
spin_lock_irqsave(&bam_ch[rx_hdr->ch_id].lock, flags);
- if (bam_ch[rx_hdr->ch_id].receive_cb)
- bam_ch[rx_hdr->ch_id].receive_cb(bam_ch[rx_hdr->ch_id].priv,
- rx_skb);
+ if (bam_ch[rx_hdr->ch_id].notify)
+ bam_ch[rx_hdr->ch_id].notify(
+ bam_ch[rx_hdr->ch_id].priv, BAM_DMUX_RECEIVE,
+ event_data);
else
dev_kfree_skb_any(rx_skb);
spin_unlock_irqrestore(&bam_ch[rx_hdr->ch_id].lock, flags);
@@ -302,15 +305,18 @@
struct sk_buff *skb;
struct bam_mux_hdr *hdr;
struct tx_pkt_info *info;
+ unsigned long event_data;
info = container_of(work, struct tx_pkt_info, work);
skb = info->skb;
kfree(info);
hdr = (struct bam_mux_hdr *)skb->data;
DBG_INC_WRITE_CNT(skb->data_len);
- if (bam_ch[hdr->ch_id].write_done)
- bam_ch[hdr->ch_id].write_done(
- bam_ch[hdr->ch_id].priv, skb);
+ event_data = (unsigned long)(skb);
+ if (bam_ch[hdr->ch_id].notify)
+ bam_ch[hdr->ch_id].notify(
+ bam_ch[hdr->ch_id].priv, BAM_DMUX_WRITE_DONE,
+ event_data);
else
dev_kfree_skb_any(skb);
}
@@ -400,8 +406,7 @@
}
int msm_bam_dmux_open(uint32_t id, void *priv,
- void (*receive_cb)(void *, struct sk_buff *),
- void (*write_done)(void *, struct sk_buff *))
+ void (*notify)(void *, int, unsigned long))
{
struct bam_mux_hdr *hdr;
unsigned long flags;
@@ -412,6 +417,8 @@
return -ENODEV;
if (id >= BAM_DMUX_NUM_CHANNELS)
return -EINVAL;
+ if (notify == NULL)
+ return -EINVAL;
hdr = kmalloc(sizeof(struct bam_mux_hdr), GFP_KERNEL);
if (hdr == NULL) {
@@ -433,8 +440,7 @@
goto open_done;
}
- bam_ch[id].receive_cb = receive_cb;
- bam_ch[id].write_done = write_done;
+ bam_ch[id].notify = notify;
bam_ch[id].priv = priv;
bam_ch[id].status |= BAM_CH_LOCAL_OPEN;
spin_unlock_irqrestore(&bam_ch[id].lock, flags);
@@ -466,8 +472,7 @@
return -ENODEV;
spin_lock_irqsave(&bam_ch[id].lock, flags);
- bam_ch[id].write_done = NULL;
- bam_ch[id].receive_cb = NULL;
+ bam_ch[id].notify = NULL;
bam_ch[id].priv = NULL;
bam_ch[id].status &= ~BAM_CH_LOCAL_OPEN;
spin_unlock_irqrestore(&bam_ch[id].lock, flags);
diff --git a/arch/arm/mach-msm/include/mach/bam_dmux.h b/arch/arm/mach-msm/include/mach/bam_dmux.h
index d4c6652..415c06a 100644
--- a/arch/arm/mach-msm/include/mach/bam_dmux.h
+++ b/arch/arm/mach-msm/include/mach/bam_dmux.h
@@ -47,16 +47,16 @@
*/
#ifdef CONFIG_MSM_BAM_DMUX
int msm_bam_dmux_open(uint32_t id, void *priv,
- void (*receive_cb)(void *, struct sk_buff *),
- void (*write_done)(void *, struct sk_buff *));
+ void (*notify)(void *priv, int event_type,
+ unsigned long data));
int msm_bam_dmux_close(uint32_t id);
int msm_bam_dmux_write(uint32_t id, struct sk_buff *skb);
#else
int msm_bam_dmux_open(uint32_t id, void *priv,
- void (*receive_cb)(void *, struct sk_buff *),
- void (*write_done)(void *, struct sk_buff *))
+ void (*notify)(void *priv, int event_type,
+ unsigned long data))
{
return -ENODEV;
}
diff --git a/drivers/net/msm_rmnet_bam.c b/drivers/net/msm_rmnet_bam.c
index a8bdeb3..5397cbf 100644
--- a/drivers/net/msm_rmnet_bam.c
+++ b/drivers/net/msm_rmnet_bam.c
@@ -335,6 +335,18 @@
netif_wake_queue(dev);
}
+static void bam_notify(void *dev, int event, unsigned long data)
+{
+ switch (event) {
+ case BAM_DMUX_RECEIVE:
+ bam_recv_notify(dev, (struct sk_buff *)(data));
+ break;
+ case BAM_DMUX_WRITE_DONE:
+ bam_write_done(dev, (struct sk_buff *)(data));
+ break;
+ }
+}
+
static int __rmnet_open(struct net_device *dev)
{
int r;
@@ -343,8 +355,7 @@
DBG0("[%s] __rmnet_open()\n", dev->name);
if (!p->device_up) {
- r = msm_bam_dmux_open(p->ch_id, dev,
- bam_recv_notify, bam_write_done);
+ r = msm_bam_dmux_open(p->ch_id, dev, bam_notify);
if (r < 0)
return -ENODEV;
diff --git a/drivers/usb/gadget/u_bam.c b/drivers/usb/gadget/u_bam.c
index e44b339..0c87e3e88 100644
--- a/drivers/usb/gadget/u_bam.c
+++ b/drivers/usb/gadget/u_bam.c
@@ -490,15 +490,25 @@
gbam_start_rx(port);
}
+static void gbam_notify(void *p, int event, unsigned long data)
+{
+ switch (event) {
+ case BAM_DMUX_RECEIVE:
+ gbam_data_recv_cb(p, (struct sk_buff *)(data));
+ break;
+ case BAM_DMUX_WRITE_DONE:
+ gbam_data_write_done(p, (struct sk_buff *)(data));
+ break;
+ }
+}
+
static void gbam_connect_work(struct work_struct *w)
{
struct gbam_port *port = container_of(w, struct gbam_port, connect_w);
struct bam_ch_info *d = &port->data_ch;
int ret;
- ret = msm_bam_dmux_open(d->id, port,
- gbam_data_recv_cb,
- gbam_data_write_done);
+ ret = msm_bam_dmux_open(d->id, port, gbam_notify);
if (ret) {
pr_err("%s: unable open bam ch:%d err:%d\n",
__func__, d->id, ret);