xref: /openbmc/linux/drivers/net/usb/lg-vl600.c (revision 7a635ea989991d7f12d57a12f2ba7cb6d211e083)
1*7a635ea9SAndrzej Zaborowski /*
2*7a635ea9SAndrzej Zaborowski  * Ethernet interface part of the LG VL600 LTE modem (4G dongle)
3*7a635ea9SAndrzej Zaborowski  *
4*7a635ea9SAndrzej Zaborowski  * Copyright (C) 2011 Intel Corporation
5*7a635ea9SAndrzej Zaborowski  * Author: Andrzej Zaborowski <balrogg@gmail.com>
6*7a635ea9SAndrzej Zaborowski  *
7*7a635ea9SAndrzej Zaborowski  * This program is free software; you can redistribute it and/or modify
8*7a635ea9SAndrzej Zaborowski  * it under the terms of the GNU General Public License as published by
9*7a635ea9SAndrzej Zaborowski  * the Free Software Foundation; either version 2 of the License, or
10*7a635ea9SAndrzej Zaborowski  * (at your option) any later version.
11*7a635ea9SAndrzej Zaborowski  *
12*7a635ea9SAndrzej Zaborowski  * This program is distributed in the hope that it will be useful,
13*7a635ea9SAndrzej Zaborowski  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14*7a635ea9SAndrzej Zaborowski  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15*7a635ea9SAndrzej Zaborowski  * GNU General Public License for more details.
16*7a635ea9SAndrzej Zaborowski  *
17*7a635ea9SAndrzej Zaborowski  * You should have received a copy of the GNU General Public License
18*7a635ea9SAndrzej Zaborowski  * along with this program; if not, write to the Free Software
19*7a635ea9SAndrzej Zaborowski  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
20*7a635ea9SAndrzej Zaborowski  */
21*7a635ea9SAndrzej Zaborowski #include <linux/etherdevice.h>
22*7a635ea9SAndrzej Zaborowski #include <linux/ethtool.h>
23*7a635ea9SAndrzej Zaborowski #include <linux/mii.h>
24*7a635ea9SAndrzej Zaborowski #include <linux/usb.h>
25*7a635ea9SAndrzej Zaborowski #include <linux/usb/cdc.h>
26*7a635ea9SAndrzej Zaborowski #include <linux/usb/usbnet.h>
27*7a635ea9SAndrzej Zaborowski #include <linux/if_ether.h>
28*7a635ea9SAndrzej Zaborowski #include <linux/if_arp.h>
29*7a635ea9SAndrzej Zaborowski #include <linux/inetdevice.h>
30*7a635ea9SAndrzej Zaborowski 
31*7a635ea9SAndrzej Zaborowski /*
32*7a635ea9SAndrzej Zaborowski  * The device has a CDC ACM port for modem control (it claims to be
33*7a635ea9SAndrzej Zaborowski  * CDC ACM anyway) and a CDC Ethernet port for actual network data.
34*7a635ea9SAndrzej Zaborowski  * It will however ignore data on both ports that is not encapsulated
35*7a635ea9SAndrzej Zaborowski  * in a specific way, any data returned is also encapsulated the same
36*7a635ea9SAndrzej Zaborowski  * way.  The headers don't seem to follow any popular standard.
37*7a635ea9SAndrzej Zaborowski  *
38*7a635ea9SAndrzej Zaborowski  * This driver adds and strips these headers from the ethernet frames
39*7a635ea9SAndrzej Zaborowski  * sent/received from the CDC Ethernet port.  The proprietary header
40*7a635ea9SAndrzej Zaborowski  * replaces the standard ethernet header in a packet so only actual
41*7a635ea9SAndrzej Zaborowski  * ethernet frames are allowed.  The headers allow some form of
42*7a635ea9SAndrzej Zaborowski  * multiplexing by using non standard values of the .h_proto field.
43*7a635ea9SAndrzej Zaborowski  * Windows/Mac drivers do send a couple of such frames to the device
44*7a635ea9SAndrzej Zaborowski  * during initialisation, with protocol set to 0x0906 or 0x0b06 and (what
45*7a635ea9SAndrzej Zaborowski  * seems to be) a flag in the .dummy_flags.  This doesn't seem necessary
46*7a635ea9SAndrzej Zaborowski  * for modem operation but can possibly be used for GPS or other funcitons.
47*7a635ea9SAndrzej Zaborowski  */
48*7a635ea9SAndrzej Zaborowski 
49*7a635ea9SAndrzej Zaborowski struct vl600_frame_hdr {
50*7a635ea9SAndrzej Zaborowski 	__le32 len;
51*7a635ea9SAndrzej Zaborowski 	__le32 serial;
52*7a635ea9SAndrzej Zaborowski 	__le32 pkt_cnt;
53*7a635ea9SAndrzej Zaborowski 	__le32 dummy_flags;
54*7a635ea9SAndrzej Zaborowski 	__le32 dummy;
55*7a635ea9SAndrzej Zaborowski 	__le32 magic;
56*7a635ea9SAndrzej Zaborowski } __attribute__((packed));
57*7a635ea9SAndrzej Zaborowski 
58*7a635ea9SAndrzej Zaborowski struct vl600_pkt_hdr {
59*7a635ea9SAndrzej Zaborowski 	__le32 dummy[2];
60*7a635ea9SAndrzej Zaborowski 	__le32 len;
61*7a635ea9SAndrzej Zaborowski 	__be16 h_proto;
62*7a635ea9SAndrzej Zaborowski } __attribute__((packed));
63*7a635ea9SAndrzej Zaborowski 
64*7a635ea9SAndrzej Zaborowski struct vl600_state {
65*7a635ea9SAndrzej Zaborowski 	struct sk_buff *current_rx_buf;
66*7a635ea9SAndrzej Zaborowski };
67*7a635ea9SAndrzej Zaborowski 
68*7a635ea9SAndrzej Zaborowski static int vl600_bind(struct usbnet *dev, struct usb_interface *intf)
69*7a635ea9SAndrzej Zaborowski {
70*7a635ea9SAndrzej Zaborowski 	int ret;
71*7a635ea9SAndrzej Zaborowski 	struct vl600_state *s = kzalloc(sizeof(struct vl600_state), GFP_KERNEL);
72*7a635ea9SAndrzej Zaborowski 
73*7a635ea9SAndrzej Zaborowski 	if (!s)
74*7a635ea9SAndrzej Zaborowski 		return -ENOMEM;
75*7a635ea9SAndrzej Zaborowski 
76*7a635ea9SAndrzej Zaborowski 	ret = usbnet_cdc_bind(dev, intf);
77*7a635ea9SAndrzej Zaborowski 	if (ret) {
78*7a635ea9SAndrzej Zaborowski 		kfree(s);
79*7a635ea9SAndrzej Zaborowski 		return ret;
80*7a635ea9SAndrzej Zaborowski 	}
81*7a635ea9SAndrzej Zaborowski 
82*7a635ea9SAndrzej Zaborowski 	dev->driver_priv = s;
83*7a635ea9SAndrzej Zaborowski 
84*7a635ea9SAndrzej Zaborowski 	/* ARP packets don't go through, but they're also of no use.  The
85*7a635ea9SAndrzej Zaborowski 	 * subnet has only two hosts anyway: us and the gateway / DHCP
86*7a635ea9SAndrzej Zaborowski 	 * server (probably simulated by modem firmware or network operator)
87*7a635ea9SAndrzej Zaborowski 	 * whose address changes everytime we connect to the intarwebz and
88*7a635ea9SAndrzej Zaborowski 	 * who doesn't bother answering ARP requests either.  So hardware
89*7a635ea9SAndrzej Zaborowski 	 * addresses have no meaning, the destination and the source of every
90*7a635ea9SAndrzej Zaborowski 	 * packet depend only on whether it is on the IN or OUT endpoint.  */
91*7a635ea9SAndrzej Zaborowski 	dev->net->flags |= IFF_NOARP;
92*7a635ea9SAndrzej Zaborowski 
93*7a635ea9SAndrzej Zaborowski 	return ret;
94*7a635ea9SAndrzej Zaborowski }
95*7a635ea9SAndrzej Zaborowski 
96*7a635ea9SAndrzej Zaborowski static void vl600_unbind(struct usbnet *dev, struct usb_interface *intf)
97*7a635ea9SAndrzej Zaborowski {
98*7a635ea9SAndrzej Zaborowski 	struct vl600_state *s = dev->driver_priv;
99*7a635ea9SAndrzej Zaborowski 
100*7a635ea9SAndrzej Zaborowski 	if (s->current_rx_buf)
101*7a635ea9SAndrzej Zaborowski 		dev_kfree_skb(s->current_rx_buf);
102*7a635ea9SAndrzej Zaborowski 
103*7a635ea9SAndrzej Zaborowski 	kfree(s);
104*7a635ea9SAndrzej Zaborowski 
105*7a635ea9SAndrzej Zaborowski 	return usbnet_cdc_unbind(dev, intf);
106*7a635ea9SAndrzej Zaborowski }
107*7a635ea9SAndrzej Zaborowski 
108*7a635ea9SAndrzej Zaborowski static int vl600_rx_fixup(struct usbnet *dev, struct sk_buff *skb)
109*7a635ea9SAndrzej Zaborowski {
110*7a635ea9SAndrzej Zaborowski 	struct vl600_frame_hdr *frame;
111*7a635ea9SAndrzej Zaborowski 	struct vl600_pkt_hdr *packet;
112*7a635ea9SAndrzej Zaborowski 	struct ethhdr *ethhdr;
113*7a635ea9SAndrzej Zaborowski 	int packet_len, count;
114*7a635ea9SAndrzej Zaborowski 	struct sk_buff *buf = skb;
115*7a635ea9SAndrzej Zaborowski 	struct sk_buff *clone;
116*7a635ea9SAndrzej Zaborowski 	struct vl600_state *s = dev->driver_priv;
117*7a635ea9SAndrzej Zaborowski 
118*7a635ea9SAndrzej Zaborowski 	/* Frame lengths are generally 4B multiplies but every couple of
119*7a635ea9SAndrzej Zaborowski 	 * hours there's an odd number of bytes sized yet correct frame,
120*7a635ea9SAndrzej Zaborowski 	 * so don't require this.  */
121*7a635ea9SAndrzej Zaborowski 
122*7a635ea9SAndrzej Zaborowski 	/* Allow a packet (or multiple packets batched together) to be
123*7a635ea9SAndrzej Zaborowski 	 * split across many frames.  We don't allow a new batch to
124*7a635ea9SAndrzej Zaborowski 	 * begin in the same frame another one is ending however, and no
125*7a635ea9SAndrzej Zaborowski 	 * leading or trailing pad bytes.  */
126*7a635ea9SAndrzej Zaborowski 	if (s->current_rx_buf) {
127*7a635ea9SAndrzej Zaborowski 		frame = (struct vl600_frame_hdr *) s->current_rx_buf->data;
128*7a635ea9SAndrzej Zaborowski 		if (skb->len + s->current_rx_buf->len >
129*7a635ea9SAndrzej Zaborowski 				le32_to_cpup(&frame->len)) {
130*7a635ea9SAndrzej Zaborowski 			netif_err(dev, ifup, dev->net, "Fragment too long\n");
131*7a635ea9SAndrzej Zaborowski 			dev->net->stats.rx_length_errors++;
132*7a635ea9SAndrzej Zaborowski 			goto error;
133*7a635ea9SAndrzej Zaborowski 		}
134*7a635ea9SAndrzej Zaborowski 
135*7a635ea9SAndrzej Zaborowski 		buf = s->current_rx_buf;
136*7a635ea9SAndrzej Zaborowski 		memcpy(skb_put(buf, skb->len), skb->data, skb->len);
137*7a635ea9SAndrzej Zaborowski 	} else if (skb->len < 4) {
138*7a635ea9SAndrzej Zaborowski 		netif_err(dev, ifup, dev->net, "Frame too short\n");
139*7a635ea9SAndrzej Zaborowski 		dev->net->stats.rx_length_errors++;
140*7a635ea9SAndrzej Zaborowski 		goto error;
141*7a635ea9SAndrzej Zaborowski 	}
142*7a635ea9SAndrzej Zaborowski 
143*7a635ea9SAndrzej Zaborowski 	frame = (struct vl600_frame_hdr *) buf->data;
144*7a635ea9SAndrzej Zaborowski 	/* NOTE: Should check that frame->magic == 0x53544448?
145*7a635ea9SAndrzej Zaborowski 	 * Otherwise if we receive garbage at the beginning of the frame
146*7a635ea9SAndrzej Zaborowski 	 * we may end up allocating a huge buffer and saving all the
147*7a635ea9SAndrzej Zaborowski 	 * future incoming data into it.  */
148*7a635ea9SAndrzej Zaborowski 
149*7a635ea9SAndrzej Zaborowski 	if (buf->len < sizeof(*frame) ||
150*7a635ea9SAndrzej Zaborowski 			buf->len != le32_to_cpup(&frame->len)) {
151*7a635ea9SAndrzej Zaborowski 		/* Save this fragment for later assembly */
152*7a635ea9SAndrzej Zaborowski 		if (s->current_rx_buf)
153*7a635ea9SAndrzej Zaborowski 			return 0;
154*7a635ea9SAndrzej Zaborowski 
155*7a635ea9SAndrzej Zaborowski 		s->current_rx_buf = skb_copy_expand(skb, 0,
156*7a635ea9SAndrzej Zaborowski 				le32_to_cpup(&frame->len), GFP_ATOMIC);
157*7a635ea9SAndrzej Zaborowski 		if (!s->current_rx_buf) {
158*7a635ea9SAndrzej Zaborowski 			netif_err(dev, ifup, dev->net, "Reserving %i bytes "
159*7a635ea9SAndrzej Zaborowski 					"for packet assembly failed.\n",
160*7a635ea9SAndrzej Zaborowski 					le32_to_cpup(&frame->len));
161*7a635ea9SAndrzej Zaborowski 			dev->net->stats.rx_errors++;
162*7a635ea9SAndrzej Zaborowski 		}
163*7a635ea9SAndrzej Zaborowski 
164*7a635ea9SAndrzej Zaborowski 		return 0;
165*7a635ea9SAndrzej Zaborowski 	}
166*7a635ea9SAndrzej Zaborowski 
167*7a635ea9SAndrzej Zaborowski 	count = le32_to_cpup(&frame->pkt_cnt);
168*7a635ea9SAndrzej Zaborowski 
169*7a635ea9SAndrzej Zaborowski 	skb_pull(buf, sizeof(*frame));
170*7a635ea9SAndrzej Zaborowski 
171*7a635ea9SAndrzej Zaborowski 	while (count--) {
172*7a635ea9SAndrzej Zaborowski 		if (buf->len < sizeof(*packet)) {
173*7a635ea9SAndrzej Zaborowski 			netif_err(dev, ifup, dev->net, "Packet too short\n");
174*7a635ea9SAndrzej Zaborowski 			goto error;
175*7a635ea9SAndrzej Zaborowski 		}
176*7a635ea9SAndrzej Zaborowski 
177*7a635ea9SAndrzej Zaborowski 		packet = (struct vl600_pkt_hdr *) buf->data;
178*7a635ea9SAndrzej Zaborowski 		packet_len = sizeof(*packet) + le32_to_cpup(&packet->len);
179*7a635ea9SAndrzej Zaborowski 		if (packet_len > buf->len) {
180*7a635ea9SAndrzej Zaborowski 			netif_err(dev, ifup, dev->net,
181*7a635ea9SAndrzej Zaborowski 					"Bad packet length stored in header\n");
182*7a635ea9SAndrzej Zaborowski 			goto error;
183*7a635ea9SAndrzej Zaborowski 		}
184*7a635ea9SAndrzej Zaborowski 
185*7a635ea9SAndrzej Zaborowski 		/* Packet header is same size as the ethernet header
186*7a635ea9SAndrzej Zaborowski 		 * (sizeof(*packet) == sizeof(*ethhdr)), additionally
187*7a635ea9SAndrzej Zaborowski 		 * the h_proto field is in the same place so we just leave it
188*7a635ea9SAndrzej Zaborowski 		 * alone and fill in the remaining fields.
189*7a635ea9SAndrzej Zaborowski 		 */
190*7a635ea9SAndrzej Zaborowski 		ethhdr = (struct ethhdr *) skb->data;
191*7a635ea9SAndrzej Zaborowski 		if (be16_to_cpup(&ethhdr->h_proto) == ETH_P_ARP &&
192*7a635ea9SAndrzej Zaborowski 				buf->len > 0x26) {
193*7a635ea9SAndrzej Zaborowski 			/* Copy the addresses from packet contents */
194*7a635ea9SAndrzej Zaborowski 			memcpy(ethhdr->h_source,
195*7a635ea9SAndrzej Zaborowski 					&buf->data[sizeof(*ethhdr) + 0x8],
196*7a635ea9SAndrzej Zaborowski 					ETH_ALEN);
197*7a635ea9SAndrzej Zaborowski 			memcpy(ethhdr->h_dest,
198*7a635ea9SAndrzej Zaborowski 					&buf->data[sizeof(*ethhdr) + 0x12],
199*7a635ea9SAndrzej Zaborowski 					ETH_ALEN);
200*7a635ea9SAndrzej Zaborowski 		} else {
201*7a635ea9SAndrzej Zaborowski 			memset(ethhdr->h_source, 0, ETH_ALEN);
202*7a635ea9SAndrzej Zaborowski 			memcpy(ethhdr->h_dest, dev->net->dev_addr, ETH_ALEN);
203*7a635ea9SAndrzej Zaborowski 		}
204*7a635ea9SAndrzej Zaborowski 
205*7a635ea9SAndrzej Zaborowski 		if (count) {
206*7a635ea9SAndrzej Zaborowski 			/* Not the last packet in this batch */
207*7a635ea9SAndrzej Zaborowski 			clone = skb_clone(buf, GFP_ATOMIC);
208*7a635ea9SAndrzej Zaborowski 			if (!clone)
209*7a635ea9SAndrzej Zaborowski 				goto error;
210*7a635ea9SAndrzej Zaborowski 
211*7a635ea9SAndrzej Zaborowski 			skb_trim(clone, packet_len);
212*7a635ea9SAndrzej Zaborowski 			usbnet_skb_return(dev, clone);
213*7a635ea9SAndrzej Zaborowski 
214*7a635ea9SAndrzej Zaborowski 			skb_pull(buf, (packet_len + 3) & ~3);
215*7a635ea9SAndrzej Zaborowski 		} else {
216*7a635ea9SAndrzej Zaborowski 			skb_trim(buf, packet_len);
217*7a635ea9SAndrzej Zaborowski 
218*7a635ea9SAndrzej Zaborowski 			if (s->current_rx_buf) {
219*7a635ea9SAndrzej Zaborowski 				usbnet_skb_return(dev, buf);
220*7a635ea9SAndrzej Zaborowski 				s->current_rx_buf = NULL;
221*7a635ea9SAndrzej Zaborowski 				return 0;
222*7a635ea9SAndrzej Zaborowski 			}
223*7a635ea9SAndrzej Zaborowski 
224*7a635ea9SAndrzej Zaborowski 			return 1;
225*7a635ea9SAndrzej Zaborowski 		}
226*7a635ea9SAndrzej Zaborowski 	}
227*7a635ea9SAndrzej Zaborowski 
228*7a635ea9SAndrzej Zaborowski error:
229*7a635ea9SAndrzej Zaborowski 	if (s->current_rx_buf) {
230*7a635ea9SAndrzej Zaborowski 		dev_kfree_skb_any(s->current_rx_buf);
231*7a635ea9SAndrzej Zaborowski 		s->current_rx_buf = NULL;
232*7a635ea9SAndrzej Zaborowski 	}
233*7a635ea9SAndrzej Zaborowski 	dev->net->stats.rx_errors++;
234*7a635ea9SAndrzej Zaborowski 	return 0;
235*7a635ea9SAndrzej Zaborowski }
236*7a635ea9SAndrzej Zaborowski 
237*7a635ea9SAndrzej Zaborowski static struct sk_buff *vl600_tx_fixup(struct usbnet *dev,
238*7a635ea9SAndrzej Zaborowski 		struct sk_buff *skb, gfp_t flags)
239*7a635ea9SAndrzej Zaborowski {
240*7a635ea9SAndrzej Zaborowski 	struct sk_buff *ret;
241*7a635ea9SAndrzej Zaborowski 	struct vl600_frame_hdr *frame;
242*7a635ea9SAndrzej Zaborowski 	struct vl600_pkt_hdr *packet;
243*7a635ea9SAndrzej Zaborowski 	static uint32_t serial = 1;
244*7a635ea9SAndrzej Zaborowski 	int orig_len = skb->len - sizeof(struct ethhdr);
245*7a635ea9SAndrzej Zaborowski 	int full_len = (skb->len + sizeof(struct vl600_frame_hdr) + 3) & ~3;
246*7a635ea9SAndrzej Zaborowski 
247*7a635ea9SAndrzej Zaborowski 	frame = (struct vl600_frame_hdr *) skb->data;
248*7a635ea9SAndrzej Zaborowski 	if (skb->len > sizeof(*frame) && skb->len == le32_to_cpup(&frame->len))
249*7a635ea9SAndrzej Zaborowski 		return skb; /* Already encapsulated? */
250*7a635ea9SAndrzej Zaborowski 
251*7a635ea9SAndrzej Zaborowski 	if (skb->len < sizeof(struct ethhdr))
252*7a635ea9SAndrzej Zaborowski 		/* Drop, device can only deal with ethernet packets */
253*7a635ea9SAndrzej Zaborowski 		return NULL;
254*7a635ea9SAndrzej Zaborowski 
255*7a635ea9SAndrzej Zaborowski 	if (!skb_cloned(skb)) {
256*7a635ea9SAndrzej Zaborowski 		int headroom = skb_headroom(skb);
257*7a635ea9SAndrzej Zaborowski 		int tailroom = skb_tailroom(skb);
258*7a635ea9SAndrzej Zaborowski 
259*7a635ea9SAndrzej Zaborowski 		if (tailroom >= full_len - skb->len - sizeof(*frame) &&
260*7a635ea9SAndrzej Zaborowski 				headroom >= sizeof(*frame))
261*7a635ea9SAndrzej Zaborowski 			/* There's enough head and tail room */
262*7a635ea9SAndrzej Zaborowski 			goto encapsulate;
263*7a635ea9SAndrzej Zaborowski 
264*7a635ea9SAndrzej Zaborowski 		if (headroom + tailroom + skb->len >= full_len) {
265*7a635ea9SAndrzej Zaborowski 			/* There's enough total room, just readjust */
266*7a635ea9SAndrzej Zaborowski 			skb->data = memmove(skb->head + sizeof(*frame),
267*7a635ea9SAndrzej Zaborowski 					skb->data, skb->len);
268*7a635ea9SAndrzej Zaborowski 			skb_set_tail_pointer(skb, skb->len);
269*7a635ea9SAndrzej Zaborowski 			goto encapsulate;
270*7a635ea9SAndrzej Zaborowski 		}
271*7a635ea9SAndrzej Zaborowski 	}
272*7a635ea9SAndrzej Zaborowski 
273*7a635ea9SAndrzej Zaborowski 	/* Alloc a new skb with the required size */
274*7a635ea9SAndrzej Zaborowski 	ret = skb_copy_expand(skb, sizeof(struct vl600_frame_hdr), full_len -
275*7a635ea9SAndrzej Zaborowski 			skb->len - sizeof(struct vl600_frame_hdr), flags);
276*7a635ea9SAndrzej Zaborowski 	dev_kfree_skb_any(skb);
277*7a635ea9SAndrzej Zaborowski 	if (!ret)
278*7a635ea9SAndrzej Zaborowski 		return ret;
279*7a635ea9SAndrzej Zaborowski 	skb = ret;
280*7a635ea9SAndrzej Zaborowski 
281*7a635ea9SAndrzej Zaborowski encapsulate:
282*7a635ea9SAndrzej Zaborowski 	/* Packet header is same size as ethernet packet header
283*7a635ea9SAndrzej Zaborowski 	 * (sizeof(*packet) == sizeof(struct ethhdr)), additionally the
284*7a635ea9SAndrzej Zaborowski 	 * h_proto field is in the same place so we just leave it alone and
285*7a635ea9SAndrzej Zaborowski 	 * overwrite the remaining fields.
286*7a635ea9SAndrzej Zaborowski 	 */
287*7a635ea9SAndrzej Zaborowski 	packet = (struct vl600_pkt_hdr *) skb->data;
288*7a635ea9SAndrzej Zaborowski 	memset(&packet->dummy, 0, sizeof(packet->dummy));
289*7a635ea9SAndrzej Zaborowski 	packet->len = cpu_to_le32(orig_len);
290*7a635ea9SAndrzej Zaborowski 
291*7a635ea9SAndrzej Zaborowski 	frame = (struct vl600_frame_hdr *) skb_push(skb, sizeof(*frame));
292*7a635ea9SAndrzej Zaborowski 	memset(frame, 0, sizeof(*frame));
293*7a635ea9SAndrzej Zaborowski 	frame->len = cpu_to_le32(full_len);
294*7a635ea9SAndrzej Zaborowski 	frame->serial = cpu_to_le32(serial++);
295*7a635ea9SAndrzej Zaborowski 	frame->pkt_cnt = cpu_to_le32(1);
296*7a635ea9SAndrzej Zaborowski 
297*7a635ea9SAndrzej Zaborowski 	if (skb->len < full_len) /* Pad */
298*7a635ea9SAndrzej Zaborowski 		skb_put(skb, full_len - skb->len);
299*7a635ea9SAndrzej Zaborowski 
300*7a635ea9SAndrzej Zaborowski 	return skb;
301*7a635ea9SAndrzej Zaborowski }
302*7a635ea9SAndrzej Zaborowski 
303*7a635ea9SAndrzej Zaborowski static const struct driver_info	vl600_info = {
304*7a635ea9SAndrzej Zaborowski 	.description	= "LG VL600 modem",
305*7a635ea9SAndrzej Zaborowski 	.flags		= FLAG_ETHER | FLAG_RX_ASSEMBLE,
306*7a635ea9SAndrzej Zaborowski 	.bind		= vl600_bind,
307*7a635ea9SAndrzej Zaborowski 	.unbind		= vl600_unbind,
308*7a635ea9SAndrzej Zaborowski 	.status		= usbnet_cdc_status,
309*7a635ea9SAndrzej Zaborowski 	.rx_fixup	= vl600_rx_fixup,
310*7a635ea9SAndrzej Zaborowski 	.tx_fixup	= vl600_tx_fixup,
311*7a635ea9SAndrzej Zaborowski };
312*7a635ea9SAndrzej Zaborowski 
313*7a635ea9SAndrzej Zaborowski static const struct usb_device_id products[] = {
314*7a635ea9SAndrzej Zaborowski 	{
315*7a635ea9SAndrzej Zaborowski 		USB_DEVICE_AND_INTERFACE_INFO(0x1004, 0x61aa, USB_CLASS_COMM,
316*7a635ea9SAndrzej Zaborowski 				USB_CDC_SUBCLASS_ETHERNET, USB_CDC_PROTO_NONE),
317*7a635ea9SAndrzej Zaborowski 		.driver_info	= (unsigned long) &vl600_info,
318*7a635ea9SAndrzej Zaborowski 	},
319*7a635ea9SAndrzej Zaborowski 	{},	/* End */
320*7a635ea9SAndrzej Zaborowski };
321*7a635ea9SAndrzej Zaborowski MODULE_DEVICE_TABLE(usb, products);
322*7a635ea9SAndrzej Zaborowski 
323*7a635ea9SAndrzej Zaborowski static struct usb_driver lg_vl600_driver = {
324*7a635ea9SAndrzej Zaborowski 	.name		= "lg-vl600",
325*7a635ea9SAndrzej Zaborowski 	.id_table	= products,
326*7a635ea9SAndrzej Zaborowski 	.probe		= usbnet_probe,
327*7a635ea9SAndrzej Zaborowski 	.disconnect	= usbnet_disconnect,
328*7a635ea9SAndrzej Zaborowski 	.suspend	= usbnet_suspend,
329*7a635ea9SAndrzej Zaborowski 	.resume		= usbnet_resume,
330*7a635ea9SAndrzej Zaborowski };
331*7a635ea9SAndrzej Zaborowski 
332*7a635ea9SAndrzej Zaborowski static int __init vl600_init(void)
333*7a635ea9SAndrzej Zaborowski {
334*7a635ea9SAndrzej Zaborowski 	return usb_register(&lg_vl600_driver);
335*7a635ea9SAndrzej Zaborowski }
336*7a635ea9SAndrzej Zaborowski module_init(vl600_init);
337*7a635ea9SAndrzej Zaborowski 
338*7a635ea9SAndrzej Zaborowski static void __exit vl600_exit(void)
339*7a635ea9SAndrzej Zaborowski {
340*7a635ea9SAndrzej Zaborowski 	usb_deregister(&lg_vl600_driver);
341*7a635ea9SAndrzej Zaborowski }
342*7a635ea9SAndrzej Zaborowski module_exit(vl600_exit);
343*7a635ea9SAndrzej Zaborowski 
344*7a635ea9SAndrzej Zaborowski MODULE_AUTHOR("Anrzej Zaborowski");
345*7a635ea9SAndrzej Zaborowski MODULE_DESCRIPTION("LG-VL600 modem's ethernet link");
346*7a635ea9SAndrzej Zaborowski MODULE_LICENSE("GPL");
347