usb: gadget: modify gserial and grmnet structures

Rename send_cpkt_request to send_encap_cmd & send_cbits_tomodem
to notify_modem.
Update notify_modem and send_encap_cmd functions' parameter to
void pointer.
Remove struct grmnet pointer parameter from send_encap_cmd
function.

Above changes are done to come up with generic callbacks registered
by transport drivers for both the structures.

Change-Id: I149386186d42a5c77adca2da2a7b4bdcf4c01e88
Signed-off-by: Hemant Kumar <hemantk@codeaurora.org>
diff --git a/drivers/usb/gadget/f_rmnet.c b/drivers/usb/gadget/f_rmnet.c
index 7686bf2..db43f95 100644
--- a/drivers/usb/gadget/f_rmnet.c
+++ b/drivers/usb/gadget/f_rmnet.c
@@ -466,16 +466,24 @@
 }
 
 static int
-frmnet_send_cpkt_response(struct grmnet *gr, struct rmnet_ctrl_pkt *cpkt)
+frmnet_send_cpkt_response(void *gr, void *buf, size_t len)
 {
 	struct f_rmnet		*dev;
+	struct rmnet_ctrl_pkt	*cpkt;
 	unsigned long		flags;
 
-	if (!gr || !cpkt) {
-		pr_err("%s: Invalid grmnet/cpkt, grmnet:%p cpkt:%p\n",
-				__func__, gr, cpkt);
+	if (!gr || !buf) {
+		pr_err("%s: Invalid grmnet/buf, grmnet:%p buf:%p\n",
+				__func__, gr, buf);
 		return -ENODEV;
 	}
+	cpkt = rmnet_alloc_ctrl_pkt(len, GFP_ATOMIC);
+	if (IS_ERR(cpkt)) {
+		pr_err("%s: Unable to allocate ctrl pkt\n", __func__);
+		return -ENOMEM;
+	}
+	memcpy(cpkt->buf, buf, len);
+	cpkt->len = len;
 
 	dev = port_to_rmnet(gr);
 
@@ -500,7 +508,6 @@
 {
 	struct f_rmnet			*dev = req->context;
 	struct usb_composite_dev	*cdev;
-	struct rmnet_ctrl_pkt		*cpkt;
 
 	if (!dev) {
 		pr_err("%s: rmnet dev is null\n", __func__);
@@ -511,16 +518,8 @@
 
 	cdev = dev->cdev;
 
-	cpkt = rmnet_alloc_ctrl_pkt(req->actual, GFP_ATOMIC);
-	if (IS_ERR(cpkt)) {
-		pr_err("%s: Unable to allocate ctrl pkt\n", __func__);
-		return;
-	}
-
-	memcpy(cpkt->buf, req->buf, req->actual);
-
-	if (dev->port.send_cpkt_request)
-		dev->port.send_cpkt_request(&dev->port, dev->port_num, cpkt);
+	if (dev->port.send_encap_cmd)
+		dev->port.send_encap_cmd(dev->port_num, req->buf, req->actual);
 }
 
 static void frmnet_notify_complete(struct usb_ep *ep, struct usb_request *req)
@@ -615,8 +614,8 @@
 		break;
 	case ((USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE) << 8)
 			| USB_CDC_REQ_SET_CONTROL_LINE_STATE:
-		if (dev->port.send_cbits_tomodem)
-			dev->port.send_cbits_tomodem(&dev->port,
+		if (dev->port.notify_modem)
+			dev->port.notify_modem(&dev->port,
 							dev->port_num,
 							w_value);
 		ret = 0;
diff --git a/drivers/usb/gadget/u_rmnet.h b/drivers/usb/gadget/u_rmnet.h
index 3c21316..d8de31e 100644
--- a/drivers/usb/gadget/u_rmnet.h
+++ b/drivers/usb/gadget/u_rmnet.h
@@ -35,19 +35,14 @@
 	/* to usb host, aka laptop, windows pc etc. Will
 	 * be filled by usb driver of rmnet functionality
 	 */
-	int (*send_cpkt_response)(struct grmnet *g,
-				struct rmnet_ctrl_pkt *pkt);
+	int (*send_cpkt_response)(void *g, void *buf, size_t len);
 
 	/* to modem, and to be filled by driver implementing
 	 * control function
 	 */
-	int (*send_cpkt_request)(struct grmnet *g,
-				u8 port_num,
-				struct rmnet_ctrl_pkt *pkt);
+	int (*send_encap_cmd)(u8 port_num, void *buf, size_t len);
 
-	void (*send_cbits_tomodem)(struct grmnet *g,
-				u8 port_num,
-				int cbits);
+	void (*notify_modem)(void *g, u8 port_num, int cbits);
 
 	void (*disconnect)(struct grmnet *g);
 	void (*connect)(struct grmnet *g);
diff --git a/drivers/usb/gadget/u_rmnet_ctrl_smd.c b/drivers/usb/gadget/u_rmnet_ctrl_smd.c
index fc159cc..8b08b7a 100644
--- a/drivers/usb/gadget/u_rmnet_ctrl_smd.c
+++ b/drivers/usb/gadget/u_rmnet_ctrl_smd.c
@@ -83,6 +83,7 @@
 		kfree(pkt);
 		return ERR_PTR(-ENOMEM);
 	}
+
 	pkt->len = len;
 
 	return pkt;
@@ -103,7 +104,8 @@
 	struct smd_ch_info *c = container_of(w, struct smd_ch_info, read_w);
 	struct rmnet_ctrl_port *port = c->port;
 	int sz;
-	struct rmnet_ctrl_pkt *cpkt;
+	size_t len;
+	void *buf;
 	unsigned long flags;
 
 	while (1) {
@@ -114,22 +116,20 @@
 		if (smd_read_avail(c->ch) < sz)
 			break;
 
-		cpkt = alloc_rmnet_ctrl_pkt(sz, GFP_KERNEL);
-		if (IS_ERR(cpkt)) {
-			pr_err("%s: unable to allocate rmnet control pkt\n",
-					__func__);
+		buf = kmalloc(sz, GFP_KERNEL);
+		if (!buf)
 			return;
-		}
-		cpkt->len = smd_read(c->ch, cpkt->buf, sz);
+
+		len = smd_read(c->ch, buf, sz);
 
 		/* send it to USB here */
 		spin_lock_irqsave(&port->port_lock, flags);
 		if (port->port_usb && port->port_usb->send_cpkt_response) {
-			port->port_usb->send_cpkt_response(
-							port->port_usb,
-							cpkt);
+			port->port_usb->send_cpkt_response(port->port_usb,
+							buf, len);
 			c->to_host++;
 		}
+		kfree(buf);
 		spin_unlock_irqrestore(&port->port_lock, flags);
 	}
 }
@@ -157,8 +157,7 @@
 		ret = smd_write(c->ch, cpkt->buf, cpkt->len);
 		spin_lock_irqsave(&port->port_lock, flags);
 		if (ret != cpkt->len) {
-			pr_err("%s: smd_write failed err:%d\n",
-					__func__, ret);
+			pr_err("%s: smd_write failed err:%d\n", __func__, ret);
 			free_rmnet_ctrl_pkt(cpkt);
 			break;
 		}
@@ -169,24 +168,29 @@
 }
 
 static int
-grmnet_ctrl_smd_send_cpkt_tomodem(struct grmnet *gr, u8 portno,
-			struct rmnet_ctrl_pkt *cpkt)
+grmnet_ctrl_smd_send_cpkt_tomodem(u8 portno,
+	void *buf, size_t len)
 {
 	unsigned long		flags;
 	struct rmnet_ctrl_port	*port;
 	struct smd_ch_info	*c;
+	struct rmnet_ctrl_pkt *cpkt;
 
 	if (portno >= n_rmnet_ctrl_ports) {
 		pr_err("%s: Invalid portno#%d\n", __func__, portno);
 		return -ENODEV;
 	}
 
-	if (!gr) {
-		pr_err("%s: grmnet is null\n", __func__);
-		return -ENODEV;
+	port = ctrl_smd_ports[portno].port;
+
+	cpkt = alloc_rmnet_ctrl_pkt(len, GFP_ATOMIC);
+	if (IS_ERR(cpkt)) {
+		pr_err("%s: Unable to allocate ctrl pkt\n", __func__);
+		return -ENOMEM;
 	}
 
-	port = ctrl_smd_ports[portno].port;
+	memcpy(cpkt->buf, buf, len);
+	cpkt->len = len;
 
 	spin_lock_irqsave(&port->port_lock, flags);
 	c = &port->ctrl_ch;
@@ -207,7 +211,7 @@
 
 #define RMNET_CTRL_DTR		0x01
 static void
-gsmd_ctrl_send_cbits_tomodem(struct grmnet *gr, u8 portno, int cbits)
+gsmd_ctrl_send_cbits_tomodem(void *gptr, u8 portno, int cbits)
 {
 	struct rmnet_ctrl_port	*port;
 	struct smd_ch_info	*c;
@@ -220,7 +224,7 @@
 		return;
 	}
 
-	if (!gr) {
+	if (!gptr) {
 		pr_err("%s: grmnet is null\n", __func__);
 		return;
 	}
@@ -362,8 +366,8 @@
 
 	spin_lock_irqsave(&port->port_lock, flags);
 	port->port_usb = gr;
-	gr->send_cpkt_request = grmnet_ctrl_smd_send_cpkt_tomodem;
-	gr->send_cbits_tomodem = gsmd_ctrl_send_cbits_tomodem;
+	gr->send_encap_cmd = grmnet_ctrl_smd_send_cpkt_tomodem;
+	gr->notify_modem = gsmd_ctrl_send_cbits_tomodem;
 	spin_unlock_irqrestore(&port->port_lock, flags);
 
 	queue_work(grmnet_ctrl_wq, &port->connect_w);
@@ -395,8 +399,8 @@
 
 	spin_lock_irqsave(&port->port_lock, flags);
 	port->port_usb = 0;
-	gr->send_cpkt_request = 0;
-	gr->send_cbits_tomodem = 0;
+	gr->send_encap_cmd = 0;
+	gr->notify_modem = 0;
 	c->cbits_tomodem = 0;
 
 	while (!list_empty(&c->tx_q)) {
diff --git a/drivers/usb/gadget/u_sdio.c b/drivers/usb/gadget/u_sdio.c
index 6ba7543..9bd4370 100644
--- a/drivers/usb/gadget/u_sdio.c
+++ b/drivers/usb/gadget/u_sdio.c
@@ -639,10 +639,11 @@
 			port->cbits_to_modem, ~(port->cbits_to_modem));
 }
 
-void gsdio_ctrl_notify_modem(struct gserial *gser, u8 portno, int ctrl_bits)
+void gsdio_ctrl_notify_modem(void *gptr, u8 portno, int ctrl_bits)
 {
 	struct gsdio_port *port;
 	int temp;
+	struct gserial *gser = gptr;
 
 	if (portno >= n_sdio_ports) {
 		pr_err("%s: invalid portno#%d\n", __func__, portno);
diff --git a/drivers/usb/gadget/u_serial.h b/drivers/usb/gadget/u_serial.h
index fea53d8..c937006 100644
--- a/drivers/usb/gadget/u_serial.h
+++ b/drivers/usb/gadget/u_serial.h
@@ -55,7 +55,7 @@
 	int (*send_modem_ctrl_bits)(struct gserial *p, int ctrl_bits);
 
 	/* notification changes to modem */
-	void (*notify_modem)(struct gserial *gser, u8 portno, int ctrl_bits);
+	void (*notify_modem)(void *gser, u8 portno, int ctrl_bits);
 };
 
 /* utilities to allocate/free request and buffer */
diff --git a/drivers/usb/gadget/u_smd.c b/drivers/usb/gadget/u_smd.c
index 60826b9..caccade 100644
--- a/drivers/usb/gadget/u_smd.c
+++ b/drivers/usb/gadget/u_smd.c
@@ -579,10 +579,11 @@
 	}
 }
 
-static void gsmd_notify_modem(struct gserial *gser, u8 portno, int ctrl_bits)
+static void gsmd_notify_modem(void *gptr, u8 portno, int ctrl_bits)
 {
 	struct gsmd_port *port;
 	int temp;
+	struct gserial *gser = gptr;
 
 	if (portno >= n_smd_ports) {
 		pr_err("%s: invalid portno#%d\n", __func__, portno);