xref: /linux/drivers/net/usb/kalmia.c (revision b080db585384b9f037e015c0c28d1ad33be41dfc)
1d4026123SMarius B. Kotsbak /*
2d4026123SMarius B. Kotsbak  * USB network interface driver for Samsung Kalmia based LTE USB modem like the
3d4026123SMarius B. Kotsbak  * Samsung GT-B3730 and GT-B3710.
4d4026123SMarius B. Kotsbak  *
5d4026123SMarius B. Kotsbak  * Copyright (C) 2011 Marius Bjoernstad Kotsbak <marius@kotsbak.com>
6d4026123SMarius B. Kotsbak  *
7d4026123SMarius B. Kotsbak  * Sponsored by Quicklink Video Distribution Services Ltd.
8d4026123SMarius B. Kotsbak  *
9d4026123SMarius B. Kotsbak  * Based on the cdc_eem module.
10d4026123SMarius B. Kotsbak  *
11d4026123SMarius B. Kotsbak  * This program is free software; you can redistribute it and/or modify
12d4026123SMarius B. Kotsbak  * it under the terms of the GNU General Public License as published by
13d4026123SMarius B. Kotsbak  * the Free Software Foundation; either version 2 of the License, or
14d4026123SMarius B. Kotsbak  * (at your option) any later version.
15d4026123SMarius B. Kotsbak  */
16d4026123SMarius B. Kotsbak 
17d4026123SMarius B. Kotsbak #include <linux/module.h>
18d4026123SMarius B. Kotsbak #include <linux/netdevice.h>
19d4026123SMarius B. Kotsbak #include <linux/etherdevice.h>
20d4026123SMarius B. Kotsbak #include <linux/ctype.h>
21d4026123SMarius B. Kotsbak #include <linux/ethtool.h>
22d4026123SMarius B. Kotsbak #include <linux/workqueue.h>
23d4026123SMarius B. Kotsbak #include <linux/mii.h>
24d4026123SMarius B. Kotsbak #include <linux/usb.h>
25d4026123SMarius B. Kotsbak #include <linux/crc32.h>
26d4026123SMarius B. Kotsbak #include <linux/usb/cdc.h>
27d4026123SMarius B. Kotsbak #include <linux/usb/usbnet.h>
28d4026123SMarius B. Kotsbak #include <linux/gfp.h>
29d4026123SMarius B. Kotsbak 
30d4026123SMarius B. Kotsbak /*
31d4026123SMarius B. Kotsbak  * The Samsung Kalmia based LTE USB modems have a CDC ACM port for modem control
32d4026123SMarius B. Kotsbak  * handled by the "option" module and an ethernet data port handled by this
33d4026123SMarius B. Kotsbak  * module.
34d4026123SMarius B. Kotsbak  *
35d4026123SMarius B. Kotsbak  * The stick must first be switched into modem mode by usb_modeswitch
36d4026123SMarius B. Kotsbak  * or similar tool. Then the modem gets sent two initialization packets by
37d4026123SMarius B. Kotsbak  * this module, which gives the MAC address of the device. User space can then
38d4026123SMarius B. Kotsbak  * connect the modem using AT commands through the ACM port and then use
39d4026123SMarius B. Kotsbak  * DHCP on the network interface exposed by this module. Network packets are
40d4026123SMarius B. Kotsbak  * sent to and from the modem in a proprietary format discovered after watching
41d4026123SMarius B. Kotsbak  * the behavior of the windows driver for the modem.
42d4026123SMarius B. Kotsbak  *
43d4026123SMarius B. Kotsbak  * More information about the use of the modem is available in usb_modeswitch
44d4026123SMarius B. Kotsbak  * forum and the project page:
45d4026123SMarius B. Kotsbak  *
46d4026123SMarius B. Kotsbak  * http://www.draisberghof.de/usb_modeswitch/bb/viewtopic.php?t=465
47d4026123SMarius B. Kotsbak  * https://github.com/mkotsbak/Samsung-GT-B3730-linux-driver
48d4026123SMarius B. Kotsbak  */
49d4026123SMarius B. Kotsbak 
50d4026123SMarius B. Kotsbak /* #define	DEBUG */
51d4026123SMarius B. Kotsbak /* #define	VERBOSE */
52d4026123SMarius B. Kotsbak 
53d4026123SMarius B. Kotsbak #define KALMIA_HEADER_LENGTH 6
54d4026123SMarius B. Kotsbak #define KALMIA_ALIGN_SIZE 4
55d4026123SMarius B. Kotsbak #define KALMIA_USB_TIMEOUT 10000
56d4026123SMarius B. Kotsbak 
57d4026123SMarius B. Kotsbak /*-------------------------------------------------------------------------*/
58d4026123SMarius B. Kotsbak 
59d4026123SMarius B. Kotsbak static int
60d4026123SMarius B. Kotsbak kalmia_send_init_packet(struct usbnet *dev, u8 *init_msg, u8 init_msg_len,
61d4026123SMarius B. Kotsbak 	u8 *buffer, u8 expected_len)
62d4026123SMarius B. Kotsbak {
63d4026123SMarius B. Kotsbak 	int act_len;
64d4026123SMarius B. Kotsbak 	int status;
65d4026123SMarius B. Kotsbak 
66d4026123SMarius B. Kotsbak 	netdev_dbg(dev->net, "Sending init packet");
67d4026123SMarius B. Kotsbak 
68d4026123SMarius B. Kotsbak 	status = usb_bulk_msg(dev->udev, usb_sndbulkpipe(dev->udev, 0x02),
69d4026123SMarius B. Kotsbak 		init_msg, init_msg_len, &act_len, KALMIA_USB_TIMEOUT);
70d4026123SMarius B. Kotsbak 	if (status != 0) {
71d4026123SMarius B. Kotsbak 		netdev_err(dev->net,
72d4026123SMarius B. Kotsbak 			"Error sending init packet. Status %i, length %i\n",
73d4026123SMarius B. Kotsbak 			status, act_len);
74d4026123SMarius B. Kotsbak 		return status;
75d4026123SMarius B. Kotsbak 	}
76d4026123SMarius B. Kotsbak 	else if (act_len != init_msg_len) {
77d4026123SMarius B. Kotsbak 		netdev_err(dev->net,
78d4026123SMarius B. Kotsbak 			"Did not send all of init packet. Bytes sent: %i",
79d4026123SMarius B. Kotsbak 			act_len);
80d4026123SMarius B. Kotsbak 	}
81d4026123SMarius B. Kotsbak 	else {
82d4026123SMarius B. Kotsbak 		netdev_dbg(dev->net, "Successfully sent init packet.");
83d4026123SMarius B. Kotsbak 	}
84d4026123SMarius B. Kotsbak 
85d4026123SMarius B. Kotsbak 	status = usb_bulk_msg(dev->udev, usb_rcvbulkpipe(dev->udev, 0x81),
86d4026123SMarius B. Kotsbak 		buffer, expected_len, &act_len, KALMIA_USB_TIMEOUT);
87d4026123SMarius B. Kotsbak 
88d4026123SMarius B. Kotsbak 	if (status != 0)
89d4026123SMarius B. Kotsbak 		netdev_err(dev->net,
90d4026123SMarius B. Kotsbak 			"Error receiving init result. Status %i, length %i\n",
91d4026123SMarius B. Kotsbak 			status, act_len);
92d4026123SMarius B. Kotsbak 	else if (act_len != expected_len)
93d4026123SMarius B. Kotsbak 		netdev_err(dev->net, "Unexpected init result length: %i\n",
94d4026123SMarius B. Kotsbak 			act_len);
95d4026123SMarius B. Kotsbak 
96d4026123SMarius B. Kotsbak 	return status;
97d4026123SMarius B. Kotsbak }
98d4026123SMarius B. Kotsbak 
99d4026123SMarius B. Kotsbak static int
100d4026123SMarius B. Kotsbak kalmia_init_and_get_ethernet_addr(struct usbnet *dev, u8 *ethernet_addr)
101d4026123SMarius B. Kotsbak {
102bd0d7aa6SJesper Juhl 	static const char init_msg_1[] =
103d4026123SMarius B. Kotsbak 		{ 0x57, 0x50, 0x04, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00,
104d4026123SMarius B. Kotsbak 		0x00, 0x00 };
105bd0d7aa6SJesper Juhl 	static const char init_msg_2[] =
106d4026123SMarius B. Kotsbak 		{ 0x57, 0x50, 0x04, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0xf4,
107d4026123SMarius B. Kotsbak 		0x00, 0x00 };
108bd0d7aa6SJesper Juhl 	static const int buflen = 28;
1097cdfa4a3SMarius B. Kotsbak 	char *usb_buf;
110d4026123SMarius B. Kotsbak 	int status;
111d4026123SMarius B. Kotsbak 
1127cdfa4a3SMarius B. Kotsbak 	usb_buf = kmalloc(buflen, GFP_DMA | GFP_KERNEL);
1137cdfa4a3SMarius B. Kotsbak 	if (!usb_buf)
1147cdfa4a3SMarius B. Kotsbak 		return -ENOMEM;
1157cdfa4a3SMarius B. Kotsbak 
1167cdfa4a3SMarius B. Kotsbak 	memcpy(usb_buf, init_msg_1, 12);
1177cdfa4a3SMarius B. Kotsbak 	status = kalmia_send_init_packet(dev, usb_buf, sizeof(init_msg_1)
1187cdfa4a3SMarius B. Kotsbak 		/ sizeof(init_msg_1[0]), usb_buf, 24);
119d4026123SMarius B. Kotsbak 	if (status != 0)
120d4026123SMarius B. Kotsbak 		return status;
121d4026123SMarius B. Kotsbak 
1227cdfa4a3SMarius B. Kotsbak 	memcpy(usb_buf, init_msg_2, 12);
1237cdfa4a3SMarius B. Kotsbak 	status = kalmia_send_init_packet(dev, usb_buf, sizeof(init_msg_2)
1247cdfa4a3SMarius B. Kotsbak 		/ sizeof(init_msg_2[0]), usb_buf, 28);
125d4026123SMarius B. Kotsbak 	if (status != 0)
126d4026123SMarius B. Kotsbak 		return status;
127d4026123SMarius B. Kotsbak 
1287cdfa4a3SMarius B. Kotsbak 	memcpy(ethernet_addr, usb_buf + 10, ETH_ALEN);
129d4026123SMarius B. Kotsbak 
1307cdfa4a3SMarius B. Kotsbak 	kfree(usb_buf);
131d4026123SMarius B. Kotsbak 	return status;
132d4026123SMarius B. Kotsbak }
133d4026123SMarius B. Kotsbak 
134d4026123SMarius B. Kotsbak static int
135d4026123SMarius B. Kotsbak kalmia_bind(struct usbnet *dev, struct usb_interface *intf)
136d4026123SMarius B. Kotsbak {
1375c18e80bSDan Carpenter 	int status;
138d4026123SMarius B. Kotsbak 	u8 ethernet_addr[ETH_ALEN];
139d4026123SMarius B. Kotsbak 
140d4026123SMarius B. Kotsbak 	/* Don't bind to AT command interface */
141d4026123SMarius B. Kotsbak 	if (intf->cur_altsetting->desc.bInterfaceClass != USB_CLASS_VENDOR_SPEC)
142d4026123SMarius B. Kotsbak 		return -EINVAL;
143d4026123SMarius B. Kotsbak 
144d4026123SMarius B. Kotsbak 	dev->in = usb_rcvbulkpipe(dev->udev, 0x81 & USB_ENDPOINT_NUMBER_MASK);
145d4026123SMarius B. Kotsbak 	dev->out = usb_sndbulkpipe(dev->udev, 0x02 & USB_ENDPOINT_NUMBER_MASK);
146d4026123SMarius B. Kotsbak 	dev->status = NULL;
147d4026123SMarius B. Kotsbak 
148d4026123SMarius B. Kotsbak 	dev->net->hard_header_len += KALMIA_HEADER_LENGTH;
149d4026123SMarius B. Kotsbak 	dev->hard_mtu = 1400;
150d4026123SMarius B. Kotsbak 	dev->rx_urb_size = dev->hard_mtu * 10; // Found as optimal after testing
151d4026123SMarius B. Kotsbak 
152d4026123SMarius B. Kotsbak 	status = kalmia_init_and_get_ethernet_addr(dev, ethernet_addr);
153d4026123SMarius B. Kotsbak 
154e30520c2SArnd Bergmann 	if (status) {
155d4026123SMarius B. Kotsbak 		usb_set_intfdata(intf, NULL);
156d4026123SMarius B. Kotsbak 		usb_driver_release_interface(driver_of(intf), intf);
157d4026123SMarius B. Kotsbak 		return status;
158d4026123SMarius B. Kotsbak 	}
159d4026123SMarius B. Kotsbak 
160d4026123SMarius B. Kotsbak 	memcpy(dev->net->dev_addr, ethernet_addr, ETH_ALEN);
161d4026123SMarius B. Kotsbak 
162d4026123SMarius B. Kotsbak 	return status;
163d4026123SMarius B. Kotsbak }
164d4026123SMarius B. Kotsbak 
165d4026123SMarius B. Kotsbak static struct sk_buff *
166d4026123SMarius B. Kotsbak kalmia_tx_fixup(struct usbnet *dev, struct sk_buff *skb, gfp_t flags)
167d4026123SMarius B. Kotsbak {
168d4026123SMarius B. Kotsbak 	struct sk_buff *skb2 = NULL;
169d4026123SMarius B. Kotsbak 	u16 content_len;
170d4026123SMarius B. Kotsbak 	unsigned char *header_start;
171d4026123SMarius B. Kotsbak 	unsigned char ether_type_1, ether_type_2;
172d4026123SMarius B. Kotsbak 	u8 remainder, padlen = 0;
173d4026123SMarius B. Kotsbak 
174d4026123SMarius B. Kotsbak 	if (!skb_cloned(skb)) {
175d4026123SMarius B. Kotsbak 		int headroom = skb_headroom(skb);
176d4026123SMarius B. Kotsbak 		int tailroom = skb_tailroom(skb);
177d4026123SMarius B. Kotsbak 
178d4026123SMarius B. Kotsbak 		if ((tailroom >= KALMIA_ALIGN_SIZE) && (headroom
179d4026123SMarius B. Kotsbak 			>= KALMIA_HEADER_LENGTH))
180d4026123SMarius B. Kotsbak 			goto done;
181d4026123SMarius B. Kotsbak 
182d4026123SMarius B. Kotsbak 		if ((headroom + tailroom) > (KALMIA_HEADER_LENGTH
183d4026123SMarius B. Kotsbak 			+ KALMIA_ALIGN_SIZE)) {
184d4026123SMarius B. Kotsbak 			skb->data = memmove(skb->head + KALMIA_HEADER_LENGTH,
185d4026123SMarius B. Kotsbak 				skb->data, skb->len);
186d4026123SMarius B. Kotsbak 			skb_set_tail_pointer(skb, skb->len);
187d4026123SMarius B. Kotsbak 			goto done;
188d4026123SMarius B. Kotsbak 		}
189d4026123SMarius B. Kotsbak 	}
190d4026123SMarius B. Kotsbak 
191d4026123SMarius B. Kotsbak 	skb2 = skb_copy_expand(skb, KALMIA_HEADER_LENGTH,
192d4026123SMarius B. Kotsbak 		KALMIA_ALIGN_SIZE, flags);
193d4026123SMarius B. Kotsbak 	if (!skb2)
194d4026123SMarius B. Kotsbak 		return NULL;
195d4026123SMarius B. Kotsbak 
196d4026123SMarius B. Kotsbak 	dev_kfree_skb_any(skb);
197d4026123SMarius B. Kotsbak 	skb = skb2;
198d4026123SMarius B. Kotsbak 
1997cdfa4a3SMarius B. Kotsbak done:
2007cdfa4a3SMarius B. Kotsbak 	header_start = skb_push(skb, KALMIA_HEADER_LENGTH);
201d4026123SMarius B. Kotsbak 	ether_type_1 = header_start[KALMIA_HEADER_LENGTH + 12];
202d4026123SMarius B. Kotsbak 	ether_type_2 = header_start[KALMIA_HEADER_LENGTH + 13];
203d4026123SMarius B. Kotsbak 
204d4026123SMarius B. Kotsbak 	netdev_dbg(dev->net, "Sending etherType: %02x%02x", ether_type_1,
205d4026123SMarius B. Kotsbak 		ether_type_2);
206d4026123SMarius B. Kotsbak 
207d4026123SMarius B. Kotsbak 	/* According to empiric data for data packages */
208d4026123SMarius B. Kotsbak 	header_start[0] = 0x57;
209d4026123SMarius B. Kotsbak 	header_start[1] = 0x44;
210d4026123SMarius B. Kotsbak 	content_len = skb->len - KALMIA_HEADER_LENGTH;
211d4026123SMarius B. Kotsbak 
2127cdfa4a3SMarius B. Kotsbak 	put_unaligned_le16(content_len, &header_start[2]);
213d4026123SMarius B. Kotsbak 	header_start[4] = ether_type_1;
214d4026123SMarius B. Kotsbak 	header_start[5] = ether_type_2;
215d4026123SMarius B. Kotsbak 
216d4026123SMarius B. Kotsbak 	/* Align to 4 bytes by padding with zeros */
217d4026123SMarius B. Kotsbak 	remainder = skb->len % KALMIA_ALIGN_SIZE;
218d4026123SMarius B. Kotsbak 	if (remainder > 0) {
219d4026123SMarius B. Kotsbak 		padlen = KALMIA_ALIGN_SIZE - remainder;
220*b080db58SJohannes Berg 		skb_put_zero(skb, padlen);
221d4026123SMarius B. Kotsbak 	}
222d4026123SMarius B. Kotsbak 
223cbb963deSAndy Shevchenko 	netdev_dbg(dev->net,
224cbb963deSAndy Shevchenko 		"Sending package with length %i and padding %i. Header: %6phC.",
225cbb963deSAndy Shevchenko 		content_len, padlen, header_start);
226d4026123SMarius B. Kotsbak 
227d4026123SMarius B. Kotsbak 	return skb;
228d4026123SMarius B. Kotsbak }
229d4026123SMarius B. Kotsbak 
230d4026123SMarius B. Kotsbak static int
231d4026123SMarius B. Kotsbak kalmia_rx_fixup(struct usbnet *dev, struct sk_buff *skb)
232d4026123SMarius B. Kotsbak {
233d4026123SMarius B. Kotsbak 	/*
234d4026123SMarius B. Kotsbak 	 * Our task here is to strip off framing, leaving skb with one
235d4026123SMarius B. Kotsbak 	 * data frame for the usbnet framework code to process.
236d4026123SMarius B. Kotsbak 	 */
237bd0d7aa6SJesper Juhl 	static const u8 HEADER_END_OF_USB_PACKET[] =
238d4026123SMarius B. Kotsbak 		{ 0x57, 0x5a, 0x00, 0x00, 0x08, 0x00 };
239bd0d7aa6SJesper Juhl 	static const u8 EXPECTED_UNKNOWN_HEADER_1[] =
240d4026123SMarius B. Kotsbak 		{ 0x57, 0x43, 0x1e, 0x00, 0x15, 0x02 };
241bd0d7aa6SJesper Juhl 	static const u8 EXPECTED_UNKNOWN_HEADER_2[] =
242d4026123SMarius B. Kotsbak 		{ 0x57, 0x50, 0x0e, 0x00, 0x00, 0x00 };
2437cdfa4a3SMarius B. Kotsbak 	int i = 0;
244d4026123SMarius B. Kotsbak 
245d4026123SMarius B. Kotsbak 	/* incomplete header? */
246d4026123SMarius B. Kotsbak 	if (skb->len < KALMIA_HEADER_LENGTH)
247d4026123SMarius B. Kotsbak 		return 0;
248d4026123SMarius B. Kotsbak 
249d4026123SMarius B. Kotsbak 	do {
250d4026123SMarius B. Kotsbak 		struct sk_buff *skb2 = NULL;
251d4026123SMarius B. Kotsbak 		u8 *header_start;
252d4026123SMarius B. Kotsbak 		u16 usb_packet_length, ether_packet_length;
253d4026123SMarius B. Kotsbak 		int is_last;
254d4026123SMarius B. Kotsbak 
255d4026123SMarius B. Kotsbak 		header_start = skb->data;
256d4026123SMarius B. Kotsbak 
257d4026123SMarius B. Kotsbak 		if (unlikely(header_start[0] != 0x57 || header_start[1] != 0x44)) {
258d4026123SMarius B. Kotsbak 			if (!memcmp(header_start, EXPECTED_UNKNOWN_HEADER_1,
259d4026123SMarius B. Kotsbak 				sizeof(EXPECTED_UNKNOWN_HEADER_1)) || !memcmp(
260d4026123SMarius B. Kotsbak 				header_start, EXPECTED_UNKNOWN_HEADER_2,
261d4026123SMarius B. Kotsbak 				sizeof(EXPECTED_UNKNOWN_HEADER_2))) {
262cbb963deSAndy Shevchenko 				netdev_dbg(dev->net,
263cbb963deSAndy Shevchenko 					"Received expected unknown frame header: %6phC. Package length: %i\n",
264cbb963deSAndy Shevchenko 					header_start,
265d4026123SMarius B. Kotsbak 					skb->len - KALMIA_HEADER_LENGTH);
266d4026123SMarius B. Kotsbak 			}
267d4026123SMarius B. Kotsbak 			else {
268cbb963deSAndy Shevchenko 				netdev_err(dev->net,
269cbb963deSAndy Shevchenko 					"Received unknown frame header: %6phC. Package length: %i\n",
270cbb963deSAndy Shevchenko 					header_start,
271d4026123SMarius B. Kotsbak 					skb->len - KALMIA_HEADER_LENGTH);
272d4026123SMarius B. Kotsbak 				return 0;
273d4026123SMarius B. Kotsbak 			}
274d4026123SMarius B. Kotsbak 		}
275d4026123SMarius B. Kotsbak 		else
276cbb963deSAndy Shevchenko 			netdev_dbg(dev->net,
277cbb963deSAndy Shevchenko 				"Received header: %6phC. Package length: %i\n",
278cbb963deSAndy Shevchenko 				header_start, skb->len - KALMIA_HEADER_LENGTH);
279d4026123SMarius B. Kotsbak 
280d4026123SMarius B. Kotsbak 		/* subtract start header and end header */
281d4026123SMarius B. Kotsbak 		usb_packet_length = skb->len - (2 * KALMIA_HEADER_LENGTH);
2827cdfa4a3SMarius B. Kotsbak 		ether_packet_length = get_unaligned_le16(&header_start[2]);
283d4026123SMarius B. Kotsbak 		skb_pull(skb, KALMIA_HEADER_LENGTH);
284d4026123SMarius B. Kotsbak 
285d4026123SMarius B. Kotsbak 		/* Some small packets misses end marker */
286d4026123SMarius B. Kotsbak 		if (usb_packet_length < ether_packet_length) {
287d4026123SMarius B. Kotsbak 			ether_packet_length = usb_packet_length
288d4026123SMarius B. Kotsbak 				+ KALMIA_HEADER_LENGTH;
289d4026123SMarius B. Kotsbak 			is_last = true;
290d4026123SMarius B. Kotsbak 		}
291d4026123SMarius B. Kotsbak 		else {
292d4026123SMarius B. Kotsbak 			netdev_dbg(dev->net, "Correct package length #%i", i
293d4026123SMarius B. Kotsbak 				+ 1);
294d4026123SMarius B. Kotsbak 
295d4026123SMarius B. Kotsbak 			is_last = (memcmp(skb->data + ether_packet_length,
296d4026123SMarius B. Kotsbak 				HEADER_END_OF_USB_PACKET,
297d4026123SMarius B. Kotsbak 				sizeof(HEADER_END_OF_USB_PACKET)) == 0);
298d4026123SMarius B. Kotsbak 			if (!is_last) {
299d4026123SMarius B. Kotsbak 				header_start = skb->data + ether_packet_length;
300cbb963deSAndy Shevchenko 				netdev_dbg(dev->net,
301cbb963deSAndy Shevchenko 					"End header: %6phC. Package length: %i\n",
302cbb963deSAndy Shevchenko 					header_start,
303d4026123SMarius B. Kotsbak 					skb->len - KALMIA_HEADER_LENGTH);
304d4026123SMarius B. Kotsbak 			}
305d4026123SMarius B. Kotsbak 		}
306d4026123SMarius B. Kotsbak 
307d4026123SMarius B. Kotsbak 		if (is_last) {
308d4026123SMarius B. Kotsbak 			skb2 = skb;
309d4026123SMarius B. Kotsbak 		}
310d4026123SMarius B. Kotsbak 		else {
311d4026123SMarius B. Kotsbak 			skb2 = skb_clone(skb, GFP_ATOMIC);
312d4026123SMarius B. Kotsbak 			if (unlikely(!skb2))
313d4026123SMarius B. Kotsbak 				return 0;
314d4026123SMarius B. Kotsbak 		}
315d4026123SMarius B. Kotsbak 
316d4026123SMarius B. Kotsbak 		skb_trim(skb2, ether_packet_length);
317d4026123SMarius B. Kotsbak 
318d4026123SMarius B. Kotsbak 		if (is_last) {
319d4026123SMarius B. Kotsbak 			return 1;
320d4026123SMarius B. Kotsbak 		}
321d4026123SMarius B. Kotsbak 		else {
322d4026123SMarius B. Kotsbak 			usbnet_skb_return(dev, skb2);
323d4026123SMarius B. Kotsbak 			skb_pull(skb, ether_packet_length);
324d4026123SMarius B. Kotsbak 		}
325d4026123SMarius B. Kotsbak 
326d4026123SMarius B. Kotsbak 		i++;
327d4026123SMarius B. Kotsbak 	}
328d4026123SMarius B. Kotsbak 	while (skb->len);
329d4026123SMarius B. Kotsbak 
330d4026123SMarius B. Kotsbak 	return 1;
331d4026123SMarius B. Kotsbak }
332d4026123SMarius B. Kotsbak 
333d4026123SMarius B. Kotsbak static const struct driver_info kalmia_info = {
334d4026123SMarius B. Kotsbak 	.description = "Samsung Kalmia LTE USB dongle",
335d4026123SMarius B. Kotsbak 	.flags = FLAG_WWAN,
336d4026123SMarius B. Kotsbak 	.bind = kalmia_bind,
337d4026123SMarius B. Kotsbak 	.rx_fixup = kalmia_rx_fixup,
338d4026123SMarius B. Kotsbak 	.tx_fixup = kalmia_tx_fixup
339d4026123SMarius B. Kotsbak };
340d4026123SMarius B. Kotsbak 
341d4026123SMarius B. Kotsbak /*-------------------------------------------------------------------------*/
342d4026123SMarius B. Kotsbak 
343d4026123SMarius B. Kotsbak static const struct usb_device_id products[] = {
344d4026123SMarius B. Kotsbak 	/* The unswitched USB ID, to get the module auto loaded: */
345d4026123SMarius B. Kotsbak 	{ USB_DEVICE(0x04e8, 0x689a) },
34608a7e621SMasahiro Yamada 	/* The stick switched into modem (by e.g. usb_modeswitch): */
347d4026123SMarius B. Kotsbak 	{ USB_DEVICE(0x04e8, 0x6889),
348d4026123SMarius B. Kotsbak 		.driver_info = (unsigned long) &kalmia_info, },
349d4026123SMarius B. Kotsbak 	{ /* EMPTY == end of list */} };
350d4026123SMarius B. Kotsbak MODULE_DEVICE_TABLE( usb, products);
351d4026123SMarius B. Kotsbak 
352d4026123SMarius B. Kotsbak static struct usb_driver kalmia_driver = {
353d4026123SMarius B. Kotsbak 	.name = "kalmia",
354d4026123SMarius B. Kotsbak 	.id_table = products,
355d4026123SMarius B. Kotsbak 	.probe = usbnet_probe,
356d4026123SMarius B. Kotsbak 	.disconnect = usbnet_disconnect,
357d4026123SMarius B. Kotsbak 	.suspend = usbnet_suspend,
358e1f12eb6SSarah Sharp 	.resume = usbnet_resume,
359e1f12eb6SSarah Sharp 	.disable_hub_initiated_lpm = 1,
360d4026123SMarius B. Kotsbak };
361d4026123SMarius B. Kotsbak 
362d632eb1bSGreg Kroah-Hartman module_usb_driver(kalmia_driver);
363d4026123SMarius B. Kotsbak 
364d4026123SMarius B. Kotsbak MODULE_AUTHOR("Marius Bjoernstad Kotsbak <marius@kotsbak.com>");
365d4026123SMarius B. Kotsbak MODULE_DESCRIPTION("Samsung Kalmia USB network driver");
366d4026123SMarius B. Kotsbak MODULE_LICENSE("GPL");
367