Skip to contentSkip to conversation

staging: gdm7240: adding LTE USB driver

PATCH Superseded Won Kang 5 participants 16 messages Jul 22, 2013 – Jul 25, 2013 Staging

lore
Share & tools
lore

Won Kang

author
#0 lore raw

PATCH 1/2 staging: gdm7240: adding LTE USB driver

GCT Semiconductor GDM7240 is 4G LTE chip.
This driver supports GCT reference platform as a USB device.

---
 drivers/staging/Kconfig              |    2 +
 drivers/staging/Makefile             |    1 +
 drivers/staging/gdm724x/Kconfig      |    9 +
 drivers/staging/gdm724x/Makefile     |    9 +
 drivers/staging/gdm724x/TODO         |    2 +
 drivers/staging/gdm724x/gdm_endian.c |   69 ++
 drivers/staging/gdm724x/gdm_endian.h |   49 ++
 drivers/staging/gdm724x/gdm_lte.c    | 1152 ++++++++++++++++++++++++++++++++++
 drivers/staging/gdm724x/gdm_lte.h    |   93 +++
 drivers/staging/gdm724x/gdm_mux.c    |  789 +++++++++++++++++++++++
 drivers/staging/gdm724x/gdm_mux.h    |   77 +++
 drivers/staging/gdm724x/gdm_tty.c    |  382 +++++++++++
 drivers/staging/gdm724x/gdm_tty.h    |   63 ++
 drivers/staging/gdm724x/gdm_usb.c    | 1105 ++++++++++++++++++++++++++++++++
 drivers/staging/gdm724x/gdm_usb.h    |   92 +++
 drivers/staging/gdm724x/hci.h        |   55 ++
 drivers/staging/gdm724x/hci_packet.h |   97 +++
 drivers/staging/gdm724x/lte_ioctl.h  |   73 +++
 drivers/staging/gdm724x/netlink_k.c  |  161 +++++
 drivers/staging/gdm724x/netlink_k.h  |   25 +
 20 files changed, 4305 insertions(+)
 create mode 100644 drivers/staging/gdm724x/Kconfig
 create mode 100644 drivers/staging/gdm724x/Makefile
 create mode 100644 drivers/staging/gdm724x/TODO
 create mode 100644 drivers/staging/gdm724x/gdm_endian.c
 create mode 100644 drivers/staging/gdm724x/gdm_endian.h
 create mode 100644 drivers/staging/gdm724x/gdm_lte.c
 create mode 100644 drivers/staging/gdm724x/gdm_lte.h
 create mode 100644 drivers/staging/gdm724x/gdm_mux.c
 create mode 100644 drivers/staging/gdm724x/gdm_mux.h
 create mode 100644 drivers/staging/gdm724x/gdm_tty.c
 create mode 100644 drivers/staging/gdm724x/gdm_tty.h
 create mode 100644 drivers/staging/gdm724x/gdm_usb.c
 create mode 100644 drivers/staging/gdm724x/gdm_usb.h
 create mode 100644 drivers/staging/gdm724x/hci.h
 create mode 100644 drivers/staging/gdm724x/hci_packet.h
 create mode 100644 drivers/staging/gdm724x/lte_ioctl.h
 create mode 100644 drivers/staging/gdm724x/netlink_k.c
 create mode 100644 drivers/staging/gdm724x/netlink_k.h
drivers/staging/Kconfig +2 -0
index 57d8b34..d55bc34 100644
@@ -118,6 +118,8 @@ source "drivers/staging/ozwpan/Kconfig"
 
 source "drivers/staging/gdm72xx/Kconfig"
 
+source "drivers/staging/gdm724x/Kconfig"
+
 source "drivers/staging/silicom/Kconfig"
 
 source "drivers/staging/ced1401/Kconfig"
drivers/staging/Makefile +1 -0
index 429321f..c23cf3b 100644
@@ -52,6 +52,7 @@ obj-$(CONFIG_MFD_NVEC)		+= nvec/
 obj-$(CONFIG_ANDROID)		+= android/
 obj-$(CONFIG_USB_WPAN_HCD)	+= ozwpan/
 obj-$(CONFIG_WIMAX_GDM72XX)	+= gdm72xx/
+obj-$(CONFIG_LTE_GDM724X)	+= gdm724x/
 obj-$(CONFIG_NET_VENDOR_SILICOM)	+= silicom/
 obj-$(CONFIG_CED1401)		+= ced1401/
 obj-$(CONFIG_DRM_IMX)		+= imx-drm/
drivers/staging/gdm724x/Kconfig new file +9 -0
new file mode 100644
index 0000000..84b35d7
@@ -0,0 +1,9 @@
+#
+# GCT GDM724x LTE driver configuration
+#
+
+config LTE_GDM724X
+	tristate "GCT GDM724x LTE support"
+	depends on NET && USB
+	help
+	  Support for the GCT GDM724x LTE chip
drivers/staging/gdm724x/Makefile new file +9 -0
new file mode 100644
index 0000000..4ee5426
@@ -0,0 +1,9 @@
+obj-$(CONFIG_LTE_GDM724X) := gdmulte.o
+gdmulte-y += gdm_lte.o netlink_k.o
+gdmulte-y += gdm_usb.o gdm_endian.o
+
+obj-$(CONFIG_LTE_GDM724X) += gdmtty.o
+gdmtty-y := gdm_tty.o gdm_mux.o
+
+EXTRA_CFLAGS += -DLTE_USB_PM
+
drivers/staging/gdm724x/TODO new file +2 -0
new file mode 100644
index 0000000..b9e1177
@@ -0,0 +1,2 @@
+TODO:
+- Clean up coding style to meet kernel standard.
\ No newline at end of file
drivers/staging/gdm724x/gdm_endian.c new file +69 -0

69 lines not on this page · raw message

drivers/staging/gdm724x/gdm_endian.h new file +49 -0

49 lines not on this page · raw message

drivers/staging/gdm724x/gdm_lte.c new file +1152 -0

1,152 lines not on this page · raw message

drivers/staging/gdm724x/gdm_lte.h new file +93 -0

93 lines not on this page · raw message

drivers/staging/gdm724x/gdm_mux.c new file +789 -0

789 lines not on this page · raw message

drivers/staging/gdm724x/gdm_mux.h new file +77 -0

77 lines not on this page · raw message

drivers/staging/gdm724x/gdm_tty.c new file +382 -0

382 lines not on this page · raw message

drivers/staging/gdm724x/gdm_tty.h new file +63 -0

63 lines not on this page · raw message

drivers/staging/gdm724x/gdm_usb.c new file +1105 -0

290 lines not on this page · raw message

drivers/staging/gdm724x/gdm_usb.h new file +92 -0

92 lines not on this page · raw message

drivers/staging/gdm724x/hci.h new file +55 -0

55 lines not on this page · raw message

drivers/staging/gdm724x/hci_packet.h new file +97 -0

97 lines not on this page · raw message

drivers/staging/gdm724x/lte_ioctl.h new file +73 -0

73 lines not on this page · raw message

drivers/staging/gdm724x/netlink_k.c new file +161 -0

161 lines not on this page · raw message

drivers/staging/gdm724x/netlink_k.h new file +25 -0
new file mode 100644
index 0000000..589486d

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Signature · 1 line
1.7.10.4

Part of the diff is not shown here. View the raw message.

author
#1 lore raw

PATCH 2/2 staging: gdm7240: added contacts for code maintanance

---
 drivers/staging/gdm724x/TODO |    6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/staging/gdm724x/TODO +5 -1
index b9e1177..dba5823 100644
@@ -1,2 +1,6 @@
 TODO:
-- Clean up coding style to meet kernel standard.
\ No newline at end of file
+- Clean up coding style to meet kernel standard.
+
+Patches to:
+	Jonathan Kim <[email protected]>
+	Dean ahn <[email protected]>
Signature · 1 line
1.7.10.4
#2 lore raw

Re: [PATCH 2/2] staging: gdm7240: added contacts for code maintanance

On Mon, 2013-07-22 at 15:56 +0900, Won Kang wrote:
[]

drivers/staging/gdm724x/TODO

Quoted 1 line
drivers/staging/gdm724x/TODO +0 -0

[]

drivers/staging/gdm724x/TODO line 6

Quoted 9 lines
drivers/staging/gdm724x/TODO +5 -1
@@ -1,2 +1,6 @@
 TODO:
-- Clean up coding style to meet kernel standard.
\ No newline at end of file
+- Clean up coding style to meet kernel standard.
+
+Patches to:
+	Jonathan Kim <[email protected]>
+	Dean ahn <[email protected]>

It would be better to add a MAINTAINERS section entry.

maintainer
#3 lore raw

Re: [PATCH 2/2] staging: gdm7240: added contacts for code maintanance

Quoted 4 lines · Joe Perches

On Mon, 2013-07-22 at 15:56 +0900, Won Kang wrote:
[]

drivers/staging/gdm724x/TODO

Quoted 1 line
drivers/staging/gdm724x/TODO +0 -0

[]

Quoted 11 lines

drivers/staging/gdm724x/TODO line 6

Quoted 9 lines
drivers/staging/gdm724x/TODO +5 -1
@@ -1,2 +1,6 @@
 TODO:
-- Clean up coding style to meet kernel standard.
\ No newline at end of file
+- Clean up coding style to meet kernel standard.
+
+Patches to:
+	Jonathan Kim <[email protected]>
+	Dean ahn <[email protected]>

It would be better to add a MAINTAINERS section entry.

Yes, but I don't require it, this is good enough for now.

thanks,

greg k-h

#4 lore raw
In reply to Won Kang
Quoted 3 lines · Won Kang

GCT Semiconductor GDM7240 is 4G LTE chip.
This driver supports GCT reference platform as a USB device.

Really I don't think this driver needs to go through staging. I reviewed it a bit and there is plenty to comment on, but it's not that far off in terms of style. The networking people will have a lot more comments on this.

By the end, I really hated the custom endian macros and the funny jumbled function endings and the bad placement of the curly braces on list_for_each() loops. Also all the ifdefs. I hated the ifdefs. I didn't totally finish because I figured it would be easier to review once the obvious small things were fixed. But in the end this driver is not bad. I say fix the things I mentioned and then see what the people on [email protected] have to say. That's going to be the stricter review.

When I reviewed it, I only commented on the first example of a mistake. Go through and fix all similar places.

regards,
dan carpenter

drivers/staging/gdm724x/Kconfig line 9

Quoted 10 lines
drivers/staging/gdm724x/Kconfig new file +9 -0
@@ -0,0 +1,9 @@
+#
+# GCT GDM724x LTE driver configuration
+#
+
+config LTE_GDM724X
+	tristate "GCT GDM724x LTE support"
+	depends on NET && USB
+	help
+	  Support for the GCT GDM724x LTE chip

Not very descriptive.

Quoted 6 lines
drivers/staging/gdm724x/Makefile new file +0 -0
new file mode 100644
index 0000000..4ee5426

drivers/staging/gdm724x/Makefile line 8

Quoted 8 lines
drivers/staging/gdm724x/Makefile new file +8 -0
@@ -0,0 +1,9 @@
+obj-$(CONFIG_LTE_GDM724X) := gdmulte.o
+gdmulte-y += gdm_lte.o netlink_k.o
+gdmulte-y += gdm_usb.o gdm_endian.o
+
+obj-$(CONFIG_LTE_GDM724X) += gdmtty.o
+gdmtty-y := gdm_tty.o gdm_mux.o
+
+EXTRA_CFLAGS += -DLTE_USB_PM

Just delete this and the related ifdefs.

drivers/staging/gdm724x/gdm_endian.c

Quoted 2 lines
drivers/staging/gdm724x/gdm_endian.c new file +0 -0

The endian stuff should not test for host endian and the functions need to be renamed.

drivers/staging/gdm724x/gdm_endian.c line 45

Quoted 7 lines
drivers/staging/gdm724x/gdm_endian.c new file +7 -0
+u16 H2D(struct gdm_endian *ed, u16 x)
+{
+	if (ed->dev_ed == ed->host_ed)
+		return x;
+
+	return Endian16_Swap(x);
+}

This should be:
u16 gdm_dev16_to_cpu(struct gdm_endian *ed, u16 val)

{
	if (ed->dev_ed == BIG_ENDIAN)
		return be16_to_cpu((__be16)val);
	else
		return le16_to_cpu((__be16)val);
}

etc.

drivers/staging/gdm724x/gdm_endian.c

Quoted 12 lines
drivers/staging/gdm724x/gdm_endian.c new file +12 -0
+#define gdm_dev_endian(n) (\
+	n->phy_dev->get_endian(n->phy_dev->priv_dev))
+
+#define gdm_lte_hci_send(n, d, l) (\
+	n->phy_dev->send_hci_func(n->phy_dev->priv_dev, d, l, NULL, NULL))
+
+#define gdm_lte_sdu_send(n, d, l, c, b, i, t) (\
+	n->phy_dev->send_sdu_func(n->phy_dev->priv_dev, d, l, n->pdn_table.dft_eps_id, 0, c, b, i, t))
+
+#define gdm_lte_rcv_with_cb(n, c, b, e) (\
+	n->rcv_func(n->priv_dev, c, b, e))
+

These macros are nasty and only used once. Delete them.

drivers/staging/gdm724x/gdm_endian.c

Quoted 5 lines
drivers/staging/gdm724x/gdm_endian.c new file +5 -0
+static void tx_complete(void *arg)
+{
+	struct nic *nic = arg;
+
+	if (nic == NULL) {

This can't happen. Don't test for stuff that can't happen.

Quoted 5 lines
drivers/staging/gdm724x/gdm_endian.c new file +5 -0
+		printk(KERN_ERR "glte: tx complete - invalid nic\n");
+		return;
+	}
+
+	if (netif_queue_stopped(nic->netdev))

drivers/staging/gdm724x/gdm_endian.c

Quoted 10 lines
drivers/staging/gdm724x/gdm_endian.c new file +10 -0
+		netif_wake_queue(nic->netdev);
+}
+
+static int gdm_lte_rx(struct sk_buff *skb, struct nic *nic, int nic_type)
+{
+	int ret;
+
+	if (nic == NULL) {
+		printk(KERN_ERR "glte: rx - invalid nic\n");
+		return -1;

1) Don't test for things which can't happen.
2) Use pr_err()
3) Don't return -1 ever (almost). You just use the english error codes. In this case -1 is -EPERM.

drivers/staging/gdm724x/gdm_endian.c

Quoted 5 lines
drivers/staging/gdm724x/gdm_endian.c new file +5 -0
+	}
+
+	ret = netif_rx_ni(skb);
+	if (ret == NET_RX_DROP) {
+		printk(KERN_ERR "glte: rx - dropped\n");

Don't print KERN_ERR for dropped packets.

drivers/staging/gdm724x/gdm_endian.c

Quoted 10 lines
drivers/staging/gdm724x/gdm_endian.c new file +10 -0
+		nic->stats.rx_dropped++;
+	} else {
+		nic->stats.rx_packets++;
+		nic->stats.rx_bytes += skb->len + ETH_HLEN;
+	}
+
+	return 0;
+}
+
+#ifdef EMULATE_ARP

This is always defined. Delete the #ifdef check.

Quoted 20 lines
drivers/staging/gdm724x/gdm_endian.c new file +20 -0
+int gdm_lte_emulate_arp(struct sk_buff *skb_in, u32 nic_type)
+{
+	struct nic *nic = netdev_priv(skb_in->dev);
+	struct sk_buff *skb_out;
+	struct ethhdr eth;
+	struct vlan_ethhdr vlan_eth;
+	struct arphdr *arp_in;
+	struct arphdr *arp_out;
+	struct arpdata {
+		u8 ar_sha[ETH_ALEN];
+		u8 ar_sip[4];
+		u8 ar_tha[ETH_ALEN];
+		u8 ar_tip[4];
+	};
+	struct arpdata *arp_data_in;
+	struct arpdata *arp_data_out;
+	u8 arp_temp[60];
+	void *mac_header_data;
+	u32 mac_header_len;
+

drivers/staging/gdm724x/gdm_endian.c

Quoted 10 lines
drivers/staging/gdm724x/gdm_endian.c new file +10 -0
+	/* Format the mac header so that it can be put to skb */
+	if (ntohs(((struct ethhdr *)skb_in->data)->h_proto) == ETH_P_8021Q) {
+		memcpy(&vlan_eth, skb_in->data, sizeof(struct vlan_ethhdr));
+		mac_header_data = &vlan_eth;
+		mac_header_len = VLAN_ETH_HLEN;
+	} else {
+		memcpy(&eth, skb_in->data, sizeof(struct ethhdr));
+		mac_header_data = &eth;
+		mac_header_len = ETH_HLEN;
+	}

I'm not a networking person but if feels like we should check that skb->len is large enough. Otherwise we read past the end which is a potential info leak and we might not reserve enough memory for the reply which is memory corruption.

Quoted 56 lines
drivers/staging/gdm724x/gdm_endian.c new file +56 -0
+
+	/* Get the pointer of the original request */
+	arp_in = (struct arphdr *)(skb_in->data + mac_header_len);
+	arp_data_in = (struct arpdata *)(skb_in->data + mac_header_len + sizeof(struct arphdr));
+
+	/* Get the pointer of the outgoing response */
+	arp_out = (struct arphdr *)arp_temp;
+	arp_data_out = (struct arpdata *)(arp_temp + sizeof(struct arphdr));
+
+	/* Copy the arp header */
+	memcpy(arp_out, arp_in, sizeof(struct arphdr));
+	arp_out->ar_op = htons(ARPOP_REPLY);
+
+	/* Copy the arp payload: based on 2 bytes of mac and fill the IP */
+	arp_data_out->ar_sha[0] = arp_data_in->ar_sha[0];
+	arp_data_out->ar_sha[1] = arp_data_in->ar_sha[1];
+	memcpy(&arp_data_out->ar_sha[2], &arp_data_in->ar_tip[0], 4);
+	memcpy(&arp_data_out->ar_sip[0], &arp_data_in->ar_tip[0], 4);
+	memcpy(&arp_data_out->ar_tha[0], &arp_data_in->ar_sha[0], 6);
+	memcpy(&arp_data_out->ar_tip[0], &arp_data_in->ar_sip[0], 4);
+
+	/* Fill the destination mac with source mac of the received packet */
+	memcpy(mac_header_data, mac_header_data + ETH_ALEN, ETH_ALEN);
+	/* Fill the source mac with nic's source mac */
+	memcpy(mac_header_data + ETH_ALEN, nic->src_mac_addr, ETH_ALEN);
+
+	/* Alloc skb and reserve align */
+	skb_out = dev_alloc_skb(skb_in->len);
+	if (!skb_out)
+		return -1;
+	skb_reserve(skb_out, NET_IP_ALIGN);
+
+	memcpy(skb_put(skb_out, mac_header_len), mac_header_data, mac_header_len);
+	memcpy(skb_put(skb_out, sizeof(struct arphdr)), arp_out, sizeof(struct arphdr));
+	memcpy(skb_put(skb_out, sizeof(struct arpdata)), arp_data_out, sizeof(struct arpdata));
+
+	skb_out->protocol = ((struct ethhdr *)mac_header_data)->h_proto;
+	skb_out->dev = skb_in->dev;
+	skb_reset_mac_header(skb_out);
+	skb_pull(skb_out, ETH_HLEN);
+
+	gdm_lte_rx(skb_out, nic, nic_type);
+
+	return 0;
+}
+#endif
+
+#ifdef EMULATE_NDP
+int icmp6_checksum(struct ipv6hdr *ipv6, u16 *ptr, int len)
+{
+	unsigned short *w = ptr;
+	int sum = 0;
+	int i;
+
+	#pragma pack(1)
+	union {

drivers/staging/gdm724x/gdm_endian.c

Quoted 10 lines
drivers/staging/gdm724x/gdm_endian.c new file +10 -0
+		struct {
+			u8 ph_src[16];
+			u8 ph_dst[16];
+			u32 ph_len;
+			u8 ph_zero[3];
+			u8 ph_nxt;
+		} ph;
+		u16 pa[20];
+	} pseudo_header;
+	#pragma pack()

Use the __packed macro.

	union {
		struct {
			u8 ph_src[16];
			u8 ph_dst[16];
			u32 ph_len;
			u8 ph_zero[3];
			u8 ph_nxt;
		} ph;
		u16 pa[20];
	} pseudo_header __packed;
Quoted 280 lines
drivers/staging/gdm724x/gdm_endian.c new file +280 -0
+
+	memset(&pseudo_header, 0, sizeof(pseudo_header));
+	memcpy(&pseudo_header.ph.ph_src, &ipv6->saddr.in6_u.u6_addr8, 16);
+	memcpy(&pseudo_header.ph.ph_dst, &ipv6->daddr.in6_u.u6_addr8, 16);
+	pseudo_header.ph.ph_len = ipv6->payload_len;
+	pseudo_header.ph.ph_nxt = ipv6->nexthdr;
+
+	w = (u16 *)&pseudo_header;
+	for (i = 0; i < sizeof(pseudo_header.pa) / sizeof(pseudo_header.pa[0]); i++)
+		sum += pseudo_header.pa[i];
+
+	w = ptr;
+	while (len > 1) {
+		sum += *w++;
+		len -= 2;
+	}
+
+	sum = (sum >> 16) + (sum & 0xFFFF);
+	sum += (sum >> 16);
+	sum = ~sum & 0xffff;
+
+	return sum;
+}
+
+int gdm_lte_emulate_ndp(struct sk_buff *skb_in, u32 nic_type)
+{
+	struct nic *nic = netdev_priv(skb_in->dev);
+	struct sk_buff *skb_out;
+	struct ethhdr eth;
+	struct vlan_ethhdr vlan_eth;
+	struct neighbour_advertisement {
+		u8 target_address[16];
+		u8 type;
+		u8 length;
+		u8 link_layer_address[6];
+	};
+	struct neighbour_advertisement na;
+	struct neighbour_solicitation {
+		u8 target_address[16];
+	};
+	struct neighbour_solicitation *ns;
+	struct ipv6hdr *ipv6_in;
+	struct ipv6hdr ipv6_out;
+	struct icmp6hdr *icmp6_in;
+	struct icmp6hdr icmp6_out;
+
+	void *mac_header_data;
+	u32 mac_header_len;
+
+	/* Format the mac header so that it can be put to skb */
+	if (ntohs(((struct ethhdr *)skb_in->data)->h_proto) == ETH_P_8021Q) {
+		memcpy(&vlan_eth, skb_in->data, sizeof(struct vlan_ethhdr));
+		if (ntohs(vlan_eth.h_vlan_encapsulated_proto) != ETH_P_IPV6)
+			return -1;
+		mac_header_data = &vlan_eth;
+		mac_header_len = VLAN_ETH_HLEN;
+	} else {
+		memcpy(&eth, skb_in->data, sizeof(struct ethhdr));
+		if (ntohs(eth.h_proto) != ETH_P_IPV6)
+			return -1;
+		mac_header_data = &eth;
+		mac_header_len = ETH_HLEN;
+	}
+
+
+	/* Check if this is IPv6 ICMP packet */
+	ipv6_in = (struct ipv6hdr *)(skb_in->data + mac_header_len);
+	if (ipv6_in->version != 6 || ipv6_in->nexthdr != IPPROTO_ICMPV6)
+		return -1;
+
+	/* Check if this is NDP packet */
+	icmp6_in = (struct icmp6hdr *)(skb_in->data + mac_header_len + sizeof(struct ipv6hdr));
+	if (icmp6_in->icmp6_type == NDISC_ROUTER_SOLICITATION) { /* Check RS */
+		return -1;
+	} else if (icmp6_in->icmp6_type == NDISC_NEIGHBOUR_SOLICITATION) { /* Check NS */
+		u8 icmp_na[sizeof(struct icmp6hdr) + sizeof(struct neighbour_advertisement)];
+		u8 zero_addr8[16] = {0,};
+
+		if (memcmp(ipv6_in->saddr.in6_u.u6_addr8, zero_addr8, 16) == 0)
+			/* Duplicate Address Detection: Source IP is all zero */
+			return 0;
+
+		icmp6_out.icmp6_type = NDISC_NEIGHBOUR_ADVERTISEMENT;
+		icmp6_out.icmp6_code = 0;
+		icmp6_out.icmp6_cksum = 0;
+		icmp6_out.icmp6_dataun.un_data32[0] = htonl(0x60000000); /* R=0, S=1, O=1 */
+
+		ns = (struct neighbour_solicitation *)(skb_in->data + mac_header_len + sizeof(struct ipv6hdr) + sizeof(struct icmp6hdr));
+		memcpy(&na.target_address, ns->target_address, 16);
+		na.type = 0x02;
+		na.length = 1;
+		na.link_layer_address[0] = 0x00;
+		na.link_layer_address[1] = 0x0a;
+		na.link_layer_address[2] = 0x3b;
+		na.link_layer_address[3] = 0xaf;
+		na.link_layer_address[4] = 0x63;
+		na.link_layer_address[5] = 0xc7;
+
+		memcpy(&ipv6_out, ipv6_in, sizeof(struct ipv6hdr));
+		memcpy(ipv6_out.saddr.in6_u.u6_addr8, &na.target_address, 16);
+		memcpy(ipv6_out.daddr.in6_u.u6_addr8, ipv6_in->saddr.in6_u.u6_addr8, 16);
+		ipv6_out.payload_len = htons(sizeof(struct icmp6hdr) + sizeof(struct neighbour_advertisement));
+
+		memcpy(icmp_na, &icmp6_out, sizeof(struct icmp6hdr));
+		memcpy(icmp_na + sizeof(struct icmp6hdr), &na, sizeof(struct neighbour_advertisement));
+
+		icmp6_out.icmp6_cksum = icmp6_checksum(&ipv6_out, (u16 *)icmp_na, sizeof(icmp_na));
+	} else {
+		return -1;
+	}
+
+	/* Fill the destination mac with source mac of the received packet */
+	memcpy(mac_header_data, mac_header_data + ETH_ALEN, ETH_ALEN);
+	/* Fill the source mac with nic's source mac */
+	memcpy(mac_header_data + ETH_ALEN, nic->src_mac_addr, ETH_ALEN);
+
+	/* Alloc skb and reserve align */
+	skb_out = dev_alloc_skb(skb_in->len);
+	if (!skb_out)
+		return -1;
+	skb_reserve(skb_out, NET_IP_ALIGN);
+
+	memcpy(skb_put(skb_out, mac_header_len), mac_header_data, mac_header_len);
+	memcpy(skb_put(skb_out, sizeof(struct ipv6hdr)), &ipv6_out, sizeof(struct ipv6hdr));
+	memcpy(skb_put(skb_out, sizeof(struct icmp6hdr)), &icmp6_out, sizeof(struct icmp6hdr));
+	memcpy(skb_put(skb_out, sizeof(struct neighbour_advertisement)), &na, sizeof(struct neighbour_advertisement));
+
+	skb_out->protocol = ((struct ethhdr *)mac_header_data)->h_proto;
+	skb_out->dev = skb_in->dev;
+	skb_reset_mac_header(skb_out);
+	skb_pull(skb_out, ETH_HLEN);
+
+	gdm_lte_rx(skb_out, nic, nic_type);
+
+	return 0;
+}
+#endif
+
+static s32 gdm_lte_tx_nic_type(struct net_device *dev, struct sk_buff *skb)
+{
+	struct nic *nic = netdev_priv(dev);
+	struct ethhdr *eth;
+	struct vlan_ethhdr *vlan_eth;
+	struct iphdr *ip;
+	struct ipv6hdr *ipv6;
+	int mac_proto;
+	void *network_data;
+	u32 nic_type = 0;
+
+	if (nic == NULL)
+		return -1;
+
+	if (nic->nic_id >= MAX_NIC_TYPE)
+		return -1;
+
+	/* NIC TYPE is based on the nic_id of this net_device */
+	nic_type = 0x00000010 | nic->nic_id;
+
+	/* Get ethernet protocol */
+	eth = (struct ethhdr *)skb->data;
+	if (ntohs(eth->h_proto) == ETH_P_8021Q) {
+		vlan_eth = (struct vlan_ethhdr *)skb->data;
+		mac_proto = ntohs(vlan_eth->h_vlan_encapsulated_proto);
+		network_data = skb->data + VLAN_ETH_HLEN;
+		nic_type |= NIC_TYPE_F_VLAN;
+	} else {
+		mac_proto = ntohs(eth->h_proto);
+		network_data = skb->data + ETH_HLEN;
+	}
+
+	/* Process packet for nic type */
+	switch (mac_proto) {
+	case ETH_P_ARP:
+		nic_type |= NIC_TYPE_ARP;
+		break;
+	case ETH_P_IP:
+		nic_type |= NIC_TYPE_F_IPV4;
+		ip = (struct iphdr *)network_data;
+
+		/* Check DHCPv4 */
+		if (ip->protocol == IPPROTO_UDP) {
+			struct udphdr *udp = (struct udphdr *)(network_data + sizeof(struct iphdr));
+			if (ntohs(udp->dest) == 67 || ntohs(udp->dest) == 68)
+				nic_type |= NIC_TYPE_F_DHCP;
+		}
+		break;
+	case ETH_P_IPV6:
+		nic_type |= NIC_TYPE_F_IPV6;
+		ipv6 = (struct ipv6hdr *)network_data;
+
+		if (ipv6->nexthdr == IPPROTO_ICMPV6) /* Check NDP request */ {
+			struct icmp6hdr *icmp6 = (struct icmp6hdr *)(network_data + sizeof(struct ipv6hdr));
+			if (/*icmp6->icmp6_type == NDISC_ROUTER_SOLICITATION || */
+				icmp6->icmp6_type == NDISC_NEIGHBOUR_SOLICITATION)
+				nic_type |= NIC_TYPE_ICMPV6;
+		} else if (ipv6->nexthdr == IPPROTO_UDP) /* Check DHCPv6 */ {
+			struct udphdr *udp = (struct udphdr *)(network_data + sizeof(struct ipv6hdr));
+			if (ntohs(udp->dest) == 546 || ntohs(udp->dest) == 547)
+				nic_type |= NIC_TYPE_F_DHCP;
+		}
+		break;
+	default:
+		return -1;
+		break;
+	}
+
+	return nic_type;
+}
+
+static int gdm_lte_tx(struct sk_buff *skb, struct net_device *dev)
+{
+	struct nic *nic = netdev_priv(dev);
+	u32 nic_type;
+	void *data_buf;
+	int data_len;
+	int idx;
+	int ret = 0;
+
+	nic_type = gdm_lte_tx_nic_type(dev, skb);
+	if (nic_type == 0) {
+		printk(KERN_ERR "glte: tx - invalid nic_type\n");
+		return -1;
+	}
+
+#ifdef EMULATE_ARP
+	if (nic_type & NIC_TYPE_ARP) {
+		if (gdm_lte_emulate_arp(skb, nic_type) == 0) {
+			dev_kfree_skb(skb);
+			return 0;
+		}
+	}
+#endif
+
+#ifdef EMULATE_NDP
+	if (nic_type & NIC_TYPE_ICMPV6) {
+		if (gdm_lte_emulate_ndp(skb, nic_type) == 0) {
+			dev_kfree_skb(skb);
+			return 0;
+		}
+	}
+#endif
+
+	/*
+	Need byte shift (that is, remove VLAN tag) if there is one
+	For the case of ARP, this breaks the offset as vlan_ethhdr+4 is treated as ethhdr
+	However, it shouldn't be a problem as the reponse starts from arp_hdr and ethhdr
+	is created by this driver based on the NIC mac
+	*/
+	if (nic_type & NIC_TYPE_F_VLAN) {
+		struct vlan_ethhdr *vlan_eth = (struct vlan_ethhdr *)skb->data;
+		nic->vlan_id = ntohs(vlan_eth->h_vlan_TCI) & VLAN_VID_MASK;
+		data_buf = skb->data + (VLAN_ETH_HLEN - ETH_HLEN);
+		data_len = skb->len - (VLAN_ETH_HLEN - ETH_HLEN);
+	} else {
+		nic->vlan_id = 0;
+		data_buf = skb->data;
+		data_len = skb->len;
+	}
+
+	/* If it is a ICMPV6 packet, clear all the other bits : for backward compatibilty with the firmware */
+	if (nic_type & NIC_TYPE_ICMPV6)
+		nic_type = NIC_TYPE_ICMPV6;
+
+	/* If it is not a dhcp packet, clear all the flag bits : original NIC, otherwise the special flag (IPVX | DHCP) */
+	if (!(nic_type & NIC_TYPE_F_DHCP))
+		nic_type &= NIC_TYPE_MASK;
+
+	sscanf(dev->name, "lte%d", &idx);
+
+	ret = gdm_lte_sdu_send(nic,
+			       data_buf,
+			       data_len,
+			       tx_complete,
+			       nic,
+			       idx,
+			       nic_type);
+
+	if (ret == TX_NO_BUFFER || ret == TX_NO_SPC) {
+		netif_stop_queue(dev);
+		if (ret == TX_NO_BUFFER)

drivers/staging/gdm724x/gdm_endian.c

Quoted 10 lines
drivers/staging/gdm724x/gdm_endian.c new file +10 -0
+			ret = 0;
+		else
+			ret = -ENOSPC;
+	} else if (ret == TX_NO_DEV) {
+		ret = -ENODEV;
+	}
+
+	/* Updates tx stats */
+	if (ret) {
+		printk(KERN_ERR "glte: tx - sending sdu failed\n");

Don't DoS the system by filling /var/log/messages with noise.

Quoted 23 lines
drivers/staging/gdm724x/gdm_endian.c new file +23 -0
+		nic->stats.tx_dropped++;
+	} else {
+		nic->stats.tx_packets++;
+		nic->stats.tx_bytes += data_len;
+	}
+	dev_kfree_skb(skb);
+
+	return 0;
+}
+
+static struct net_device_stats *gdm_lte_stats(struct net_device *dev)
+{
+	struct nic *nic = netdev_priv(dev);
+	return &nic->stats;
+}
+
+static void get_network_statics(struct data_t *data, struct net_device *dev)
+{
+	struct nic *nic = netdev_priv(dev);
+	struct phy_dev *pdev = nic->phy_dev;
+	unsigned char *buf;
+	struct net_info_t *net_stats;
+	struct net_info_t *net_stats_requested = (struct net_info_t *)data->buf;

drivers/staging/gdm724x/gdm_endian.c

Quoted 10 lines
drivers/staging/gdm724x/gdm_endian.c new file +10 -0
+	int i;
+	unsigned long ret;
+
+	buf = kmalloc(sizeof(*net_stats), GFP_KERNEL);
+	if (!buf)
+		return;
+
+	memset(buf, 0, sizeof(*net_stats));
+
+	net_stats = (struct net_info_t *)buf;

Don't use "buf", and use kzalloc() instead of kmalloc(). This function should return a negative value on error.

	struct net_info_t *net_stats;

	net_stats = kzalloc(sizeof(*net_stats), GFP_KERNEL);
	if (!net_stats)
		return -ENOMEM;

	net_stats->nic_index = net_stats_requested->nic_index;

Actually this whole function is part of a custom ioctl and it should be replaced with normal networking stats function. Look it up. Don't make Ben Hutchings have to be the only one who knows how mii-tool works. :P

Quoted 25 lines
drivers/staging/gdm724x/gdm_endian.c new file +25 -0
+	net_stats->nic_index = net_stats_requested->nic_index;
+
+	if (net_stats->nic_index > MAX_NIC_TYPE) {
+		printk(KERN_INFO "glte: stats - invalid nic_index\n");
+		kfree(buf);
+		return;
+	}
+
+	if (net_stats->nic_index == MAX_NIC_TYPE) {
+		for (i = 0; i < MAX_NIC_TYPE; i++) {
+			nic = netdev_priv(pdev->dev[i]);
+			net_stats->stats.tx_packets += nic->stats.tx_packets;
+			net_stats->stats.tx_bytes += nic->stats.tx_bytes;
+			net_stats->stats.tx_dropped += nic->stats.tx_dropped;
+			net_stats->stats.rx_packets += nic->stats.rx_packets;
+			net_stats->stats.rx_bytes += nic->stats.rx_bytes;
+			net_stats->stats.rx_dropped += nic->stats.rx_dropped;
+		}
+	} else {
+		nic = netdev_priv(pdev->dev[net_stats->nic_index]);
+		net_stats->stats.tx_packets = nic->stats.tx_packets;
+		net_stats->stats.tx_bytes = nic->stats.tx_bytes;
+		net_stats->stats.tx_dropped = nic->stats.tx_dropped;
+		net_stats->stats.rx_packets = nic->stats.rx_packets;
+		net_stats->stats.rx_bytes = nic->stats.rx_bytes;

drivers/staging/gdm724x/gdm_endian.c

Quoted 10 lines
drivers/staging/gdm724x/gdm_endian.c new file +10 -0
+		net_stats->stats.rx_dropped = nic->stats.rx_dropped;
+	}
+
+	ret = copy_to_user(data->buf, buf, sizeof(*net_stats));
+	if (ret)
+		printk(KERN_INFO "glte: state - failed to copy\n");
+	kfree(buf);
+}
+
+static int get_ver(u8 *src, u8 *dst)

Use MODULE_VERSION() and delete this part of the ioctl. Basically we hate every custom ioctl. Delete it all.

Quoted 37 lines
drivers/staging/gdm724x/gdm_endian.c new file +37 -0
+{
+	u8 tmp_buf[4] = {0,};
+	int i = 0;
+
+	while (1) {
+		if (dst[i] < '0' || dst[i] > '9')
+			break;
+
+		tmp_buf[i] = dst[i] % 0x30;
+		i++;
+	}
+
+	if (i == 1)
+		*src = tmp_buf[0];
+	else if (i == 2)
+		*src = (tmp_buf[0] * 10) + tmp_buf[1];
+	else if (i == 3)
+		*src = (tmp_buf[0] * 100) + (tmp_buf[1] * 10) + tmp_buf[3];
+
+	return i;
+}
+
+static void get_driver_version(struct data_t *data, struct net_device *dev)
+{
+	u8 ver[16] = {0,};
+	u8 drv_ver[4] = {0,};
+	int i = 0;
+	int j = 0;
+	unsigned long ret;
+
+	memcpy(ver, DRIVER_VERSION, sizeof(DRIVER_VERSION));
+
+	while (i < sizeof(DRIVER_VERSION)) {
+		if (ver[i] != '.') {
+			i += get_ver(&drv_ver[j], &ver[i]);
+			j++;
+		} else {

drivers/staging/gdm724x/gdm_endian.c

Quoted 10 lines
drivers/staging/gdm724x/gdm_endian.c new file +10 -0
+			i++;
+		}
+
+		if (j == 4)
+			break;
+	}
+
+	ret = copy_to_user(data->buf, drv_ver, sizeof(drv_ver));
+	if (ret)
+		printk(KERN_INFO "glte: state - failed to copy\n");

The error handling here sucks but we're going to delete this anyway.

Quoted 75 lines
drivers/staging/gdm724x/gdm_endian.c new file +75 -0
+}
+
+static void get_dev_endian(struct data_t *data, struct net_device *dev)
+{
+	struct nic *nic = netdev_priv(dev);
+	unsigned long ret;
+	
+	ret = copy_to_user(data->buf, gdm_dev_endian(nic), sizeof(struct dev_endian_t));
+	if (ret)
+		printk(KERN_INFO "glte: state - failed to copy\n");
+}
+
+static int gdm_lte_ioctl_get_data(struct wm_req_t *req, struct net_device *dev)
+{
+	u16 id = req->data_id;
+
+	switch (id) {
+	case GET_NETWORK_STATICS:
+		get_network_statics(&req->data, dev);
+		break;
+	case GET_DRV_VER:
+		get_driver_version(&req->data, dev);
+		break;
+	case GET_ENDIAN_INFO:
+		get_dev_endian(&req->data, dev);
+		break;
+	default:
+		printk(KERN_ERR "glte: ioctl - unknown type %d\n", id);
+		break;
+	}
+	return 0;
+}
+
+static int gdm_lte_ioctl_set_data(struct wm_req_t *req, struct net_device *dev)
+{
+	u16 id = req->data_id;
+
+	switch (id) {
+	case LINK_ON:
+		netif_carrier_on(dev);
+		break;
+	case LINK_OFF:
+		netif_carrier_off(dev);
+		break;
+	}
+
+	return 0;
+}
+
+static int gdm_lte_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
+{
+	struct wm_req_t *req = (struct wm_req_t *)ifr;
+
+	if (cmd != SIOCLTEIOCTL)
+		return -EOPNOTSUPP;
+
+	switch (req->cmd) {
+	case SIOCG_DATA:
+	case SIOCS_DATA:
+		if (req->data_id >= 100)
+			return -EOPNOTSUPP;
+		if (req->cmd == SIOCG_DATA)
+			gdm_lte_ioctl_get_data(req, dev);
+		else if (req->cmd == SIOCS_DATA)
+			gdm_lte_ioctl_set_data(req, dev);
+		break;
+	default:
+		return -EOPNOTSUPP;
+	}
+
+	return 0;
+}
+
+static int gdm_lte_event_send(struct net_device *dev, char *buf, int len)
+{

drivers/staging/gdm724x/gdm_endian.c

Quoted 10 lines
drivers/staging/gdm724x/gdm_endian.c new file +10 -0
+	struct nic *nic = netdev_priv(dev);
+	struct hci_packet *hci = (struct hci_packet *)buf;
+	int idx;
+
+#ifdef DEBUG
+	printk(KERN_DEBUG "glte: D=>H: 0x%04x(%d) len %d\n",
+	       D2H(gdm_dev_endian(nic), hci->cmd_evt),
+	       D2H(gdm_dev_endian(nic), hci->len),
+	       len);
+#endif

Delete this.

Quoted 8 lines
drivers/staging/gdm724x/gdm_endian.c new file +8 -0
+
+	sscanf(dev->name, "lte%d", &idx);
+
+	return netlink_send(lte_event.sock, idx, 0, buf,
+			    D2H(gdm_dev_endian(nic), hci->len) + HCI_HEADER_SIZE);
+}
+
+static void gdm_lte_event_rcv(struct net_device *dev, u16 type, void *msg, int len)

drivers/staging/gdm724x/gdm_endian.c

Quoted 10 lines
drivers/staging/gdm724x/gdm_endian.c new file +10 -0
+{
+	struct nic *nic = netdev_priv(dev);
+
+#ifdef DEBUG
+	struct hci_packet *hci = (struct hci_packet *)msg;
+	printk(KERN_DEBUG, "glte: H=>D: 0x%04x(%d) len %d\n",
+	       D2H(gdm_dev_endian(nic), hci->cmd_evt),
+	       D2H(gdm_dev_endian(nic), hci->len),
+	       len);
+#endif

Delete.

Quoted 22 lines
drivers/staging/gdm724x/gdm_endian.c new file +22 -0
+
+	gdm_lte_hci_send(nic, msg, len);
+}
+
+int gdm_lte_event_init(void)
+{
+	if (lte_event.ref_cnt == 0)
+		lte_event.sock = netlink_init(NETLINK_LTE, gdm_lte_event_rcv);
+
+	if (lte_event.sock) {
+		lte_event.ref_cnt++;
+		return 0;
+	}
+
+	printk(KERN_ERR "glte: event init failed\n");
+	return -1;
+}
+
+void gdm_lte_event_exit(void)
+{
+	if (lte_event.sock && --lte_event.ref_cnt == 0) {
+		netlink_exit(lte_event.sock);

drivers/staging/gdm724x/gdm_endian.c

Quoted 10 lines
drivers/staging/gdm724x/gdm_endian.c new file +10 -0
+		lte_event.sock = NULL;
+	}
+}
+
+static int find_dev_index(u32 nic_type)
+{
+	int index;
+
+	index = nic_type & 0x0000000f;
+	if (index > MAX_NIC_TYPE || index < 0)

It can never be negative because we masked away the signed bit. Also the error handling on this function confuses me a lot. It feels like it should be "index >= MAX_NIC_TYPE". Some of the callers for check that.

Quoted 12 lines
drivers/staging/gdm724x/gdm_endian.c new file +12 -0
+		index = 0;
+
+	return index;
+}
+
+static void gdm_lte_netif_rx(struct net_device *dev, char *buf, int len, int flagged_nic_type)
+{
+	u32 nic_type;
+	struct nic *nic;
+	struct sk_buff *skb;
+	struct ethhdr eth;
+	struct vlan_ethhdr vlan_eth;

drivers/staging/gdm724x/gdm_endian.c

Quoted 10 lines
drivers/staging/gdm724x/gdm_endian.c new file +10 -0
+	void *mac_header_data;
+	u32 mac_header_len;
+	char ip_version = 0;
+
+	nic_type = flagged_nic_type & NIC_TYPE_MASK;
+	nic = netdev_priv(dev);
+	if (nic == NULL) {
+		printk(KERN_ERR "glte: rx, invalid nic\n");
+		return;
+	}

netdev_priv() will never return a NULL here. Delete this unneeded noise.

Quoted 21 lines
drivers/staging/gdm724x/gdm_endian.c new file +21 -0
+	if (flagged_nic_type & NIC_TYPE_F_DHCP) {
+		/* Change the destination mac address with the one requested the IP */
+		if (flagged_nic_type & NIC_TYPE_F_IPV4) {
+			struct dhcp_packet {
+				u8 op;      /* BOOTREQUEST or BOOTREPLY */
+				u8 htype;   /* hardware address type. 1 = 10mb ethernet */
+				u8 hlen;    /* hardware address length */
+				u8 hops;    /* used by relay agents only */
+				u32 xid;    /* unique id */
+				u16 secs;   /* elapsed since client began acquisition/renewal */
+				u16 flags;  /* only one flag so far: */
+				#define BROADCAST_FLAG 0x8000 /* "I need broadcast replies" */
+				u32 ciaddr; /* client IP (if client is in BOUND, RENEW or REBINDING state) */
+				u32 yiaddr; /* 'your' (client) IP address */
+				/* IP address of next server to use in bootstrap, returned in DHCPOFFER, DHCPACK by server */
+				u32 siaddr_nip;
+				u32 gateway_nip; /* relay agent IP address */
+				u8 chaddr[16];   /* link-layer client hardware address (MAC) */
+				u8 sname[64];    /* server host name (ASCIZ) */
+				u8 file[128];    /* boot file name (ASCIZ) */
+				u32 cookie;      /* fixed first four option bytes (99,130,83,99 dec) */

drivers/staging/gdm724x/gdm_endian.c

Quoted 10 lines
drivers/staging/gdm724x/gdm_endian.c new file +10 -0
+			} __packed;
+
+			#define DHCP_V4_HW_ADDR_OFFSET	(\
+				sizeof(struct iphdr) + \
+				sizeof(struct udphdr) + \
+				offsetof(struct dhcp_packet, chaddr))
+			#define DHCP_V4_IP_ADDR_OFFSET (\
+				sizeof(struct iphdr) + \
+				sizeof(struct udphdr) + \
+				offsetof(struct dhcp_packet, yiaddr))

These defines are ugly. The second one isn't even used. Just say:

	void *addr;

	addr = buf + sizeof(struct iphdr) + sizeof(struct udphdr) +
		offsetof(struct dhcp_packet, chaddr);

	memcpy(nic->dest_mac_addr, addr, ETH_ALEN);
Quoted 205 lines
drivers/staging/gdm724x/gdm_endian.c new file +205 -0
+
+			memcpy(nic->dest_mac_addr, buf + DHCP_V4_HW_ADDR_OFFSET, 6);
+		} else if (flagged_nic_type & NIC_TYPE_F_IPV6) {
+			printk(KERN_INFO "glte: DHCPv6 not supported yet\n");
+		}
+	}
+
+	if (nic->vlan_id > 0) {
+		mac_header_data = (void *)&vlan_eth;
+		mac_header_len = VLAN_ETH_HLEN;
+	} else {
+		mac_header_data = (void *)&eth;
+		mac_header_len = ETH_HLEN;
+	}
+
+	/* Format the data so that it can be put to skb */
+	memcpy(mac_header_data, nic->dest_mac_addr, ETH_ALEN);
+	memcpy(mac_header_data + ETH_ALEN, nic->src_mac_addr, ETH_ALEN);
+
+	vlan_eth.h_vlan_TCI = htons(nic->vlan_id);
+	vlan_eth.h_vlan_proto = htons(ETH_P_8021Q);
+
+	if (nic_type == NIC_TYPE_ARP) {
+		/* Should be response: Only happens because there was a request from the host */
+		eth.h_proto = htons(ETH_P_ARP);
+		vlan_eth.h_vlan_encapsulated_proto = htons(ETH_P_ARP);
+	} else {
+		ip_version = buf[0] >> 4;
+		if (ip_version == IP_VERSION_4) {
+			eth.h_proto = htons(ETH_P_IP);
+			vlan_eth.h_vlan_encapsulated_proto = htons(ETH_P_IP);
+		} else if (ip_version == IP_VERSION_6) {
+			eth.h_proto = htons(ETH_P_IPV6);
+			vlan_eth.h_vlan_encapsulated_proto = htons(ETH_P_IPV6);
+		} else {
+			printk(KERN_ERR "glte: Unknown IP version %d\n", ip_version);
+			return;
+		}
+	}
+
+	/* Alloc skb and reserve align */
+	skb = dev_alloc_skb(len + mac_header_len + NET_IP_ALIGN);
+	if (!skb)
+		return;
+	skb_reserve(skb, NET_IP_ALIGN);
+
+	memcpy(skb_put(skb, mac_header_len), mac_header_data, mac_header_len);
+	memcpy(skb_put(skb, len), buf, len);
+
+	skb->protocol = ((struct ethhdr *)mac_header_data)->h_proto;
+	skb->dev = dev;
+	skb_reset_mac_header(skb);
+	skb_pull(skb, ETH_HLEN);
+
+	gdm_lte_rx(skb, nic, nic_type);
+}
+
+static void gdm_lte_multi_sdu_pkt(struct phy_dev *phy_dev, char *buf, int len)
+{
+	struct net_device *dev;
+	struct multi_sdu *multi_sdu = (struct multi_sdu *)buf;
+	struct sdu *sdu = NULL;
+	u8 *data = (u8 *)multi_sdu->data;
+	u16 i = 0;
+	u16 num_packet;
+	u16 hci_len;
+	u16 cmd_evt;
+	u32 nic_type;
+	int index;
+
+	hci_len = D2H(phy_dev->get_endian(phy_dev->priv_dev), multi_sdu->len);
+	num_packet = D2H(phy_dev->get_endian(phy_dev->priv_dev), multi_sdu->num_packet);
+
+#ifdef DEBUG
+	printk(KERN_DEBUG "glte: rx sdu len %d, num_packet %d\n",
+	       multi_sdu->len, multi_sdu->num_packet);
+#endif
+
+	for (i = 0; i < num_packet; i++) {
+		sdu = (struct sdu *)data;
+
+		cmd_evt = D2H(phy_dev->get_endian(phy_dev->priv_dev), sdu->cmd_evt);
+		hci_len = D2H(phy_dev->get_endian(phy_dev->priv_dev), sdu->len);
+		nic_type = D4H(phy_dev->get_endian(phy_dev->priv_dev), sdu->nic_type);
+
+		if (cmd_evt != LTE_RX_SDU) {
+			printk(KERN_ERR "glte: rx sdu wrong hci %04x\n", cmd_evt);
+			return;
+		}
+		if (hci_len < 12) {
+			printk(KERN_ERR "glte: rx sdu invalid len %d\n", hci_len);
+			return;
+		}
+
+		index = find_dev_index(nic_type);
+		if (index >= 0 && index < MAX_NIC_TYPE) {
+			dev = phy_dev->dev[index];
+			gdm_lte_netif_rx(dev, (char *)sdu->data, (int)(hci_len-12), nic_type);
+		} else {
+			printk(KERN_ERR "glte: rx sdu invalid nic_type : %x\n", nic_type);
+		}
+
+		data += ((hci_len+3) & 0xfffc) + HCI_HEADER_SIZE;
+	}
+}
+
+static void gdm_lte_pdn_table(struct net_device *dev, char *buf, int len)
+{
+	struct nic *nic = netdev_priv(dev);
+	struct hci_pdn_table_ind *pdn_table = (struct hci_pdn_table_ind *)buf;
+
+	if (pdn_table->activate) {
+		nic->pdn_table.activate = pdn_table->activate;
+		nic->pdn_table.dft_eps_id = D4H(gdm_dev_endian(nic), pdn_table->dft_eps_id);
+		nic->pdn_table.nic_type = D4H(gdm_dev_endian(nic), pdn_table->nic_type);
+
+		printk(KERN_INFO "glte: pdn %s activated, nic_type=0x%x\n",
+		       dev->name, nic->pdn_table.nic_type);
+	} else {
+		memset(&nic->pdn_table, 0x00, sizeof(struct pdn_table));
+		printk(KERN_INFO "glte: pdn %s deactivated\n",
+		       dev->name);
+	}
+}
+
+static int gdm_lte_receive_pkt(struct phy_dev *phy_dev, char *buf, int len)
+{
+	struct hci_packet *hci = (struct hci_packet *)buf;
+	struct hci_pdn_table_ind *pdn_table = (struct hci_pdn_table_ind *)buf;
+	struct sdu *sdu;
+	struct net_device *dev;
+	int ret = 0;
+	u16 cmd_evt;
+	u32 nic_type;
+	int index;
+
+	if (!len)
+		return ret;
+
+	cmd_evt = D2H(phy_dev->get_endian(phy_dev->priv_dev), hci->cmd_evt);
+
+	dev = phy_dev->dev[0];
+	if (dev == NULL)
+		return 0;
+
+	switch (cmd_evt) {
+	case LTE_RX_SDU:
+		sdu = (struct sdu *)hci->data;
+		nic_type = D4H(phy_dev->get_endian(phy_dev->priv_dev), sdu->nic_type);
+		index = find_dev_index(nic_type);
+		if (index >= 0) {
+			dev = phy_dev->dev[index];
+			gdm_lte_netif_rx(dev, hci->data, len, nic_type);
+		}
+		break;
+	case LTE_RX_MULTI_SDU:
+		gdm_lte_multi_sdu_pkt(phy_dev, buf, len);
+		break;
+	case LTE_LINK_ON_OFF_INDICATION:
+		{
+			struct hci_connect_ind *connect_ind = (struct hci_connect_ind *)buf;
+			printk(KERN_INFO "glte: link %s\n",
+			       connect_ind->connect ? "on" : "off");
+		}
+		break;
+	case LTE_PDN_TABLE_IND:
+		pdn_table = (struct hci_pdn_table_ind *)buf;
+		nic_type = D4H(phy_dev->get_endian(phy_dev->priv_dev), pdn_table->nic_type);
+		index = find_dev_index(nic_type);
+		if (index >= 0) {
+			dev = phy_dev->dev[index];
+			gdm_lte_pdn_table(dev, buf, len);
+		}
+		/* Fall through */
+	default:
+		ret = gdm_lte_event_send(dev, buf, len);
+		break;
+	}
+
+	return ret;
+}
+
+static int rx_complete(void *arg, void *data, int len, int context)
+{
+	struct phy_dev *phy_dev = (struct phy_dev *)arg;
+
+	return gdm_lte_receive_pkt(phy_dev, (char *)data, len);
+}
+
+void start_rx_proc(struct phy_dev *phy_dev)
+{
+	int i;
+
+	for (i = 0; i < MAX_RX_SUBMIT_COUNT; i++)
+		gdm_lte_rcv_with_cb(phy_dev, rx_complete, phy_dev, USB_COMPLETE);
+}
+
+static struct net_device_ops gdm_netdev_ops = {
+	.ndo_open			= gdm_lte_open,
+	.ndo_stop			= gdm_lte_close,
+	.ndo_set_config			= gdm_lte_set_config,
+	.ndo_start_xmit			= gdm_lte_tx,
+	.ndo_get_stats			= gdm_lte_stats,
+	.ndo_do_ioctl			= gdm_lte_ioctl,
+};

drivers/staging/gdm724x/gdm_endian.c

Quoted 10 lines
drivers/staging/gdm724x/gdm_endian.c new file +10 -0
+
+static u8 gdm_lte_macaddr[6] = {0x00, 0x0a, 0x3b, 0x00, 0x00, 0x00};
+
+static void form_mac_address(u8 *dev_addr, u8 *nic_src, u8 *nic_dest, u8 *mac_address, u8 index)
+{
+	/* Form the dev_addr */
+	if (!mac_address)
+		memcpy(dev_addr, gdm_lte_macaddr, 6);
+	else
+		memcpy(dev_addr, mac_address, 6);

Use ETH_ALEN.

drivers/staging/gdm724x/gdm_endian.c

Quoted 3 lines
drivers/staging/gdm724x/gdm_endian.c new file +3 -0
+
+	/* The last byte of the mac address should be less than or equal to 0xFC */
+	dev_addr[5] = (u8) (dev_addr[5] + index);

No need to cast.

Quoted 12 lines
drivers/staging/gdm724x/gdm_endian.c new file +12 -0
+
+	/* Create random nic src and copy the first 3 bytes to be the same as dev_addr */
+	random_ether_addr(nic_src);
+	memcpy(nic_src, dev_addr, 3);
+
+	/* Copy the nic_dest from dev_addr*/
+	memcpy(nic_dest,  dev_addr, 6);
+}
+
+static void mac_validation(u8 *mac_address)
+{
+	u8 invalid_mac = 0;

drivers/staging/gdm724x/gdm_endian.c

Quoted 10 lines
drivers/staging/gdm724x/gdm_endian.c new file +10 -0
+
+	/* the mac address is not 00-00-00-00-00-00 */
+	if (
+		(mac_address[0] == 0x00) &&
+		(mac_address[1] == 0x00) &&
+		(mac_address[2] == 0x00) &&
+		(mac_address[3] == 0x00) &&
+		(mac_address[4] == 0x00) &&
+		(mac_address[5] == 0x00))
+		invalid_mac = 1;

Use is_zero_ether_addr().

drivers/staging/gdm724x/gdm_endian.c

Quoted 10 lines
drivers/staging/gdm724x/gdm_endian.c new file +10 -0
+	/* check for multicast bit */
+	else if ((mac_address[0] & 0x01) == 0x01)
+		invalid_mac = 1;
+
+	if (invalid_mac) {
+		/* Restore the default value */
+		printk(KERN_ERR "glte: MAC invalid, restoring default\n");
+		memcpy(mac_address, gdm_lte_macaddr, 6);
+	} else {
+		printk(KERN_INFO "glte: MAC validated\n");

I feel like this driver is too spammy.

Quoted 9 lines
drivers/staging/gdm724x/gdm_endian.c new file +9 -0
+	}
+}
+
+int register_lte_device(struct phy_dev *phy_dev, struct device *dev, u8 *mac_address)
+{
+	struct nic *nic;
+	struct net_device *net;
+	char pdn_dev_name[16];
+	int ret = 0;

drivers/staging/gdm724x/gdm_endian.c

Quoted 10 lines
drivers/staging/gdm724x/gdm_endian.c new file +10 -0
+	u8 index;
+
+	mac_validation(mac_address);
+
+	for (index = 0; index < MAX_NIC_TYPE; index++) {
+		/* Create device name lteXpdnX */
+		sprintf(pdn_dev_name, "lte%%dpdn%d", index);
+
+		/* Allocate netdev */
+		net =  alloc_netdev(sizeof(struct nic), pdn_dev_name, ether_setup);
                      ^

Extra space.

drivers/staging/gdm724x/gdm_endian.c

Quoted 3 lines
drivers/staging/gdm724x/gdm_endian.c new file +3 -0
+		if (net == NULL) {
+			printk(KERN_ERR "glte: alloc_netdev failed\n");
+			ret = -1;

-ENOMEM;

drivers/staging/gdm724x/gdm_endian.c

Quoted 4 lines
drivers/staging/gdm724x/gdm_endian.c new file +4 -0
+			break;
+		}
+
+		/* Configure device */

Obvious comment is not useful. Delete.

Quoted 16 lines
drivers/staging/gdm724x/gdm_endian.c new file +16 -0
+
+		net->netdev_ops = &gdm_netdev_ops;
+		net->flags &= ~IFF_MULTICAST;
+		net->mtu = DEFAULT_MTU_SIZE;
+
+		/* Configure nic */
+		nic = netdev_priv(net);
+		memset(nic, 0, sizeof(struct nic));
+		nic->netdev = net;
+		nic->phy_dev = phy_dev;
+		nic->nic_id = index;
+
+		form_mac_address(
+				net->dev_addr,
+				nic->src_mac_addr,
+				nic->dest_mac_addr,

drivers/staging/gdm724x/gdm_endian.c

Quoted 10 lines
drivers/staging/gdm724x/gdm_endian.c new file +10 -0
+				mac_address,
+				index);
+
+		SET_NETDEV_DEV(net, dev);
+		SET_NETDEV_DEVTYPE(net, &wwan_type);
+
+		ret = register_netdev(net);
+		if (ret) {
+			printk(KERN_ERR "glte: register %s failed\n", net->name);
+			free_netdev(net);

We should free all the previously allocated devices in a loop. We should return an error code instead of zero.

Quoted 50 lines
drivers/staging/gdm724x/gdm_endian.c new file +29 -0
+			break;
+		}
+
+		netif_carrier_on(net);
+
+		phy_dev->dev[index] = net;
+
+		printk(KERN_INFO "glte: register %s\n", net->name);
+	}
+
+	return 0;
+}
+
+void unregister_lte_device(struct phy_dev *phy_dev)
+{
+	struct net_device *net;
+	int index;
+
+	for (index = MAX_NIC_TYPE-1; index >= 0; index--) {
+		net = phy_dev->dev[index];
+		if (net == NULL)
+			continue;
+
+		printk(KERN_INFO "glte: unregister %s\n", net->name);
+
+		unregister_netdev(net);
+		free_netdev(net);
+	}
+}
drivers/staging/gdm724x/gdm_lte.h new file +15 -0
new file mode 100644
index 0000000..61f62d6
@@ -0,0 +1,93 @@
+/*
+ * Copyright (c) 2012 GCT Semiconductor, Inc. All rights reserved.
+ *
+ * This software is licensed under the terms of the GNU General Public
+ * License version 2, as published by the Free Software Foundation, and
+ * may be copied, distributed, and modified under those terms.
+ *
+ * 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.
+ */
+
+#ifndef _GDM_LTE_H_
+#define _GDM_LTE_H_

drivers/staging/gdm724x/gdm_lte.h line 25

Quoted 10 lines
drivers/staging/gdm724x/gdm_lte.h new file +10 -0
+
+#include <linux/netdevice.h>
+#include <linux/version.h>
+#include <linux/types.h>
+
+#include "gdm_endian.h"
+
+#ifndef __packed
+#define __packed __attribute__((packed))
+#endif

Delete.

drivers/staging/gdm724x/gdm_lte.h line 38

Quoted 13 lines
drivers/staging/gdm724x/gdm_lte.h new file +13 -0
+
+#define SPBC_PATH		"GCT_LTE_MBL.bin"
+#define SIMG_PATH		"signed_app.bin"
+
+#define MAX_NIC_TYPE		4
+#define MAX_RX_SUBMIT_COUNT	3
+#define MAX_FILE_PATH		260
+#define DRIVER_VERSION		"3.7.17.0"
+
+#define H2L(x)		__cpu_to_le16(x)
+#define L2H(x)		__le16_to_cpu(x)
+#define H4L(x)		__cpu_to_le32(x)
+#define L4H(x)		__le32_to_cpu(x)

Delete these.

Quoted 33 lines
drivers/staging/gdm724x/gdm_lte.h new file +33 -0
+
+enum TX_ERROR_CODE {
+	TX_NO_ERROR = 0,
+	TX_NO_DEV,
+	TX_NO_SPC,
+	TX_NO_BUFFER,
+};
+
+enum CALLBACK_CONTEXT {
+	KERNEL_THREAD = 0,
+	USB_COMPLETE,
+};
+
+struct pdn_table {
+	u8 activate;
+	u32 dft_eps_id;
+	u32 nic_type;
+} __packed;
+
+struct nic;
+
+struct phy_dev {
+	void	*priv_dev;
+	struct net_device *dev[MAX_NIC_TYPE];
+	int	(*send_hci_func)(void *priv_dev, void *data, int len,
+			void (*cb)(void *cb_data), void *cb_data);
+	int	(*send_sdu_func)(void *priv_dev, void *data, int len,
+			unsigned int dftEpsId, unsigned int epsId,
+			void (*cb)(void *cb_data), void *cb_data,
+			int dev_idx, int nic_type);
+	int	(*rcv_func)(void *priv_dev,
+			int (*cb)(void *cb_data, void *data, int len, int context),
+			void *cb_data, int context);

drivers/staging/gdm724x/gdm_lte.h line 81

Quoted 10 lines
drivers/staging/gdm724x/gdm_lte.h new file +10 -0
+	struct gdm_endian *(*get_endian)(void *priv_dev);
+};
+
+struct nic {
+	struct net_device *netdev;
+	struct phy_dev *phy_dev;
+	struct net_device_stats stats;
+	struct pdn_table pdn_table;
+	u8 dest_mac_addr[6];
+	u8 src_mac_addr[6];

ETH_ALEN.

Quoted 46 lines
drivers/staging/gdm724x/gdm_lte.h new file +12 -0
+	u32 nic_id;
+	u16 vlan_id;
+};
+
+int gdm_lte_event_init(void);
+void gdm_lte_event_exit(void);
+
+void start_rx_proc(struct phy_dev *phy_dev);
+int register_lte_device(struct phy_dev *phy_dev, struct device *dev, u8 *mac_address);
+void unregister_lte_device(struct phy_dev *phy_dev);
+
+#endif /* _GDM_LTE_H_ */
drivers/staging/gdm724x/gdm_mux.c new file +28 -0
new file mode 100644
index 0000000..7908fb7
@@ -0,0 +1,789 @@
+/*
+ * Copyright (c) 2012 GCT Semiconductor, Inc. All rights reserved.
+ *
+ * This software is licensed under the terms of the GNU General Public
+ * License version 2, as published by the Free Software Foundation, and
+ * may be copied, distributed, and modified under those terms.
+ *
+ * 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.
+ */
+
+#include <linux/module.h>
+#include <linux/version.h>
+#include <linux/kernel.h>
+#include <linux/usb.h>
+#include <linux/errno.h>
+#include <linux/init.h>
+#include <linux/tty.h>
+#include <linux/tty_driver.h>
+#include <linux/tty_flip.h>
+#include <linux/slab.h>
+#include <linux/usb/cdc.h>
+
+#include "gdm_mux.h"
+#include "gdm_tty.h"
+

drivers/staging/gdm724x/gdm_mux.c line 38

Quoted 10 lines
drivers/staging/gdm724x/gdm_mux.c new file +10 -0
+#ifdef LTE_USB_PM
+#define PM_NORMAL 0
+#define PM_SUSPEND 1
+#endif /* LTE_USB_PM */
+
+#define USB_RT_ACM          (USB_TYPE_CLASS | USB_RECIP_INTERFACE)
+
+#define START_FLAG 0xA512485A
+#define MUX_HEADER_SIZE 14
+#define MUX_RX_MAX_SIZE (1024*30)

This seems like a lot of data for kmalloc to allocate.

drivers/staging/gdm724x/gdm_mux.c line 46

Quoted 8 lines
drivers/staging/gdm724x/gdm_mux.c new file +8 -0
+#define AT_PKT_TYPE 0xF011
+#define DM_PKT_TYPE 0xF010
+
+#define RETRY_TIMER 30 /* msec */
+
+struct workqueue_struct *mux_rx_wq;
+
+

Only one blank line needed.

Quoted 14 lines
drivers/staging/gdm724x/gdm_mux.c new file +14 -0
+static u16 PACKET_TYPE[TTY_MAX_COUNT] = {0xF011, 0xF010};
+
+#define USB_DEVICE_CDC_DATA(vid, pid) \
+	.match_flags = \
+		USB_DEVICE_ID_MATCH_DEVICE |\
+		USB_DEVICE_ID_MATCH_INT_CLASS |\
+		USB_DEVICE_ID_MATCH_INT_SUBCLASS,\
+	.idVendor = vid,\
+	.idProduct = pid,\
+	.bInterfaceClass = USB_CLASS_COMM,\
+	.bInterfaceSubClass = USB_CDC_SUBCLASS_ACM
+
+static const struct usb_device_id id_table[] = {
+	{ USB_DEVICE_CDC_DATA(0x1076, 0x8000) }, /* GCT GDM7240 */

drivers/staging/gdm724x/gdm_mux.c line 70

Quoted 10 lines
drivers/staging/gdm724x/gdm_mux.c new file +10 -0
+	{ USB_DEVICE_CDC_DATA(0x1076, 0x8f00) }, /* GCT GDM7243 */
+	{ USB_DEVICE_CDC_DATA(0x1076, 0x9000) }, /* GCT GDM7243 */
+	{ USB_DEVICE_CDC_DATA(0x1d74, 0x2300) }, /* LGIT Phoenix */
+	{}
+};
+
+
+MODULE_DEVICE_TABLE(usb, id_table);
+
+int PacketTypeToIndex(u16 packetType)

CamelCase function.

drivers/staging/gdm724x/gdm_mux.c line 79

Quoted 9 lines
drivers/staging/gdm724x/gdm_mux.c new file +9 -0
+{
+	int i;
+
+	for (i = 0; i < TTY_MAX_COUNT; i++) {
+		if (PACKET_TYPE[i] == packetType)
+			return i;
+	}
+
+	printk(KERN_ERR "glte: invalid packet type:%d\n", packetType);

Noise.

drivers/staging/gdm724x/gdm_mux.c line 89

Quoted 10 lines
drivers/staging/gdm724x/gdm_mux.c new file +10 -0
+
+	return -1;
+}
+
+static struct mux_tx *alloc_mux_tx(int len)
+{
+	struct mux_tx *t = NULL;
+	int ret = 0;
+
+

Extra blank.

drivers/staging/gdm724x/gdm_mux.c line 93

Quoted 4 lines
drivers/staging/gdm724x/gdm_mux.c new file +4 -0
+	t = kmalloc(sizeof(struct mux_tx), GFP_ATOMIC);
+	if (!t) {
+		ret = -ENOMEM;
+		goto out;

Return NULL directly. There is no error handling in this case.

drivers/staging/gdm724x/gdm_mux.c line 95

Quoted 2 lines
drivers/staging/gdm724x/gdm_mux.c new file +2 -0
+	}
+	memset(t, 0, sizeof(struct mux_tx));

Use kzalloc.

drivers/staging/gdm724x/gdm_mux.c line 103

Quoted 8 lines
drivers/staging/gdm724x/gdm_mux.c new file +8 -0
+
+	t->urb = usb_alloc_urb(0, GFP_ATOMIC);
+	t->buf = kmalloc(1024*10, GFP_ATOMIC);
+	if (!t->urb || !t->buf) {
+		ret = -ENOMEM;
+		goto out;
+	}
+
	return t;

drivers/staging/gdm724x/gdm_mux.c line 106

Quoted 3 lines
drivers/staging/gdm724x/gdm_mux.c new file +3 -0
+out:
+
+	if (ret < 0) {

Now it's only errors here. Remove the check. Pull it in one indent.

drivers/staging/gdm724x/gdm_mux.c line 107

Quoted 1 line
drivers/staging/gdm724x/gdm_mux.c new file +1 -0
+		if (t) {

"t" is always non-null now. Remove this check. Pull it in one indent level. Update the label.

err_free_t:

	usb_free_urb(t->urb);
	kfree(t->buf);
	kfree(t);

	return NULL;
}

PLEASE PLEASE fix these. They are horrible to look at. It should be:

	ret = soemthing();
	if (ret)
		goto release_resource_b;

	return success;

release_resource_b:

	release(b);
free_a;
	free(a);

	return ret;
}

This way has no nested if statements and multiple indents.

Quoted 28 lines
drivers/staging/gdm724x/gdm_mux.c new file +28 -0
+			usb_free_urb(t->urb);
+			kfree(t->buf);
+			kfree(t);
+		}
+
+		return NULL;
+	}
+
+	return t;
+}
+
+static void free_mux_tx(struct mux_tx *t)
+{
+	if (t) {
+		usb_free_urb(t->urb);
+		kfree(t->buf);
+		kfree(t);
+	}
+}
+
+static struct mux_rx *alloc_mux_rx(void)
+{
+	struct mux_rx *r = NULL;
+	int ret = 0;
+
+
+	r = kmalloc(sizeof(struct mux_rx), GFP_ATOMIC);
+	if (!r) {

drivers/staging/gdm724x/gdm_mux.c line 145

Quoted 10 lines
drivers/staging/gdm724x/gdm_mux.c new file +10 -0
+		ret = -ENOMEM;
+		goto out;
+	}
+
+	r->urb = usb_alloc_urb(0, GFP_ATOMIC);
+	r->buf = kmalloc(MUX_RX_MAX_SIZE, GFP_ATOMIC);
+	if (!r->urb || !r->buf) {
+		ret = -ENOMEM;
+		goto out;
+	}

Same thing. No need for spaghetti code at the end of the function.

Quoted 48 lines
drivers/staging/gdm724x/gdm_mux.c new file +48 -0
+out:
+
+	if (ret < 0) {
+		if (r) {
+			usb_free_urb(r->urb);
+			kfree(r->buf);
+			kfree(r);
+		}
+
+		return NULL;
+	}
+
+	return r;
+}
+
+static void free_mux_rx(struct mux_rx *r)
+{
+	if (r) {
+		usb_free_urb(r->urb);
+		kfree(r->buf);
+		kfree(r);
+	}
+}
+
+static struct mux_rx *get_rx_struct(struct rx_cxt *rx)
+{
+	struct mux_rx *r;
+	unsigned long flags;
+
+	spin_lock_irqsave(&rx->free_list_lock, flags);
+
+	if (list_empty(&rx->rx_free_list)) {
+		spin_unlock_irqrestore(&rx->free_list_lock, flags);
+		return NULL;
+	}
+
+	r = list_entry(rx->rx_free_list.prev, struct mux_rx, free_list);
+	list_del(&r->free_list);
+
+	spin_unlock_irqrestore(&rx->free_list_lock, flags);
+
+	return r;
+}
+
+static void put_rx_struct(struct rx_cxt *rx, struct mux_rx *r)
+{
+	unsigned long flags;
+

drivers/staging/gdm724x/gdm_mux.c line 203

Quoted 10 lines
drivers/staging/gdm724x/gdm_mux.c new file +10 -0
+	spin_lock_irqsave(&rx->free_list_lock, flags);
+	list_add_tail(&r->free_list, &rx->rx_free_list);
+	spin_unlock_irqrestore(&rx->free_list_lock, flags);
+}
+
+
+static int up_to_host(struct mux_rx *r)
+{
+	struct mux_dev *mux_dev = (struct mux_dev *)r->mux_dev;
+	struct mux_pkt_header *mux_header = NULL;

Unneeded initialization. These just suppress GCC's natural error finding abilities. Remove all unneeded initialization.

Quoted 16 lines
drivers/staging/gdm724x/gdm_mux.c new file +16 -0
+	unsigned int start_flag;
+	unsigned int payload_size;
+	unsigned short packet_type;
+	int remain;
+	int dummy_cnt;
+	u32 packet_size_sum = r->offset;
+	u8 *buf;
+	int index;
+	int ret = 0;
+	int len = r->len;
+
+	while (1) {
+		mux_header =
+			(struct mux_pkt_header *)(r->buf + packet_size_sum);
+		start_flag = L4H(mux_header->start_flag);
+		payload_size = L4H(mux_header->payload_size);

drivers/staging/gdm724x/gdm_mux.c line 229

Quoted 10 lines
drivers/staging/gdm724x/gdm_mux.c new file +10 -0
+		packet_type = L2H(mux_header->packet_type);
+
+		if (start_flag != START_FLAG) {
+			printk(KERN_ERR "glte: invalid START_FLAG %x\n",
+				start_flag);
+			break;
+		}
+
+		remain = (MUX_HEADER_SIZE + payload_size) % 4;
+		dummy_cnt = remain ? (4-remain) : 0;

Use the ALIGN() macro?

drivers/staging/gdm724x/gdm_mux.c line 242

Quoted 13 lines
drivers/staging/gdm724x/gdm_mux.c new file +13 -0
+
+		if (len - packet_size_sum <
+			MUX_HEADER_SIZE + payload_size + dummy_cnt) {
+			printk(KERN_ERR "glte: invalid payload : %d %d %04x\n",
+			       payload_size, len,
+			       packet_type
+			       );
+			break;
+		}
+
+		index = PacketTypeToIndex(packet_type);
+		if (index < 0) {
+			printk(KERN_ERR "glte: invalid index %d\n", index);

Returning success but printing an error message.

drivers/staging/gdm724x/gdm_mux.c line 247

Quoted 5 lines
drivers/staging/gdm724x/gdm_mux.c new file +5 -0
+			break;
+		}
+
+		buf = (u8 *)(mux_header);
+		ret = r->callback((void *)&buf[MUX_HEADER_SIZE],

r->callback() doesn't care about the type. No need for a cast.

The pointer math here is confusing. MUX_HEADER_SIZE is just sizeof(struct mux_pkt_header). It might be nicer to do something like:

struct mux_pkt {
	unsigned int start_flag;
	unsigned int seq_num;
	unsigned int payload_size;
	unsigned short packet_type;
	unsigned char data[0];
};

That way you could just say:

		ret = r->callback(mux_pkt->data,

Which is more clear.

Quoted 51 lines
drivers/staging/gdm724x/gdm_mux.c new file +51 -0
+				payload_size,
+				index,
+				mux_dev->minor[index],
+				RECV_PACKET_PROCESS_CONTINUE
+				);
+		if (ret == TO_HOST_BUFFER_REQUEST_FAIL) {
+			r->offset += packet_size_sum;
+			break;
+		}
+
+		packet_size_sum += MUX_HEADER_SIZE + payload_size + dummy_cnt;
+
+		if (len - packet_size_sum <= MUX_HEADER_SIZE + 2) {
+			ret = r->callback((void *)NULL,
+					0,
+					index,
+					mux_dev->minor[index],
+					RECV_PACKET_PROCESS_COMPLETE
+					);
+			break;
+		}
+	}
+
+	return ret;
+}
+
+static void do_rx(struct work_struct *work)
+{
+	struct mux_dev *mux_dev =
+		container_of(work, struct mux_dev , work_rx.work);
+	struct mux_rx *r;
+	struct rx_cxt *rx = (struct rx_cxt *)&mux_dev->rx;
+	unsigned long flags;
+	int ret = 0;
+
+	while (1) {
+		spin_lock_irqsave(&rx->to_host_lock, flags);
+		if (list_empty(&rx->to_host_list)) {
+			spin_unlock_irqrestore(&rx->to_host_lock, flags);
+			break;
+		}
+		r = list_entry(rx->to_host_list.next, struct mux_rx, to_host_list);
+		list_del(&r->to_host_list);
+		spin_unlock_irqrestore(&rx->to_host_lock, flags);
+
+		ret = up_to_host(r);
+		if (ret == TO_HOST_BUFFER_REQUEST_FAIL)
+			printk(KERN_ERR "glte: failed to send mux data to host\n");
+		else
+			put_rx_struct(rx, r);
+	}

drivers/staging/gdm724x/gdm_mux.c line 308

Quoted 10 lines
drivers/staging/gdm724x/gdm_mux.c new file +10 -0
+}
+
+static void remove_rx_submit_list(struct mux_rx *r, struct rx_cxt *rx)
+{
+	unsigned long flags;
+	struct mux_rx	*r_remove, *r_remove_next;
+
+	spin_lock_irqsave(&rx->submit_list_lock, flags);
+	list_for_each_entry_safe(r_remove, r_remove_next, &rx->rx_submit_list, rx_submit_list)
+	{

Checkpatch error. Put the braces on the line before.

Quoted 43 lines
drivers/staging/gdm724x/gdm_mux.c new file +43 -0
+		if (r == r_remove)
+			list_del(&r->rx_submit_list);
+	}
+	spin_unlock_irqrestore(&rx->submit_list_lock, flags);
+}
+
+static void gdm_mux_rcv_complete(struct urb *urb)
+{
+	struct mux_rx *r = urb->context;
+	struct mux_dev *mux_dev = (struct mux_dev *)r->mux_dev;
+	struct rx_cxt *rx = &mux_dev->rx;
+	unsigned long flags;
+
+	remove_rx_submit_list(r, rx);
+
+	if (urb->status) {
+#ifdef LTE_USB_PM
+		if (mux_dev->usb_state == PM_NORMAL)
+			printk(KERN_ERR "glte: gdm_mux_rcv_complete urb status error %d\n", urb->status);
+#else
+		printk(KERN_ERR "glte: gdm_mux_rcv_complete urb status error %d\n", urb->status);
+#endif /* LTE_USB_PM */
+
+		put_rx_struct(rx, r);
+	} else {
+		r->len = r->urb->actual_length;
+
+		spin_lock_irqsave(&rx->to_host_lock, flags);
+		list_add_tail(&r->to_host_list, &rx->to_host_list);
+		queue_work(mux_rx_wq, &mux_dev->work_rx.work);
+		spin_unlock_irqrestore(&rx->to_host_lock, flags);
+	}
+}
+
+static int gdm_mux_recv(void *priv_dev,
+			int (*cb)(void *data, int len, int tty_index, int minor, int complete)
+			)
+{
+	struct mux_dev *mux_dev = priv_dev;
+	struct usb_device *usbdev = mux_dev->usbdev;
+	struct mux_rx *r;
+	struct rx_cxt *rx = &mux_dev->rx;
+	unsigned long flags;

drivers/staging/gdm724x/gdm_mux.c line 361

Quoted 10 lines
drivers/staging/gdm724x/gdm_mux.c new file +10 -0
+	int ret;
+
+	if (!usbdev) {
+		printk(KERN_ERR "glte: Device is Disconnect\n");
+		return -ENODEV;
+	}
+
+	r = get_rx_struct(rx);
+	if (!r) {
+		printk(KERN_ERR "glte: alloc_rx_struct fail\n");

Error message out of date. It's get_rx_struct().

Quoted 49 lines
drivers/staging/gdm724x/gdm_mux.c new file +49 -0
+		return -ENOMEM;
+	}
+
+	r->offset = 0;
+	r->mux_dev = (void *)mux_dev;
+	r->callback = cb;
+#ifdef LTE_USB_PM
+	mux_dev->rx_cb = cb;
+#endif /* LTE_USB_PM */
+
+	usb_fill_bulk_urb(r->urb,
+			  usbdev,
+			  usb_rcvbulkpipe(usbdev, 0x86),
+			  r->buf,
+			  MUX_RX_MAX_SIZE,
+			  gdm_mux_rcv_complete,
+			  r);
+
+	spin_lock_irqsave(&rx->submit_list_lock, flags);
+	list_add_tail(&r->rx_submit_list, &rx->rx_submit_list);
+	spin_unlock_irqrestore(&rx->submit_list_lock, flags);
+
+	ret = usb_submit_urb(r->urb, GFP_KERNEL);
+
+	if (ret) {
+		spin_lock_irqsave(&rx->submit_list_lock, flags);
+		list_del(&r->rx_submit_list);
+		spin_unlock_irqrestore(&rx->submit_list_lock, flags);
+
+		put_rx_struct(rx, r);
+
+		printk(KERN_ERR "glte: usb_submit_urb ret=%d\n", ret);
+	}
+
+#ifdef LTE_USB_PM
+	usb_mark_last_busy(usbdev);
+#endif /* LTE_USB_PM */
+
+	return ret;
+}
+
+static void gdm_mux_send_complete(struct urb *urb)
+{
+	struct mux_tx *t = urb->context;
+
+	if (urb->status == -ECONNRESET) {
+		printk(KERN_INFO "glte: CONNRESET\n");
+		free_mux_tx(t);
+		return;

drivers/staging/gdm724x/gdm_mux.c line 420

Quoted 10 lines
drivers/staging/gdm724x/gdm_mux.c new file +10 -0
+	}
+
+	if (t->callback)
+		t->callback(t->cb_data);
+
+	free_mux_tx(t);
+}
+
+static int gdm_mux_send(void *priv_dev, void *data, int len, int tty_index,
+			void (*cb)(void *data), void *cb_data)

It could be better to declare *data as const.

Quoted 14 lines
drivers/staging/gdm724x/gdm_mux.c new file +14 -0
+{
+	struct mux_dev *mux_dev = priv_dev;
+	struct usb_device *usbdev = mux_dev->usbdev;
+	struct mux_pkt_header *mux_header;
+	struct mux_tx *t = NULL;
+	static u32 seq_num = 1;
+	int remain;
+	int dummy_cnt;
+	int total_len;
+	int ret;
+	unsigned long flags;
+
+#ifdef LTE_USB_PM
+	if (mux_dev->usb_state == PM_SUSPEND) {

drivers/staging/gdm724x/gdm_mux.c line 444

Quoted 10 lines
drivers/staging/gdm724x/gdm_mux.c new file +10 -0
+		ret = usb_autopm_get_interface(mux_dev->intf);
+		if (!ret)
+			usb_autopm_put_interface(mux_dev->intf);
+	}
+#endif /* LTE_USB_PM */
+
+	spin_lock_irqsave(&mux_dev->write_lock, flags);
+
+	remain = (MUX_HEADER_SIZE + len) % 4;
+	dummy_cnt = remain ? (4 - remain) : 0;

ALIGN()

Quoted 69 lines
drivers/staging/gdm724x/gdm_mux.c new file +69 -0
+
+	total_len = len + MUX_HEADER_SIZE + dummy_cnt;
+
+	t = alloc_mux_tx(total_len);
+	if (!t) {
+		printk(KERN_ERR "glte: alloc_mux_tx fail\n");
+		spin_unlock_irqrestore(&mux_dev->write_lock, flags);
+		return -ENOMEM;
+	}
+
+	mux_header = (struct mux_pkt_header *)t->buf;
+	mux_header->start_flag = H4L(START_FLAG);
+	mux_header->seq_num = H4L(seq_num++);
+	mux_header->payload_size = H4L((u32)len);
+	mux_header->packet_type = H2L(PACKET_TYPE[tty_index]);
+
+	memcpy(t->buf+MUX_HEADER_SIZE, data, len);
+	memset(t->buf+MUX_HEADER_SIZE+len, 0, dummy_cnt);
+
+	t->len = total_len;
+	t->callback = cb;
+	t->cb_data = cb_data;
+
+	usb_fill_bulk_urb(t->urb,
+			  usbdev,
+			  usb_sndbulkpipe(usbdev, 5),
+			  t->buf,
+			  total_len,
+			  gdm_mux_send_complete,
+			  t);
+
+	ret = usb_submit_urb(t->urb, GFP_KERNEL);
+
+	spin_unlock_irqrestore(&mux_dev->write_lock, flags);
+
+	if (ret)
+		printk(KERN_ERR "glte: usb_submit_urb Error : %d\n", ret);
+
+#ifdef LTE_USB_PM
+	usb_mark_last_busy(usbdev);
+#endif /* LTE_USB_PM */
+
+	return ret;
+}
+
+static int gdm_mux_send_control(void *priv_dev, int request, int value, void *buf, int len)
+{
+	struct mux_dev *mux_dev = priv_dev;
+	struct usb_device *usbdev = mux_dev->usbdev;
+	int ret;
+
+	ret = usb_control_msg(usbdev,
+			      usb_sndctrlpipe(usbdev, 0),
+			      request,
+			      USB_RT_ACM,
+			      value,
+			      2,
+			      buf,
+			      len,
+			      5000
+			     );
+
+	if (ret < 0)
+		printk(KERN_ERR "glte: usb_control_msg error : %d\n", ret);
+
+	return ret < 0 ? ret : 0;
+}
+
+static void release_usb(struct mux_dev *mux_dev)

drivers/staging/gdm724x/gdm_mux.c line 523

Quoted 10 lines
drivers/staging/gdm724x/gdm_mux.c new file +10 -0
+{
+	struct rx_cxt		*rx = &mux_dev->rx;
+	struct mux_rx		*r, *r_next;
+	unsigned long		flags;
+
+	cancel_delayed_work(&mux_dev->work_rx);
+
+	spin_lock_irqsave(&rx->submit_list_lock, flags);
+	list_for_each_entry_safe(r, r_next, &rx->rx_submit_list, rx_submit_list)
+	{

Put the { on the line before. (It's not a function).

Quoted 33 lines
drivers/staging/gdm724x/gdm_mux.c new file +33 -0
+		spin_unlock_irqrestore(&rx->submit_list_lock, flags);
+		usb_kill_urb(r->urb);
+		spin_lock_irqsave(&rx->submit_list_lock, flags);
+	}
+	spin_unlock_irqrestore(&rx->submit_list_lock, flags);
+
+	spin_lock_irqsave(&rx->free_list_lock, flags);
+	list_for_each_entry_safe(r, r_next, &rx->rx_free_list, free_list)
+	{
+		list_del(&r->free_list);
+		free_mux_rx(r);
+	}
+	spin_unlock_irqrestore(&rx->free_list_lock, flags);
+
+	spin_lock_irqsave(&rx->to_host_lock, flags);
+	list_for_each_entry_safe(r, r_next, &rx->to_host_list, to_host_list)
+	{
+		if (r->mux_dev == (void *)mux_dev) {
+			list_del(&r->to_host_list);
+			free_mux_rx(r);
+		}
+	}
+	spin_unlock_irqrestore(&rx->to_host_lock, flags);
+}
+
+
+static int init_usb(struct mux_dev *mux_dev)
+{
+	struct mux_rx *r;
+	struct rx_cxt *rx = &mux_dev->rx;
+	int ret = 0;
+	int i;
+	unsigned long flags;

drivers/staging/gdm724x/gdm_mux.c line 566

Quoted 10 lines
drivers/staging/gdm724x/gdm_mux.c new file +10 -0
+
+	spin_lock_init(&mux_dev->write_lock);
+	INIT_LIST_HEAD(&rx->to_host_list);
+	INIT_LIST_HEAD(&rx->rx_submit_list);
+	INIT_LIST_HEAD(&rx->rx_free_list);
+	spin_lock_init(&rx->to_host_lock);
+	spin_lock_init(&rx->submit_list_lock);
+	spin_lock_init(&rx->free_list_lock);
+
+	for (i = 0; i < MAX_ISSUE_NUM*2; i++) {

Space around math operators.

                    i < MAX_ISSUE_NUM * 2;

drivers/staging/gdm724x/gdm_mux.c line 570

Quoted 4 lines
drivers/staging/gdm724x/gdm_mux.c new file +4 -0
+		r = alloc_mux_rx();
+		if (r == NULL) {
+			ret = -ENOMEM;
+			break;

The error handling here is not correct. It needs to unwind. We don't want to INIT_DELAYED_WORK().

Quoted 21 lines
drivers/staging/gdm724x/gdm_mux.c new file +21 -0
+		}
+
+		spin_lock_irqsave(&rx->free_list_lock, flags);
+		list_add(&r->free_list, &rx->rx_free_list);
+		spin_unlock_irqrestore(&rx->free_list_lock, flags);
+	}
+
+	INIT_DELAYED_WORK(&mux_dev->work_rx, do_rx);
+
+	return ret;
+}
+
+static int gdm_mux_probe(struct usb_interface *intf, const struct usb_device_id *id)
+{
+	struct mux_dev *mux_dev = NULL;
+	struct tty_dev *tty_dev = NULL;
+	u16 idVendor, idProduct;
+	int bInterfaceNumber;
+	int ret = 0;
+	int i;
+	struct usb_device *usbdev = interface_to_usbdev(intf);

drivers/staging/gdm724x/gdm_mux.c line 601

Quoted 10 lines
drivers/staging/gdm724x/gdm_mux.c new file +10 -0
+	bInterfaceNumber = intf->cur_altsetting->desc.bInterfaceNumber;
+
+	idVendor = L2H(usbdev->descriptor.idVendor);
+	idProduct = L2H(usbdev->descriptor.idProduct);
+
+	printk(KERN_INFO "glte: mux vid = 0x%04x pid = 0x%04x\n",
+	       idVendor, idProduct);
+
+	if (bInterfaceNumber != 2) {
+		ret = -1;

-1.

Quoted 8 lines
drivers/staging/gdm724x/gdm_mux.c new file +8 -0
+		goto out;
+	}
+
+	mux_dev = kmalloc(sizeof(struct mux_dev), GFP_KERNEL);
+	if (!mux_dev) {
+		ret = -ENOMEM;
+		goto out;
+	}

drivers/staging/gdm724x/gdm_mux.c line 619

Quoted 10 lines
drivers/staging/gdm724x/gdm_mux.c new file +10 -0
+
+	tty_dev = kmalloc(sizeof(struct tty_dev), GFP_KERNEL);
+	if (!tty_dev) {
+		kfree(mux_dev);
+		ret = -ENOMEM;
+		goto out;
+	}
+
+	memset(mux_dev, 0, sizeof(struct mux_dev));
+	memset(tty_dev, 0, sizeof(struct tty_dev));

Use kzalloc().

Quoted 16 lines
drivers/staging/gdm724x/gdm_mux.c new file +16 -0
+
+	mux_dev->usbdev = usbdev;
+	mux_dev->control_intf = intf;
+
+	ret = init_usb(mux_dev);
+	if (ret < 0)
+		goto out;
+
+	tty_dev->priv_dev = (void *)mux_dev;
+	tty_dev->send_func = gdm_mux_send;
+	tty_dev->recv_func = gdm_mux_recv;
+	tty_dev->send_control = gdm_mux_send_control;
+
+	if (register_lte_tty_device(tty_dev, &intf->dev) < 0) {
+		unregister_lte_tty_device(tty_dev);
+		mux_dev = tty_dev->priv_dev;

drivers/staging/gdm724x/gdm_mux.c line 645

Quoted 10 lines
drivers/staging/gdm724x/gdm_mux.c new file +10 -0
+
+		ret = -1;
+		goto out;
+	}
+	for (i = 0; i < TTY_MAX_COUNT; i++)
+		mux_dev->minor[i] = tty_dev->minor[i];
+
+out:
+
+	if (ret >= 0) {

These end of function splotches of spaghetti are super annoying. Why are we even testing for greater than zero when it can never be greater? Anyway, I've already explained about error handling.

Quoted 24 lines
drivers/staging/gdm724x/gdm_mux.c new file +24 -0
+#ifdef LTE_USB_PM
+		mux_dev->intf = intf;
+		mux_dev->usb_state = PM_NORMAL;
+#endif /* LTE_USB_PM */
+	} else {
+		kfree(tty_dev);
+
+		if (mux_dev) {
+			release_usb(mux_dev);
+			kfree(mux_dev);
+		}
+	}
+
+	usb_get_dev(usbdev);
+	usb_set_intfdata(intf, tty_dev);
+
+	return ret;
+}
+
+static void gdm_mux_disconnect(struct usb_interface *intf)
+{
+	struct tty_dev *tty_dev;
+	struct mux_dev *mux_dev;
+	struct usb_device *usbdev = interface_to_usbdev(intf);

drivers/staging/gdm724x/gdm_mux.c line 679

Quoted 10 lines
drivers/staging/gdm724x/gdm_mux.c new file +10 -0
+
+	tty_dev = usb_get_intfdata(intf);
+
+	mux_dev = tty_dev->priv_dev;
+
+	release_usb(mux_dev);
+	unregister_lte_tty_device(tty_dev);
+
+	kfree(mux_dev);
+	mux_dev = NULL;

Delete this no-op line. The compiler already does.

drivers/staging/gdm724x/gdm_mux.c line 682

Quoted 3 lines
drivers/staging/gdm724x/gdm_mux.c new file +3 -0
+
+	kfree(tty_dev);
+	tty_dev = NULL;

And this.

Quoted 35 lines
drivers/staging/gdm724x/gdm_mux.c new file +35 -0
+
+	usb_put_dev(usbdev);
+}
+
+#ifdef LTE_USB_PM
+static int gdm_mux_suspend(struct usb_interface *intf, pm_message_t pm_msg)
+{
+	struct tty_dev *tty_dev;
+	struct mux_dev *mux_dev;
+	struct rx_cxt *rx;
+	struct mux_rx *r, *r_next;
+	unsigned long flags;
+
+	/* printk(KERN_INFO "gdm_mux_suspend\n"); */
+
+	tty_dev = usb_get_intfdata(intf);
+	mux_dev = tty_dev->priv_dev;
+	rx = &mux_dev->rx;
+
+	if (mux_dev->usb_state != PM_NORMAL) {
+		printk(KERN_ERR "glte: usb suspend - invalid state\n");
+		return -1;
+	}
+
+	mux_dev->usb_state = PM_SUSPEND;
+
+
+	spin_lock_irqsave(&rx->submit_list_lock, flags);
+	list_for_each_entry_safe(r, r_next, &rx->rx_submit_list, rx_submit_list) {
+		spin_unlock_irqrestore(&rx->submit_list_lock, flags);
+		usb_kill_urb(r->urb);
+		spin_lock_irqsave(&rx->submit_list_lock, flags);
+	}
+	spin_unlock_irqrestore(&rx->submit_list_lock, flags);
+

drivers/staging/gdm724x/gdm_mux.c line 727

Quoted 10 lines
drivers/staging/gdm724x/gdm_mux.c new file +10 -0
+	return 0;
+}
+
+static int gdm_mux_resume(struct usb_interface *intf)
+{
+	struct tty_dev *tty_dev;
+	struct mux_dev *mux_dev;
+	u8 i;
+
+	/* printk(KERN_INFO "gdm_mux_resume\n"); */

Delete commented out code.

drivers/staging/gdm724x/gdm_mux.c line 740

Quoted 13 lines
drivers/staging/gdm724x/gdm_mux.c new file +13 -0
+
+	tty_dev = usb_get_intfdata(intf);
+	mux_dev = tty_dev->priv_dev;
+
+	if (mux_dev->usb_state != PM_SUSPEND) {
+		printk(KERN_ERR "glte: usb resume - invalid state\n");
+		return -1;
+	}
+
+	mux_dev->usb_state = PM_NORMAL;
+
+	for (i = 0;  i < MAX_ISSUE_NUM; i++)
+		gdm_mux_recv((void *)mux_dev, mux_dev->rx_cb);

No need for the cast.

Quoted 300 lines
drivers/staging/gdm724x/gdm_mux.c new file +49 -0
+
+	return 0;
+}
+#endif /* LTE_USB_PM */
+
+static struct usb_driver gdm_mux_driver = {
+	.name = "gdm_mux",
+	.probe = gdm_mux_probe,
+	.disconnect = gdm_mux_disconnect,
+	.id_table = id_table,
+#ifdef LTE_USB_PM
+	.supports_autosuspend = 1,
+	.suspend = gdm_mux_suspend,
+	.resume = gdm_mux_resume,
+	.reset_resume = gdm_mux_resume,
+#endif /* LTE_USB_PM */
+};
+
+static int __init gdm_usb_mux_init(void)
+{
+
+	mux_rx_wq = create_workqueue("mux_rx_wq");
+	if (mux_rx_wq == NULL) {
+		printk(KERN_ERR "glte: work queue create fail");
+		return -1;
+	}
+
+	register_lte_tty_driver();
+
+	return usb_register(&gdm_mux_driver);
+}
+
+static void __exit gdm_usb_mux_exit(void)
+{
+	unregister_lte_tty_driver();
+
+	if (mux_rx_wq) {
+		flush_workqueue(mux_rx_wq);
+		destroy_workqueue(mux_rx_wq);
+	}
+
+	usb_deregister(&gdm_mux_driver);
+}
+
+module_init(gdm_usb_mux_init);
+module_exit(gdm_usb_mux_exit);
+
+MODULE_DESCRIPTION("GCT LTE TTY Device Driver");
+MODULE_LICENSE("GPL");
drivers/staging/gdm724x/gdm_mux.h new file +77 -0
new file mode 100644
index 0000000..8b5ebee
@@ -0,0 +1,77 @@
+/*
+ * Copyright (c) 2012 GCT Semiconductor, Inc. All rights reserved.
+ *
+ * This software is licensed under the terms of the GNU General Public
+ * License version 2, as published by the Free Software Foundation, and
+ * may be copied, distributed, and modified under those terms.
+ *
+ * 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.
+ */
+
+#ifndef _GDM_MUX_H_
+#define _GDM_MUX_H_
+
+#include <linux/types.h>
+#include <linux/usb.h>
+#include <linux/list.h>
+
+#define H2L(x)		__cpu_to_le16(x)
+#define L2H(x)		__le16_to_cpu(x)
+#define H4L(x)		__cpu_to_le32(x)
+#define L4H(x)		__le32_to_cpu(x)
+
+struct mux_pkt_header {
+	unsigned int start_flag;
+	unsigned int seq_num;
+	unsigned int payload_size;
+	unsigned short packet_type;
+};
+
+struct mux_tx {
+	struct urb *urb;
+	u8 *buf;
+	int  len;
+	void (*callback)(void *cb_data);
+	void *cb_data;
+};
+
+struct mux_rx {
+	struct list_head free_list;
+	struct list_head rx_submit_list;
+	struct list_head to_host_list;
+	struct urb *urb;
+	u8 *buf;
+	void *mux_dev;
+	u32 offset;
+	u32 len;
+	int (*callback)(void *data, int len, int tty_index, int minor, int complete);
+};
+
+struct rx_cxt {
+	struct list_head to_host_list;
+	struct list_head rx_submit_list;
+	struct list_head rx_free_list;
+	spinlock_t to_host_lock;
+	spinlock_t submit_list_lock;
+	spinlock_t free_list_lock;
+};
+
+struct mux_dev {
+	struct usb_device *usbdev;
+	struct usb_interface *control_intf;
+	struct usb_interface *data_intf;
+	struct rx_cxt	rx;
+	struct delayed_work work_rx;
+#ifdef LTE_USB_PM
+	struct usb_interface *intf;
+	int usb_state;
+	int (*rx_cb)(void *data, int len, int tty_index, int minor, int complete);
+#endif /* LTE_USB_PM */
+	spinlock_t write_lock;
+	u8 minor[2];
+};
+
+#endif /* _GDM_MUX_H_ */
drivers/staging/gdm724x/gdm_tty.c new file +162 -0
new file mode 100644
index 0000000..130fce7
@@ -0,0 +1,382 @@
+/*
+ * Copyright (c) 2012 GCT Semiconductor, Inc. All rights reserved.
+ *
+ * This software is licensed under the terms of the GNU General Public
+ * License version 2, as published by the Free Software Foundation, and
+ * may be copied, distributed, and modified under those terms.
+ *
+ * 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.
+ */
+
+#include <linux/version.h>
+#include <linux/kernel.h>
+#include <linux/errno.h>
+#include <linux/init.h>
+#include <linux/tty.h>
+#include <linux/tty_driver.h>
+#include <linux/tty_flip.h>
+#include <linux/module.h>
+#include <linux/slab.h>
+#include <linux/usb/cdc.h>
+#include <linux/serial.h>
+#include "gdm_tty.h"
+
+#define GDM_TTY_MAJOR 0
+#define GDM_TTY_MINOR 32
+
+#define ACM_CTRL_DTR 0x01
+#define ACM_CTRL_RTS 0x02
+#define ACM_CTRL_DSR 0x02
+#define ACM_CTRL_RI  0x08
+#define ACM_CTRL_DCD 0x01
+
+#define WRITE_SIZE 2048
+
+#define MUX_TX_MAX_SIZE 2048
+
+#define gdm_tty_send(n, d, l, i, c, b) (\
+	n->tty_dev->send_func(n->tty_dev->priv_dev, d, l, i, c, b))
+#define gdm_tty_recv(n, c) (\
+	n->tty_dev->recv_func(n->tty_dev->priv_dev, c))
+#define gdm_tty_send_control(n, r, v, d, l) (\
+	n->tty_dev->send_control(n->tty_dev->priv_dev, r, v, d, l))
+
+#define acm_set_comm_feature(n, v)	\
+	gdm_tty_send_control(n, 0x02, v, NULL, 0)
+
+#define GDM_TTY_READY(tty_str) (tty_str && tty_str->tty_dev && tty_str->port.count)
+
+struct tty_driver *g_tty_drv[TTY_MAX_COUNT] = {NULL, };
+struct tty_str *g_tty_str[TTY_MAX_COUNT][GDM_TTY_MINOR] = {{NULL, }, };
+
+static char *DRIVER_STRING[TTY_MAX_COUNT] = {"GCTATC", "GCTDM"};
+static char *DEVICE_STRING[TTY_MAX_COUNT] = {"GCT-ATC", "GCT-DM"};
+
+static DEFINE_MUTEX(open_mutex);
+
+static struct tty_port_operations gdm_tty_port_ops = {
+};
+
+static int gdm_tty_open(struct tty_struct *tty, struct file *filp)
+{
+	struct tty_str *tty_str = NULL;
+	int i;
+	int ret = 0;
+
+	mutex_lock(&open_mutex);
+
+	for (i = 0; i < TTY_MAX_COUNT; i++) {
+		if (!strcmp(tty->driver->driver_name, DRIVER_STRING[i])) {
+			tty_str = g_tty_str[i][tty->index];
+			break;
+		}
+	}
+
+	if (!tty_str) {
+		printk(KERN_INFO "glte: no tty device\n");
+		mutex_unlock(&open_mutex);
+		return -ENODEV;
+	}
+
+	set_bit(TTY_NO_WRITE_SPLIT, &tty->flags);
+
+	tty->driver_data = tty_str;
+	tty_port_tty_set(&tty_str->port, tty);
+	tty_str->port.count++;
+	set_bit(ASYNCB_INITIALIZED, &tty_str->port.flags);
+	ret = tty_port_block_til_ready(&tty_str->port, tty, filp);
+
+	mutex_unlock(&open_mutex);
+
+	return ret;
+}
+
+static void gdm_tty_close(struct tty_struct *tty, struct file *filp)
+{
+	struct tty_str *tty_str = tty->driver_data;
+	int i;
+
+	if (!tty_str) {
+		printk(KERN_INFO "glte: tty device already close\n");
+		return;
+	}
+
+	if (tty_str->port.count != 0) {
+		tty_port_close_start(&tty_str->port, tty, filp);
+		tty_port_close_end(&tty_str->port, tty);
+
+		if (tty_str->port.count == 0)
+			tty_port_tty_set(&tty_str->port, NULL);
+			tty_str->port.tty = NULL;
+	}
+
+	if (!tty_str->tty_dev) {
+		for (i = 0; i < TTY_MAX_COUNT; i++) {
+			if (!strcmp(tty->driver->driver_name, DRIVER_STRING[i]))
+				break;
+		}
+
+		if (i < TTY_MAX_COUNT) {
+			tty_unregister_device(g_tty_drv[i], tty->index);
+			g_tty_str[i][tty->index] = NULL;
+			tty_port_tty_set(&tty_str->port, NULL);
+			kfree(tty_str);
+			printk(KERN_INFO "glte: unregister %s\n", DEVICE_STRING[i]);
+		}
+	}
+
+	tty->driver_data = NULL;
+}
+
+static int gdm_tty_recv_complete(void *data, int len, int index, int minor, int complete)
+{
+	struct tty_str *tty_str = g_tty_str[index][minor];
+	struct tty_struct *tty;
+
+	if (!GDM_TTY_READY(tty_str)) {
+		if (complete == RECV_PACKET_PROCESS_COMPLETE)
+			gdm_tty_recv(tty_str, gdm_tty_recv_complete);
+		return TO_HOST_PORT_CLOSE;
+	}
+
+	if (!data || !len)
+		goto complete_routine;
+
+	tty = tty_port_tty_get(&tty_str->port);
+
+	if (tty_buffer_request_room(tty, len) == len) {
+		tty_insert_flip_string(tty, data, len);
+		tty_flip_buffer_push(tty);
+	} else {
+		tty_kref_put(tty);
+		return TO_HOST_BUFFER_REQUEST_FAIL;
+	}
+
+	tty_kref_put(tty);
+complete_routine:
+	if (complete == RECV_PACKET_PROCESS_COMPLETE)
+		gdm_tty_recv(tty_str, gdm_tty_recv_complete);
+

drivers/staging/gdm724x/gdm_tty.c line 172

Quoted 10 lines
drivers/staging/gdm724x/gdm_tty.c new file +10 -0
+	return TO_HOST_SUCCESS;
+}
+
+static void gdm_tty_send_complete(void *arg)
+{
+	struct tty_str *tty_str = (struct tty_str *)arg;
+	struct tty_struct *tty;
+
+	return;
+

What's the story here? It probably needs a comment or something for this stubbed out function.

Quoted 51 lines
drivers/staging/gdm724x/gdm_tty.c new file +51 -0
+	if (!GDM_TTY_READY(tty_str))
+		return;
+
+	tty = tty_port_tty_get(&tty_str->port);
+	tty_wakeup(tty);
+	tty_kref_put(tty);
+}
+
+static int gdm_tty_write(struct tty_struct *tty, const unsigned char *buf, int len)
+{
+	struct tty_str *tty_str = tty->driver_data;
+	int remain = len;
+	int sent_len = 0;
+	int sending_len = 0;
+
+	if (!GDM_TTY_READY(tty_str))
+		return -ENODEV;
+
+	if (!len)
+		return 0;
+
+	while (1) {
+		sending_len = remain > MUX_TX_MAX_SIZE ? MUX_TX_MAX_SIZE : remain;
+		gdm_tty_send(tty_str,
+			     (void *)(buf+sent_len),
+			     sending_len,
+			     tty_str->tty_drv_index,
+			     gdm_tty_send_complete,
+			     tty_str
+			    );
+		sent_len += sending_len;
+		remain -= sending_len;
+		if (remain <= 0)
+			break;
+	}
+
+	return len;
+}
+
+static int gdm_tty_write_room(struct tty_struct *tty)
+{
+	struct tty_str *tty_str = tty->driver_data;
+
+	if (!GDM_TTY_READY(tty_str))
+		return -ENODEV;
+
+	return WRITE_SIZE;
+}
+
+static int gdm_tty_tiocmget(struct tty_struct *tty)
+{

drivers/staging/gdm724x/gdm_tty.c line 233

Quoted 10 lines
drivers/staging/gdm724x/gdm_tty.c new file +10 -0
+	struct tty_str *tty_str = tty->driver_data;
+
+	if (!GDM_TTY_READY(tty_str))
+		return -ENODEV;
+
+	return (0 & ACM_CTRL_DTR ? TIOCM_DTR : 0) |
+	       (0 & ACM_CTRL_RTS ? TIOCM_RTS : 0) |
+	       (0 & ACM_CTRL_DSR ? TIOCM_DSR : 0) |
+	       (0 & ACM_CTRL_RI  ? TIOCM_RI  : 0) |
+	       (0 & ACM_CTRL_DCD ? TIOCM_CD  : 0) |

I never understand why people do (0 & ... I assume you are planning to add that feature and are stubbing it out for now. Put a big comment why we have these no-ops here.

Quoted 7 lines
drivers/staging/gdm724x/gdm_tty.c new file +7 -0
+	       TIOCM_CTS;
+}
+
+static int gdm_tty_tiocmset(struct tty_struct *tty, unsigned int set, unsigned int clear)
+{
+	struct tty_str *tty_str = tty->driver_data;
+

drivers/staging/gdm724x/gdm_tty.c line 250

Quoted 10 lines
drivers/staging/gdm724x/gdm_tty.c new file +10 -0
+	if (!GDM_TTY_READY(tty_str))
+		return -ENODEV;
+
+	return 1;
+}
+
+int register_lte_tty_device(struct tty_dev *tty_dev, struct device *dev)
+{
+	struct tty_str *tty_str;
+	u8 i, j;
	int i, j;

drivers/staging/gdm724x/gdm_tty.c line 260

Quoted 10 lines
drivers/staging/gdm724x/gdm_tty.c new file +10 -0
+
+	for (i = 0; i < TTY_MAX_COUNT; i++) {
+		for (j = 0; j < GDM_TTY_MINOR; j++) {
+			if (!g_tty_str[i][j])
+				break;
+		}
+
+		if (j == GDM_TTY_MINOR) {
+			tty_dev->minor[i] = j;
+			return -1;

Don't return -1

Quoted 145 lines
drivers/staging/gdm724x/gdm_tty.c new file +122 -0
+		}
+
+		tty_str = kmalloc(sizeof(struct tty_str), GFP_KERNEL);
+		if (!tty_str)
+			return -ENOMEM;
+
+		g_tty_str[i][j] = tty_str;
+
+		tty_str->tty_dev = tty_dev;
+		tty_str->tty_drv_index = i;
+		tty_dev->minor[i] = j;
+		tty_port_init(&tty_str->port);
+		tty_str->port.ops = &gdm_tty_port_ops;
+
+		if (strcmp(DEVICE_STRING[i], "GCT-ATC") != 0)
+			dev = NULL;
+		tty_register_device(g_tty_drv[i], j, dev);
+
+		printk(KERN_INFO "glte: register %s\n", DEVICE_STRING[i]);
+	}
+
+	acm_set_comm_feature(tty_str, 1);
+
+	for (i = 0; i < MAX_ISSUE_NUM; i++)
+		gdm_tty_recv(tty_str, gdm_tty_recv_complete);
+
+	return 0;
+}
+
+void unregister_lte_tty_device(struct tty_dev *tty_dev)
+{
+	struct tty_str *tty_str;
+	struct tty_struct *tty;
+	int i;
+
+	for (i = 0; i < TTY_MAX_COUNT; i++) {
+		if (tty_dev->minor[i] >= GDM_TTY_MINOR)
+			continue;
+
+		tty_str = g_tty_str[i][tty_dev->minor[i]];
+		if (!tty_str)
+			continue;
+
+		tty_str->tty_dev = NULL;
+
+		if (!tty_str->port.count) {
+			tty_unregister_device(g_tty_drv[i], tty_dev->minor[i]);
+			tty_port_tty_set(&tty_str->port, NULL);
+			kfree(tty_str);
+			g_tty_str[i][tty_dev->minor[i]] = NULL;
+			printk(KERN_INFO "glte: unregister %s\n", DEVICE_STRING[i]);
+		} else {
+			tty = tty_port_tty_get(&tty_str->port);
+			if (tty) {
+				tty_hangup(tty);
+				tty_kref_put(tty);
+			}
+		}
+	}
+}
+
+static void gdm_tty_set_termios(struct tty_struct *tty, struct ktermios *termios_old)
+{
+	return;
+}
+
+static const struct tty_operations gdm_tty_ops = {
+	.open = gdm_tty_open,
+	.close = gdm_tty_close,
+	.write = gdm_tty_write,
+	.write_room = gdm_tty_write_room,
+	.tiocmget = gdm_tty_tiocmget,
+	.tiocmset = gdm_tty_tiocmset,
+	.set_termios = gdm_tty_set_termios,
+};
+
+int register_lte_tty_driver(void)
+{
+	struct tty_driver *tty_driver = NULL;
+	int i;
+	int ret;
+
+	for (i = 0; i < TTY_MAX_COUNT; i++) {
+		tty_driver = alloc_tty_driver(GDM_TTY_MINOR);
+		if (!tty_driver) {
+			printk(KERN_ERR "glte: alloc_tty_driver fail\n");
+			return -ENOMEM;
+		}
+
+		tty_driver->owner = THIS_MODULE;
+		tty_driver->driver_name = DRIVER_STRING[i];
+		tty_driver->name = DEVICE_STRING[i];
+		tty_driver->major = GDM_TTY_MAJOR;
+		tty_driver->type = TTY_DRIVER_TYPE_SERIAL;
+		tty_driver->subtype = SERIAL_TYPE_NORMAL;
+		tty_driver->flags = TTY_DRIVER_REAL_RAW | TTY_DRIVER_DYNAMIC_DEV;
+		tty_driver->init_termios = tty_std_termios;
+		tty_driver->init_termios.c_cflag = B9600 | CS8 | HUPCL | CLOCAL;
+		tty_driver->init_termios.c_lflag = ISIG | ICANON | IEXTEN;
+		tty_set_operations(tty_driver, &gdm_tty_ops);
+
+		ret = tty_register_driver(tty_driver);
+
+		g_tty_drv[i] = tty_driver;
+	}
+
+	return ret;
+}
+
+void unregister_lte_tty_driver(void)
+{
+	struct tty_driver *tty_driver;
+	int i;
+
+	for (i = 0; i < TTY_MAX_COUNT; i++) {
+		tty_driver = g_tty_drv[i];
+		if (tty_driver) {
+			tty_unregister_driver(tty_driver);
+			put_tty_driver(tty_driver);
+		}
+	}
+}
drivers/staging/gdm724x/gdm_tty.h new file +17 -0
new file mode 100644
index 0000000..0277175
@@ -0,0 +1,63 @@
+/*
+ * Copyright (c) 2012 GCT Semiconductor, Inc. All rights reserved.
+ *
+ * This software is licensed under the terms of the GNU General Public
+ * License version 2, as published by the Free Software Foundation, and
+ * may be copied, distributed, and modified under those terms.
+ *
+ * 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.
+ */
+
+#ifndef _GDM_TTY_H_
+#define _GDM_TTY_H_
+
+#include <linux/version.h>

drivers/staging/gdm724x/gdm_tty.h line 27

Quoted 10 lines
drivers/staging/gdm724x/gdm_tty.h new file +10 -0
+#include <linux/types.h>
+#include <linux/tty.h>
+
+#define ttydev_priv(tty)	((tty)->driver_data)
+#define TTY_MAX_COUNT		2
+
+#define H2L(x)		__cpu_to_le16(x)
+#define L2H(x)		__le16_to_cpu(x)
+#define H4L(x)		__cpu_to_le32(x)
+#define L4H(x)		__le32_to_cpu(x)

These defines are redefined over and over and over. They were so horrible the first time but by the third time I'm about to go nuts. Hopefully I'm coming to the end of this patch?

Quoted 119 lines
drivers/staging/gdm724x/gdm_tty.h new file +36 -0
+
+#define MAX_ISSUE_NUM 3
+
+enum TO_HOST_RESULT {
+	TO_HOST_SUCCESS = 0,
+	TO_HOST_BUFFER_REQUEST_FAIL = 1,
+	TO_HOST_PORT_CLOSE = 2,
+};
+
+enum RECV_PACKET_PROCESS {
+	RECV_PACKET_PROCESS_COMPLETE = 0,
+	RECV_PACKET_PROCESS_CONTINUE = 1,
+};
+
+struct tty_dev {
+	void *priv_dev;
+	int (*send_func)(void *priv_dev, void *data, int len, int tty_index,
+			void (*cb)(void *cb_data), void *cb_data);
+	int (*recv_func)(void *priv_dev, int (*cb)(void *data, int len, int tty_index, int minor, int complete));
+	int (*send_control)(void *priv_dev, int request, int value, void *data, int len);
+	u8 minor[2];
+};
+
+struct tty_str {
+	struct tty_dev *tty_dev;
+	int tty_drv_index;
+	struct tty_port port;
+};
+
+int register_lte_tty_driver(void);
+void unregister_lte_tty_driver(void);
+int register_lte_tty_device(struct tty_dev *tty_dev, struct device *dev);
+void unregister_lte_tty_device(struct tty_dev *tty_dev);
+
+#endif /* _GDM_USB_H_ */
+
drivers/staging/gdm724x/gdm_usb.c new file +77 -0
new file mode 100644
index 0000000..4e8d519
@@ -0,0 +1,1105 @@
+/*
+ * Copyright (c) 2012 GCT Semiconductor, Inc. All rights reserved.
+ *
+ * This software is licensed under the terms of the GNU General Public
+ * License version 2, as published by the Free Software Foundation, and
+ * may be copied, distributed, and modified under those terms.
+ *
+ * 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.
+ */
+
+#include <linux/module.h>
+#include <linux/version.h>
+#include <linux/kernel.h>
+#include <linux/usb.h>
+#include <linux/sched.h>
+#include <linux/kthread.h>
+#include <linux/usb/cdc.h>
+#include <linux/wait.h>
+#include <linux/if_ether.h>
+#include <linux/pm_runtime.h>
+
+#include "gdm_usb.h"
+#include "gdm_lte.h"
+#include "hci.h"
+#include "hci_packet.h"
+#include "gdm_endian.h"
+
+#ifdef LTE_USB_PM
+#define PM_NORMAL 0
+#define PM_SUSPEND 1
+#define AUTO_SUSPEND_TIMER 5000 /* ms */
+#endif /* LTE_USB_PM */
+
+#define RX_BUF_SIZE		(1024*32)
+#define TX_BUF_SIZE		(1024*32)
+#define SDU_BUF_SIZE	2048
+#define MAX_SDU_SIZE	(1024*30)
+
+
+#define VID_GCT			0x1076
+#define PID_GDM7240		0x8000
+#define PID_GDM7243		0x9000
+
+#define NETWORK_INTERFACE 1
+#define USB_SC_SCSI 0x06
+#define USB_PR_BULK 0x50
+
+#define USB_DEVICE_CDC_DATA(vid, pid) \
+	.match_flags = USB_DEVICE_ID_MATCH_DEVICE | USB_DEVICE_ID_MATCH_INT_CLASS | USB_DEVICE_ID_MATCH_INT_SUBCLASS,\
+	.idVendor = vid,\
+	.idProduct = pid,\
+	.bInterfaceClass = USB_CLASS_COMM,\
+	.bInterfaceSubClass = USB_CDC_SUBCLASS_ETHERNET
+
+#define USB_DEVICE_MASS_DATA(vid, pid) \
+	.match_flags = USB_DEVICE_ID_MATCH_DEVICE | USB_DEVICE_ID_MATCH_INT_INFO,\
+	.idVendor = vid,\
+	.idProduct = pid,\
+	.bInterfaceSubClass = USB_SC_SCSI, \
+	.bInterfaceClass = USB_CLASS_MASS_STORAGE,\
+	.bInterfaceProtocol = USB_PR_BULK
+
+static const struct usb_device_id id_table[] = {
+	{ USB_DEVICE_CDC_DATA(VID_GCT, PID_GDM7240) }, /* GCT GDM7240 */
+	{ USB_DEVICE_CDC_DATA(VID_GCT, PID_GDM7243) }, /* GCT GDM7243 */
+	{ }
+};
+
+MODULE_DEVICE_TABLE(usb, id_table);
+
+static struct workqueue_struct *usb_tx_wq;
+static struct workqueue_struct *usb_rx_wq;
+
+static void do_tx(struct work_struct *work);

drivers/staging/gdm724x/gdm_usb.c line 87

Quoted 10 lines
drivers/staging/gdm724x/gdm_usb.c new file +10 -0
+static void do_rx(struct work_struct *work);
+
+static int gdm_usb_recv(void *priv_dev,
+			int (*cb)(void *cb_data, void *data, int len, int context),
+			void *cb_data,
+			int context);
+
+static int request_mac_address(struct lte_udev *udev)
+{
+	u8 buf[16] = {0,};

This looks like a DMA transfer buffer. It has to be allocated with kmalloc().

Quoted 22 lines
drivers/staging/gdm724x/gdm_usb.c new file +22 -0
+	struct hci_packet *hci = (struct hci_packet *)buf;
+	struct usb_device *usbdev = udev->usbdev;
+	int actual;
+	int ret = -1;
+
+	hci->cmd_evt = H2D(&udev->gdm_ed, LTE_GET_INFORMATION);
+	hci->len = H2D(&udev->gdm_ed, 1);
+	hci->data[0] = MAC_ADDRESS;
+
+	ret = usb_bulk_msg(usbdev, usb_sndbulkpipe(usbdev, 2), buf, 5,
+		     &actual, 1000);
+
+	udev->request_mac_addr = 1;
+
+	return ret;
+}
+
+static struct usb_tx *alloc_tx_struct(int len)
+{
+	struct usb_tx *t = NULL;
+	int ret = 0;
+

drivers/staging/gdm724x/gdm_usb.c line 119

Quoted 10 lines
drivers/staging/gdm724x/gdm_usb.c new file +10 -0
+	t = kmalloc(sizeof(struct usb_tx), GFP_ATOMIC);
+	if (!t) {
+		ret = -ENOMEM;
+		goto out;
+	}
+	memset(t, 0, sizeof(struct usb_tx));
+
+	t->urb = usb_alloc_urb(0, GFP_ATOMIC);
+	if (!(len % 512))
+		len++;

Why are we not allowed multiples of 512?

Quoted 94 lines
drivers/staging/gdm724x/gdm_usb.c new file +94 -0
+
+	t->buf = kmalloc(len, GFP_ATOMIC);
+	if (!t->urb || !t->buf) {
+		ret = -ENOMEM;
+		goto out;
+	}
+
+out:
+	if (ret < 0) {
+		if (t) {
+			usb_free_urb(t->urb);
+			kfree(t->buf);
+			kfree(t);
+		}
+		return NULL;
+	}
+
+	return t;
+}
+
+static struct usb_tx_sdu *alloc_tx_sdu_struct(void)
+{
+	struct usb_tx_sdu *t_sdu = NULL;
+	int ret = 0;
+
+
+	t_sdu = kmalloc(sizeof(struct usb_tx_sdu), GFP_ATOMIC);
+	if (!t_sdu) {
+		ret = -ENOMEM;
+		goto out;
+	}
+	memset(t_sdu, 0, sizeof(struct usb_tx_sdu));
+
+	t_sdu->buf = kmalloc(SDU_BUF_SIZE, GFP_ATOMIC);
+	if (!t_sdu->buf) {
+		ret = -ENOMEM;
+		goto out;
+	}
+out:
+
+	if (ret < 0) {
+		if (t_sdu) {
+			kfree(t_sdu->buf);
+			kfree(t_sdu);
+		}
+		return NULL;
+	}
+
+	return t_sdu;
+}
+
+static void free_tx_struct(struct usb_tx *t)
+{
+	if (t) {
+		usb_free_urb(t->urb);
+		kfree(t->buf);
+		kfree(t);
+	}
+}
+
+static void free_tx_sdu_struct(struct usb_tx_sdu *t_sdu)
+{
+	if (t_sdu) {
+		kfree(t_sdu->buf);
+		kfree(t_sdu);
+	}
+}
+
+static struct usb_tx_sdu *get_tx_sdu_struct(struct tx_cxt *tx, int *no_spc)
+{
+	struct usb_tx_sdu *t_sdu;
+
+	if (list_empty(&tx->free_list))
+		return NULL;
+
+	t_sdu = list_entry(tx->free_list.next, struct usb_tx_sdu, list);
+	list_del(&t_sdu->list);
+
+	tx->avail_count--;
+
+	*no_spc = list_empty(&tx->free_list) ? 1 : 0;
+
+	return t_sdu;
+}
+
+static void put_tx_struct(struct tx_cxt *tx, struct usb_tx_sdu *t_sdu)
+{
+	list_add_tail(&t_sdu->list, &tx->free_list);
+	tx->avail_count++;
+}
+
+static struct usb_rx *alloc_rx_struct(void)
+{
+	struct usb_rx *r = NULL;

drivers/staging/gdm724x/gdm_usb.c line 223

Quoted 10 lines
drivers/staging/gdm724x/gdm_usb.c new file +10 -0
+	int ret = 0;
+
+	r = kmalloc(sizeof(struct usb_rx), GFP_ATOMIC);
+	if (!r) {
+		ret = -ENOMEM;
+		goto out;
+	}
+
+	r->urb = usb_alloc_urb(0, GFP_ATOMIC);
+	r->buf = kmalloc(RX_BUF_SIZE, GFP_ATOMIC);

We're allocating huge chunks of memory here. I don't think it needs to be atomic also.

Quoted 113 lines
drivers/staging/gdm724x/gdm_usb.c new file +113 -0
+	if (!r->urb || !r->buf) {
+		ret = -ENOMEM;
+		goto out;
+	}
+out:
+
+	if (ret < 0) {
+		if (r) {
+			usb_free_urb(r->urb);
+			kfree(r->buf);
+			kfree(r);
+		}
+		return NULL;
+	}
+
+	return r;
+}
+
+static void free_rx_struct(struct usb_rx *r)
+{
+	if (r) {
+		usb_free_urb(r->urb);
+		kfree(r->buf);
+		kfree(r);
+	}
+}
+
+static struct usb_rx *get_rx_struct(struct rx_cxt *rx, int *no_spc)
+{
+	struct usb_rx *r;
+	unsigned long flags;
+
+	spin_lock_irqsave(&rx->rx_lock, flags);
+
+	if (list_empty(&rx->free_list)) {
+		spin_unlock_irqrestore(&rx->rx_lock, flags);
+		return NULL;
+	}
+
+	r = list_entry(rx->free_list.next, struct usb_rx, free_list);
+	list_del(&r->free_list);
+
+	rx->avail_count--;
+
+	*no_spc = list_empty(&rx->free_list) ? 1 : 0;
+
+	spin_unlock_irqrestore(&rx->rx_lock, flags);
+
+	return r;
+}
+
+static void put_rx_struct(struct rx_cxt *rx, struct usb_rx *r)
+{
+	unsigned long flags;
+
+	spin_lock_irqsave(&rx->rx_lock, flags);
+
+	list_add_tail(&r->free_list, &rx->free_list);
+	rx->avail_count++;
+
+	spin_unlock_irqrestore(&rx->rx_lock, flags);
+}
+
+static void release_usb(struct lte_udev *udev)
+{
+	struct rx_cxt	*rx = &udev->rx;
+	struct tx_cxt	*tx = &udev->tx;
+	struct usb_tx	*t, *t_next;
+	struct usb_rx	*r, *r_next;
+	struct usb_tx_sdu	*t_sdu, *t_sdu_next;
+	unsigned long flags;
+
+	spin_lock_irqsave(&tx->lock, flags);
+	list_for_each_entry_safe(t_sdu, t_sdu_next, &tx->sdu_list, list)
+	{
+		list_del(&t_sdu->list);
+		free_tx_sdu_struct(t_sdu);
+	}
+
+	list_for_each_entry_safe(t, t_next, &tx->hci_list, list)
+	{
+		list_del(&t->list);
+		free_tx_struct(t);
+	}
+
+	list_for_each_entry_safe(t_sdu, t_sdu_next, &tx->free_list, list)
+	{
+		list_del(&t_sdu->list);
+		free_tx_sdu_struct(t_sdu);
+	}
+	spin_unlock_irqrestore(&tx->lock, flags);
+
+	spin_lock_irqsave(&rx->submit_lock, flags);
+	list_for_each_entry_safe(r, r_next, &rx->rx_submit_list, rx_submit_list)
+	{
+		spin_unlock_irqrestore(&rx->submit_lock, flags);
+		usb_kill_urb(r->urb);
+		spin_lock_irqsave(&rx->submit_lock, flags);
+	}
+	spin_unlock_irqrestore(&rx->submit_lock, flags);
+
+	spin_lock_irqsave(&rx->rx_lock, flags);
+	list_for_each_entry_safe(r, r_next, &rx->free_list, free_list)
+	{
+		list_del(&r->free_list);
+		free_rx_struct(r);
+	}
+	spin_unlock_irqrestore(&rx->rx_lock, flags);
+
+	spin_lock_irqsave(&rx->to_host_lock, flags);
+	list_for_each_entry_safe(r, r_next, &rx->to_host_list, to_host_list)
+	{
+		if (r->index == (void *)udev) {

drivers/staging/gdm724x/gdm_usb.c line 346

Quoted 10 lines
drivers/staging/gdm724x/gdm_usb.c new file +10 -0
+			list_del(&r->to_host_list);
+			free_rx_struct(r);
+		}
+	}
+	spin_unlock_irqrestore(&rx->to_host_lock, flags);
+}
+
+static int init_usb(struct lte_udev *udev)
+{
+#define MAX_NUM_SDU_BUF	64

Put these things in a header file.

Quoted 33 lines
drivers/staging/gdm724x/gdm_usb.c new file +33 -0
+	int ret = 0;
+	int i;
+	struct tx_cxt *tx = &udev->tx;
+	struct rx_cxt *rx = &udev->rx;
+	struct usb_tx_sdu *t_sdu = NULL;
+	struct usb_rx *r = NULL;
+	unsigned long flags;
+
+	udev->send_complete = 1;
+	udev->tx_stop = 0;
+	udev->request_mac_addr = 0;
+
+#ifdef LTE_USB_PM
+	udev->usb_state = PM_NORMAL;
+#endif /* LTE_USB_PM */
+
+
+	INIT_LIST_HEAD(&tx->sdu_list);
+	INIT_LIST_HEAD(&tx->hci_list);
+	INIT_LIST_HEAD(&tx->free_list);
+	INIT_LIST_HEAD(&rx->rx_submit_list);
+	INIT_LIST_HEAD(&rx->free_list);
+	INIT_LIST_HEAD(&rx->to_host_list);
+	spin_lock_init(&tx->lock);
+	spin_lock_init(&rx->rx_lock);
+	spin_lock_init(&rx->submit_lock);
+	spin_lock_init(&rx->to_host_lock);
+
+	tx->avail_count = 0;
+	rx->avail_count = 0;
+
+#ifdef LTE_USB_PM
+	udev->rx_cb = NULL;

drivers/staging/gdm724x/gdm_usb.c line 389

Quoted 10 lines
drivers/staging/gdm724x/gdm_usb.c new file +10 -0
+#endif /* LTE_USB_PM */
+
+	for (i = 0; i < MAX_NUM_SDU_BUF; i++) {
+		t_sdu = alloc_tx_sdu_struct();
+		if (t_sdu == NULL) {
+			ret = -ENOMEM;
+			goto fail;
+		}
+
+		spin_lock_irqsave(&tx->lock, flags);

Do we need this locking in the init() fuction? What are we racing against?

Quoted 20 lines
drivers/staging/gdm724x/gdm_usb.c new file +20 -0
+		list_add(&t_sdu->list, &tx->free_list);
+		tx->avail_count++;
+		spin_unlock_irqrestore(&tx->lock, flags);
+	}
+
+	for (i = 0; i < MAX_RX_SUBMIT_COUNT*2; i++) {
+		r = alloc_rx_struct();
+		if (r == NULL) {
+			ret = -ENOMEM;
+			goto fail;
+		}
+
+		spin_lock_irqsave(&rx->rx_lock, flags);
+		list_add(&r->free_list, &rx->free_list);
+		rx->avail_count++;
+		spin_unlock_irqrestore(&rx->rx_lock, flags);
+	}
+	INIT_DELAYED_WORK(&udev->work_tx, do_tx);
+	INIT_DELAYED_WORK(&udev->work_rx, do_rx);
+	return 0;

drivers/staging/gdm724x/gdm_usb.c line 419

Quoted 10 lines
drivers/staging/gdm724x/gdm_usb.c new file +10 -0
+fail:
+	return ret;
+}
+
+static int set_mac_address(u8 *data, void *arg)
+{
+	struct phy_dev *phy_dev = (struct phy_dev *)arg;
+	struct lte_udev *udev = phy_dev->priv_dev;
+	struct tlv *tlv = (struct tlv *)data;
+	u8 mac_address[6] = {0, };

ETH_ALEN

Quoted 203 lines
drivers/staging/gdm724x/gdm_usb.c new file +203 -0
+
+	if (tlv->type == MAC_ADDRESS && udev->request_mac_addr) {
+		memcpy(mac_address, tlv->data, tlv->len);
+
+		if (register_lte_device(phy_dev, &udev->intf->dev, mac_address) < 0)
+			printk(KERN_ERR "glte: register lte device failed\n");
+
+		udev->request_mac_addr = 0;
+
+		return 1;
+	}
+
+	return 0;
+}
+
+static void do_rx(struct work_struct *work)
+{
+	struct lte_udev *udev = container_of(work, struct lte_udev, work_rx.work);
+	struct rx_cxt *rx = &udev->rx;
+	struct usb_rx *r;
+	struct hci_packet *hci;
+	struct phy_dev *phy_dev;
+	u16 cmd_evt;
+	int ret;
+	unsigned long flags;
+
+	while (1) {
+		spin_lock_irqsave(&rx->to_host_lock, flags);
+		if (list_empty(&rx->to_host_list)) {
+			spin_unlock_irqrestore(&rx->to_host_lock, flags);
+			break;
+		}
+		r = list_entry(rx->to_host_list.next, struct usb_rx, to_host_list);
+		list_del(&r->to_host_list);
+		spin_unlock_irqrestore(&rx->to_host_lock, flags);
+
+		phy_dev = (struct phy_dev *)r->cb_data;
+		udev = (struct lte_udev *)phy_dev->priv_dev;
+		hci = (struct hci_packet *)r->buf;
+		cmd_evt = D2H(&udev->gdm_ed, hci->cmd_evt);
+
+		switch (cmd_evt) {
+		case LTE_GET_INFORMATION_RESULT:
+			if (set_mac_address(hci->data, r->cb_data) == 0) {
+				ret = r->callback(r->cb_data,
+						  r->buf,
+						  r->urb->actual_length,
+						  KERNEL_THREAD);
+			}
+			break;
+
+		default:
+			if (r->callback) {
+				ret = r->callback(r->cb_data,
+						  r->buf,
+						  r->urb->actual_length,
+						  KERNEL_THREAD);
+
+				if (ret == -EAGAIN)
+					printk(KERN_ERR "glte: failed to send received data\n");
+			}
+			break;
+		}
+
+		put_rx_struct(rx, r);
+
+		gdm_usb_recv(udev,
+			     r->callback,
+			     r->cb_data,
+			     USB_COMPLETE);
+	}
+}
+
+static void remove_rx_submit_list(struct usb_rx *r, struct rx_cxt *rx)
+{
+	unsigned long flags;
[… more lines in the raw message]

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

drivers/staging/gdm724x/gdm_usb.c line 505

Quoted 10 lines
drivers/staging/gdm724x/gdm_usb.c new file +10 -0
+	struct usb_rx	*r_remove, *r_remove_next;
+
+	spin_lock_irqsave(&rx->submit_lock, flags);
+	list_for_each_entry_safe(r_remove, r_remove_next, &rx->rx_submit_list, rx_submit_list)
+	{
+		if (r == r_remove) {
+			list_del(&r->rx_submit_list);
+			break;
+		}
+	}
[… more lines in the raw message]

What does this do? We have it other places as well.

drivers/staging/gdm724x/gdm_usb.c

Quoted 33 lines
drivers/staging/gdm724x/gdm_usb.c new file +33 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

	while (num_packet < 256) {

or better yet:

	while (num_packet < SOMETHING_MAX_PACKET) {

drivers/staging/gdm724x/gdm_usb.c

Quoted 45 lines
drivers/staging/gdm724x/gdm_usb.c new file +45 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Put a blank line between declarations and code.

drivers/staging/gdm724x/gdm_usb.c

Quoted 30 lines
drivers/staging/gdm724x/gdm_usb.c new file +30 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

No error checking here.

drivers/staging/gdm724x/gdm_usb.c

Quoted 98 lines
drivers/staging/gdm724x/gdm_usb.c new file +98 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

kmalloc() already has much better error messages than this. Just return -ENOMEM directly.

drivers/staging/gdm724x/gdm_usb.c

Quoted 46 lines
drivers/staging/gdm724x/gdm_usb.c new file +46 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Surely the prope() can use GFP_KERNEL.

Quoted 767 lines
drivers/staging/gdm724x/gdm_usb.c new file +221 -0

Lines of this file are not shown. View the raw message.

drivers/staging/gdm724x/gdm_usb.h new file +92 -0
new file mode 100644
index 0000000..c6118fc

Lines of this file are not shown. View the raw message.

drivers/staging/gdm724x/hci.h new file +55 -0
new file mode 100644
index 0000000..9a591b0

Lines of this file are not shown. View the raw message.

drivers/staging/gdm724x/hci_packet.h new file +97 -0
new file mode 100644
index 0000000..cef381f

Lines of this file are not shown. View the raw message.

drivers/staging/gdm724x/lte_ioctl.h new file +73 -0
new file mode 100644
index 0000000..8941ebf7

Lines of this file are not shown. View the raw message.

drivers/staging/gdm724x/netlink_k.c new file +161 -0
new file mode 100644
index 0000000..d5170f6

Lines of this file are not shown. View the raw message.

drivers/staging/gdm724x/netlink_k.h new file +25 -0
new file mode 100644
index 0000000..589486d

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Signature · 6 lines
1.7.10.4

_______________________________________________
devel mailing list
[email protected]
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

Part of the diff is not shown here. View the raw message.

author
#5 lore raw

PATCH v2 1/2 staging: gdm7240: adding LTE USB driver

In reply to Won Kang

GCT Semiconductor GDM7240 is 4G LTE chip.
This driver supports GCT reference platform as a USB device.

staging: gdm7240: added contacts for code maintanance

staging: gdm7240: style fixes

---
v2: cleanup and minor fixes

 drivers/staging/Kconfig              |    2 +
 drivers/staging/Makefile             |    1 +
 drivers/staging/gdm724x/Kconfig      |   15 +
 drivers/staging/gdm724x/Makefile     |    7 +
 drivers/staging/gdm724x/TODO         |   15 +
 drivers/staging/gdm724x/gdm_endian.c |   67 +++
 drivers/staging/gdm724x/gdm_endian.h |   49 ++
 drivers/staging/gdm724x/gdm_lte.c    |  920 +++++++++++++++++++++++++++++
 drivers/staging/gdm724x/gdm_lte.h    |   80 +++
 drivers/staging/gdm724x/gdm_mux.c    |  700 +++++++++++++++++++++++
 drivers/staging/gdm724x/gdm_mux.h    |   85 +++
 drivers/staging/gdm724x/gdm_tty.c    |  367 ++++++++++++
 drivers/staging/gdm724x/gdm_tty.h    |   59 ++
 drivers/staging/gdm724x/gdm_usb.c    | 1047 ++++++++++++++++++++++++++++++++++
 drivers/staging/gdm724x/gdm_usb.h    |  110 ++++
 drivers/staging/gdm724x/hci.h        |   55 ++
 drivers/staging/gdm724x/hci_packet.h |   93 +++
 drivers/staging/gdm724x/lte_ioctl.h  |   58 ++
 drivers/staging/gdm724x/netlink_k.c  |  161 ++++++
 drivers/staging/gdm724x/netlink_k.h  |   25 +
 20 files changed, 3916 insertions(+)
 create mode 100644 drivers/staging/gdm724x/Kconfig
 create mode 100644 drivers/staging/gdm724x/Makefile
 create mode 100644 drivers/staging/gdm724x/TODO
 create mode 100644 drivers/staging/gdm724x/gdm_endian.c
 create mode 100644 drivers/staging/gdm724x/gdm_endian.h
 create mode 100644 drivers/staging/gdm724x/gdm_lte.c
 create mode 100644 drivers/staging/gdm724x/gdm_lte.h
 create mode 100644 drivers/staging/gdm724x/gdm_mux.c
 create mode 100644 drivers/staging/gdm724x/gdm_mux.h
 create mode 100644 drivers/staging/gdm724x/gdm_tty.c
 create mode 100644 drivers/staging/gdm724x/gdm_tty.h
 create mode 100644 drivers/staging/gdm724x/gdm_usb.c
 create mode 100644 drivers/staging/gdm724x/gdm_usb.h
 create mode 100644 drivers/staging/gdm724x/hci.h
 create mode 100644 drivers/staging/gdm724x/hci_packet.h
 create mode 100644 drivers/staging/gdm724x/lte_ioctl.h
 create mode 100644 drivers/staging/gdm724x/netlink_k.c
 create mode 100644 drivers/staging/gdm724x/netlink_k.h
drivers/staging/Kconfig +2 -0
index 57d8b34..d55bc34 100644
@@ -118,6 +118,8 @@ source "drivers/staging/ozwpan/Kconfig"
 
 source "drivers/staging/gdm72xx/Kconfig"
 
+source "drivers/staging/gdm724x/Kconfig"
+
 source "drivers/staging/silicom/Kconfig"
 
 source "drivers/staging/ced1401/Kconfig"
drivers/staging/Makefile +1 -0
index 429321f..c23cf3b 100644
@@ -52,6 +52,7 @@ obj-$(CONFIG_MFD_NVEC)		+= nvec/
 obj-$(CONFIG_ANDROID)		+= android/
 obj-$(CONFIG_USB_WPAN_HCD)	+= ozwpan/
 obj-$(CONFIG_WIMAX_GDM72XX)	+= gdm72xx/
+obj-$(CONFIG_LTE_GDM724X)	+= gdm724x/
 obj-$(CONFIG_NET_VENDOR_SILICOM)	+= silicom/
 obj-$(CONFIG_CED1401)		+= ced1401/
 obj-$(CONFIG_DRM_IMX)		+= imx-drm/
drivers/staging/gdm724x/Kconfig new file +15 -0
new file mode 100644
index 0000000..10f7be1
@@ -0,0 +1,15 @@
+#
+# GCT GDM724x LTE driver configuration
+#
+
+config LTE_GDM724X
+	tristate "GCT GDM724x LTE support"
+	depends on NET && USB
+	help
+	  This driver supports GCT GDM724x LTE chip based USB modem devices.
+	  It exposes 4 network devices to be used per PDN and 2 tty devices to be
+	  used for AT commands and DM monitoring applications.
+	  The modules will be called gdmulte.ko and gdmtty.ko
+
+	  GCT-ATCx can be used for AT Commands
+	  GCT-DMx can be used for LTE protocol monitoring
drivers/staging/gdm724x/Makefile new file +7 -0
new file mode 100644
index 0000000..ba7f11a
@@ -0,0 +1,7 @@
+obj-$(CONFIG_LTE_GDM724X) := gdmulte.o
+gdmulte-y += gdm_lte.o netlink_k.o
+gdmulte-y += gdm_usb.o gdm_endian.o
+
+obj-$(CONFIG_LTE_GDM724X) += gdmtty.o
+gdmtty-y := gdm_tty.o gdm_mux.o
+
drivers/staging/gdm724x/TODO new file +15 -0
new file mode 100644
index 0000000..cd89214
@@ -0,0 +1,15 @@
+TODO:
+- Clean up coding style to meet kernel standard. (80 line limit, netdev_err)
+- Remove test for host endian
+- Remove confusing macros (endian, hci_send, sdu_send, rcv_with_cb)
+- Fixes for every instances of function returning -1
+- Check for skb->len in gdm_lte_emulate_arp()
+- Use ALIGN() macro for dummy_cnt in up_to_host()
+- Error handling in init_usb()
+- Explain reason for multiples of 512 bytes in alloc_tx_struct()
+- Review use of atomic allocation for tx structs
+- No error checking for alloc_tx_struct in do_tx()
+
+Patches to:
+	Jonathan Kim <[email protected]>
+	Dean ahn <[email protected]>
drivers/staging/gdm724x/gdm_endian.c new file +67 -0

67 lines not on this page · raw message

drivers/staging/gdm724x/gdm_endian.h new file +49 -0

49 lines not on this page · raw message

drivers/staging/gdm724x/gdm_lte.c new file +920 -0

920 lines not on this page · raw message

drivers/staging/gdm724x/gdm_lte.h new file +80 -0

80 lines not on this page · raw message

drivers/staging/gdm724x/gdm_mux.c new file +700 -0

700 lines not on this page · raw message

drivers/staging/gdm724x/gdm_mux.h new file +85 -0

85 lines not on this page · raw message

drivers/staging/gdm724x/gdm_tty.c new file +367 -0

367 lines not on this page · raw message

drivers/staging/gdm724x/gdm_tty.h new file +59 -0

59 lines not on this page · raw message

drivers/staging/gdm724x/gdm_usb.c new file +1047 -0

621 lines not on this page · raw message

drivers/staging/gdm724x/gdm_usb.h new file +110 -0

110 lines not on this page · raw message

drivers/staging/gdm724x/hci.h new file +55 -0

55 lines not on this page · raw message

drivers/staging/gdm724x/hci_packet.h new file +93 -0

93 lines not on this page · raw message

drivers/staging/gdm724x/lte_ioctl.h new file +58 -0

58 lines not on this page · raw message

drivers/staging/gdm724x/netlink_k.c new file +161 -0

161 lines not on this page · raw message

drivers/staging/gdm724x/netlink_k.h new file +25 -0
new file mode 100644
index 0000000..589486d

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Signature · 1 line
1.7.10.4

Part of the diff is not shown here. View the raw message.

#7 lore raw

회신: Re: [PATCH v2 1/2] staging: gdm7240: adding LTE USB driver

Hi Joe,

Got it. Thanks

Regards,
Won

-------- 원본 메시지 --------
발신: Joe Perches <[email protected]>
날짜: 2013/07/25 오전 3:42 (GMT+09:00)
수신: Won Kang <[email protected]>
참조: [email protected],[email protected],[email protected],Won Kang <[email protected]> 제목: Re: [PATCH v2 1/2] staging: gdm7240: adding LTE USB driver

Quoted 5 lines · Won Kang

GCT Semiconductor GDM7240 is 4G LTE chip.
This driver supports GCT reference platform as a USB device.

Quoted 7 lines

staging: gdm7240: added contacts for code maintanance

staging: gdm7240: style fixes

Hi Won.

Please don't sign off multiple times on one patch.

�淸�{.n�+돴윯돪�+%듚�깁負쪐w��{.n�+돴쪐{깸G쳺��{ay����,j�f"톒쉹��묎�z_溫(�쉸듶줷"얎�m����G쳺�◀?솳鈺�&x�~뤳턨O뺞촾퇉v�^�m��� �띠�◀?뻀�

maintainer
#8 lore raw
In reply to Won Kang
Quoted 2 lines · Won Kang

GCT Semiconductor GDM7240 is 4G LTE chip.
This driver supports GCT reference platform as a USB device.

I've applied this now, and fixed up the tty build warnings (which you should have also seen.) I'm not sure I got the tty fixes correct, can you test the changes that I made to ensure it still works properly now?

thanks,

greg k-h

#9 lore raw
In reply to Won Kang
Quoted 1 line · Won Kang

+- Explain reason for multiples of 512 bytes in alloc_tx_struct()

Actually I remembered that I had seen this before in gdm_usb_send() from drivers/staging/gdm72xx/gdm_usb.c. Apparently there is a firmware bug.

        /*
         * In some cases, USB Module of WiMax is blocked when data size is
         * the multiple of 512. So, increment length by one in that case.
         */
	if ((len % 512) == 0)
        	len++;

regards,
dan carpenter

#10 lore raw
In reply to Won Kang
Quoted 5 lines
drivers/staging/gdm724x/gdm_lte.c new file +5 -0
+static int gdm_lte_ioctl_get_data(struct wm_req_t *req, struct net_device *dev)
+{
+	u16 id = req->data_id;
+
+	switch (id) {

drivers/staging/gdm724x/gdm_lte.c line 524

Quoted 10 lines
drivers/staging/gdm724x/gdm_lte.c new file +10 -0
+	case GET_ENDIAN_INFO:
+		/* required for the user space application to find out device endian */
+		get_dev_endian(&req->data, dev);
+		break;
+	default:
+		printk(KERN_ERR "glte: ioctl - unknown type %d\n", id);
+		break;
+	}
+	return 0;
+}

This should be a sysfs file not an ioctl. What would break if we fixed this right now (as opposed to waiting until we can't change the API?).

Otherwise if we can't change this, then it should return an error code instead of printing a message.

regards,
dan carpenter

maintainer
#11 lore raw
Quoted 20 lines · Dan Carpenter
Quoted 5 lines
drivers/staging/gdm724x/gdm_lte.c new file +5 -0
+static int gdm_lte_ioctl_get_data(struct wm_req_t *req, struct net_device *dev)
+{
+	u16 id = req->data_id;
+
+	switch (id) {

drivers/staging/gdm724x/gdm_lte.c line 524

Quoted 10 lines
drivers/staging/gdm724x/gdm_lte.c new file +10 -0
+	case GET_ENDIAN_INFO:
+		/* required for the user space application to find out device endian */
+		get_dev_endian(&req->data, dev);
+		break;
+	default:
+		printk(KERN_ERR "glte: ioctl - unknown type %d\n", id);
+		break;
+	}
+	return 0;
+}

This should be a sysfs file not an ioctl. What would break if we fixed this right now (as opposed to waiting until we can't change the API?).

Quoted 2 lines

Otherwise if we can't change this, then it should return an error code instead of printing a message.

It should just be removed, why would you care about the endian-ness of the device at all?

thanks,

greg k-h

author
#12 lore raw

GDM7240 is in LE where as GDM7243 (currently under development) is in BE.

User space applications needs to discover the endianess to properly encode/decode LTE control protocols. We have existing customers already deploying units in large volume, and want to avoid forcing them to change SDK APIs along with kernel updates.
At some point, It will have to be fixed with SDK API can interoperate properly.

Quoted 30 lines · Greg KH
Quoted 20 lines · Dan Carpenter
Quoted 5 lines
drivers/staging/gdm724x/gdm_lte.c new file +5 -0
+static int gdm_lte_ioctl_get_data(struct wm_req_t *req, struct net_device *dev)
+{
+   u16 id = req->data_id;
+
+   switch (id) {

drivers/staging/gdm724x/gdm_lte.c line 524

Quoted 10 lines
drivers/staging/gdm724x/gdm_lte.c new file +10 -0
+   case GET_ENDIAN_INFO:
+           /* required for the user space application to find out device endian */
+           get_dev_endian(&req->data, dev);
+           break;
+   default:
+           printk(KERN_ERR "glte: ioctl - unknown type %d\n", id);
+           break;
+   }
+   return 0;
+}

This should be a sysfs file not an ioctl. What would break if we fixed this right now (as opposed to waiting until we can't change the API?).

Quoted 2 lines

Otherwise if we can't change this, then it should return an error code instead of printing a message.

It should just be removed, why would you care about the endian-ness of the device at all?

thanks,

greg k-h

maintainer
#13 lore raw

A: No.
Q: Should I include quotations after my reply?

http://daringfireball.net/2007/07/on_top

Quoted 1 line · Won Kang

GDM7240 is in LE where as GDM7243 (currently under development) is in BE.

But why does this information need to be sent to userspace?

Quoted 5 lines

User space applications needs to discover the endianess to properly encode/decode LTE control protocols. We have existing customers already deploying units in large volume, and want to avoid forcing them to change SDK APIs along with kernel updates.
At some point, It will have to be fixed with SDK API can interoperate properly.

Ugh, really? What special tools does userspace need to talk to this device? It "should" just be a network device, and a serial port, why does the endianness of the device mean anything?

Custom ioctls aren't ok for new drivers, if at all possible. Can't userspace just trigger this based on the device id instead?

thanks,

greg k-h

author
#14 lore raw
Quoted 4 lines
Quoted 1 line

GDM7240 is in LE where as GDM7243 (currently under development) is in BE.

But why does this information need to be sent to userspace?

GDM724x chips have different endianess because of their internal architecture.The device sends out and accepts LTE protocol information in its own endianess. This is the design decision we made and we let the host converts the byte order. To decode the protocols, userspace needs this endianess information.

Quoted 9 lines
Quoted 5 lines

User space applications needs to discover the endianess to properly encode/decode LTE control protocols. We have existing customers already deploying units in large volume, and want to avoid forcing them to change SDK APIs along with kernel updates.
At some point, It will have to be fixed with SDK API can interoperate properly.

Ugh, really? What special tools does userspace need to talk to this device? It "should" just be a network device, and a serial port, why does the endianness of the device mean anything?

Just like 3G modems, network device and a serial port is enough for basic operation. For this, no ioctl for endianess is required. However, customers and operators want more information and programming capabilities, and this is really difficult to achieve with standard 3GPP AT commands alone. Therefore, if wanted, we also provide SDK APIs for handling more advanced features. Examples of such information include detailed connection status, rf controls, debug logs, and even firmware download.

Quoted 2 lines

Custom ioctls aren't ok for new drivers, if at all possible. Can't userspace just trigger this based on the device id instead?

Historically, the SDK is cross-platform designed and we wanted to have common methods for different operating systems, and have chosen to use ioctl. Windows does have one :). We will probably go with reading device id

Anyway, you are right that endianess matters only when using this SDK. If you suggest to remove the ioctl because SDK is optional, I will agree.

Regards,
Won.

maintainer
#15 lore raw
Quoted 3 lines · Won Kang

Anyway, you are right that endianess matters only when using this SDK. If you suggest to remove the ioctl because SDK is optional, I will agree.

Thanks, I've now removed it from the driver.

greg k-h