All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] net/usb: Add Samsung Kalmia driver for Samsung GT-B3730
@ 2011-06-10 23:34 Marius B. Kotsbak
       [not found] ` <1307748870-12950-1-git-send-email-marius-iy5w9mehe2BBDgjK7y7TUQ@public.gmane.org>
  0 siblings, 1 reply; 35+ messages in thread
From: Marius B. Kotsbak @ 2011-06-10 23:34 UTC (permalink / raw)
  To: davem, netdev; +Cc: linux-usb, Marius B. Kotsbak

Introducing driver for the network port of Samsung Kalmia based USB LTE modems.
It has also an ACM interface that previous patches associates with the "option"
module. To access those interfaces, the modem must first be switched from modem
mode using a tool like usb_modeswitch.

As the proprietary protocol has been discovered by watching the MS Windows driver
behavior, there might be errors in the protocol handling, but stable and fast
connection has been established for hours with Norwegian operator NetCom that
distributes this modem with their LTE/4G subscription.

More and updated information about how to use this driver is available here:

http://www.draisberghof.de/usb_modeswitch/bb/viewtopic.php?t=465
https://github.com/mkotsbak/Samsung-GT-B3730-linux-driver

Signed-off-by: Marius B. Kotsbak <marius@kotsbak.com>
---
 drivers/net/usb/Kconfig  |   10 ++
 drivers/net/usb/Makefile |    2 +-
 drivers/net/usb/kalmia.c |  393 ++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 404 insertions(+), 1 deletions(-)
 create mode 100644 drivers/net/usb/kalmia.c

diff --git a/drivers/net/usb/Kconfig b/drivers/net/usb/Kconfig
index 9d4f911..b6e4efc 100644
--- a/drivers/net/usb/Kconfig
+++ b/drivers/net/usb/Kconfig
@@ -385,6 +385,16 @@ config USB_NET_CX82310_ETH
 	  router with USB ethernet port. This driver is for routers only,
 	  it will not work with ADSL modems (use cxacru driver instead).
 
+config CONFIG_USB_NET_KALMIA
+	tristate "Samsung Kalmia based LTE USB modem"
+	depends on USB_USBNET
+	help
+	  Choose this option if you have a Samsung Kalmia based USB modem
+	  as Samsung GT-B3730.
+
+	  To compile this driver as a module, choose M here: the
+	  module will be called kalmia.
+
 config USB_HSO
 	tristate "Option USB High Speed Mobile Devices"
 	depends on USB && RFKILL
diff --git a/drivers/net/usb/Makefile b/drivers/net/usb/Makefile
index c7ec8a5..6091249 100644
--- a/drivers/net/usb/Makefile
+++ b/drivers/net/usb/Makefile
@@ -28,4 +28,4 @@ obj-$(CONFIG_USB_SIERRA_NET)	+= sierra_net.o
 obj-$(CONFIG_USB_NET_CX82310_ETH)	+= cx82310_eth.o
 obj-$(CONFIG_USB_NET_CDC_NCM)	+= cdc_ncm.o
 obj-$(CONFIG_USB_VL600)		+= lg-vl600.o
-
+obj-$(CONFIG_USB_NET_KALMIA)	+= kalmia.o
diff --git a/drivers/net/usb/kalmia.c b/drivers/net/usb/kalmia.c
new file mode 100644
index 0000000..d1e80e0
--- /dev/null
+++ b/drivers/net/usb/kalmia.c
@@ -0,0 +1,393 @@
+/*
+ * USB network interface driver for Samsung Kalmia based LTE USB modem like the
+ * Samsung GT-B3730 and GT-B3710.
+ *
+ * Copyright (C) 2011 Marius Bjoernstad Kotsbak
+ *
+ * Sponsored by Quicklink Video Distribution Services Ltd.
+ *
+ * Based on the cdc_eem module.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * 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.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#include <linux/module.h>
+#include <linux/init.h>
+#include <linux/netdevice.h>
+#include <linux/etherdevice.h>
+#include <linux/ctype.h>
+#include <linux/ethtool.h>
+#include <linux/workqueue.h>
+#include <linux/mii.h>
+#include <linux/usb.h>
+#include <linux/crc32.h>
+#include <linux/usb/cdc.h>
+#include <linux/usb/usbnet.h>
+#include <linux/gfp.h>
+
+/*
+ * The Samsung Kalmia based LTE USB modems have a CDC ACM port for modem control
+ * handled by the "option" module and an ethernet data port handled by this
+ * module.
+ *
+ * The stick must first be switched into modem mode by usb_modeswitch
+ * or similar tool. Then the modem gets sent two initialization packets by
+ * this module, which gives the MAC address of the device. User space can then
+ * connect the modem using AT commands through the ACM port and then use
+ * DHCP on the network interface exposed by this module. Network packets are
+ * sent to and from the modem in a proprietary format discovered after watching
+ * the behavior of the windows driver for the modem.
+ *
+ * More information about the use of the modem is available in usb_modeswitch
+ * forum and the project page:
+ *
+ * http://www.draisberghof.de/usb_modeswitch/bb/viewtopic.php?t=465
+ * https://github.com/mkotsbak/Samsung-GT-B3730-linux-driver
+ */
+
+/* #define	DEBUG */
+/* #define	VERBOSE */
+
+#define KALMIA_HEADER_LENGTH 6
+#define KALMIA_ALIGN_SIZE 4
+#define KALMIA_USB_TIMEOUT 10000
+
+/*-------------------------------------------------------------------------*/
+
+static int
+kalmia_send_init_packet(struct usbnet *dev, u8 *init_msg, u8 init_msg_len,
+	u8 *buffer, u8 expected_len)
+{
+	int act_len;
+	int status;
+
+	netdev_dbg(dev->net, "Sending init packet");
+
+	status = usb_bulk_msg(dev->udev, usb_sndbulkpipe(dev->udev, 0x02),
+		init_msg, init_msg_len, &act_len, KALMIA_USB_TIMEOUT);
+	if (status != 0) {
+		netdev_err(dev->net,
+			"Error sending init packet. Status %i, length %i\n",
+			status, act_len);
+		return status;
+	}
+	else if (act_len != init_msg_len) {
+		netdev_err(dev->net,
+			"Did not send all of init packet. Bytes sent: %i",
+			act_len);
+	}
+	else {
+		netdev_dbg(dev->net, "Successfully sent init packet.");
+	}
+
+	status = usb_bulk_msg(dev->udev, usb_rcvbulkpipe(dev->udev, 0x81),
+		buffer, expected_len, &act_len, KALMIA_USB_TIMEOUT);
+
+	if (status != 0)
+		netdev_err(dev->net,
+			"Error receiving init result. Status %i, length %i\n",
+			status, act_len);
+	else if (act_len != expected_len)
+		netdev_err(dev->net, "Unexpected init result length: %i\n",
+			act_len);
+
+	return status;
+}
+
+static int
+kalmia_init_and_get_ethernet_addr(struct usbnet *dev, u8 *ethernet_addr)
+{
+	char init_msg_1[] =
+		{ 0x57, 0x50, 0x04, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00,
+		0x00, 0x00 };
+	char init_msg_2[] =
+		{ 0x57, 0x50, 0x04, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0xf4,
+		0x00, 0x00 };
+	char receive_buf[28];
+	int status;
+
+	status = kalmia_send_init_packet(dev, init_msg_1, sizeof(init_msg_1)
+		/ sizeof(init_msg_1[0]), receive_buf, 24);
+	if (status != 0)
+		return status;
+
+	status = kalmia_send_init_packet(dev, init_msg_2, sizeof(init_msg_2)
+		/ sizeof(init_msg_2[0]), receive_buf, 28);
+	if (status != 0)
+		return status;
+
+	memcpy(ethernet_addr, receive_buf + 10, ETH_ALEN);
+
+	return status;
+}
+
+static int
+kalmia_bind(struct usbnet *dev, struct usb_interface *intf)
+{
+	u8 status;
+	u8 ethernet_addr[ETH_ALEN];
+
+	/* Don't bind to AT command interface */
+	if (intf->cur_altsetting->desc.bInterfaceClass != USB_CLASS_VENDOR_SPEC)
+		return -EINVAL;
+
+	dev->in = usb_rcvbulkpipe(dev->udev, 0x81 & USB_ENDPOINT_NUMBER_MASK);
+	dev->out = usb_sndbulkpipe(dev->udev, 0x02 & USB_ENDPOINT_NUMBER_MASK);
+	dev->status = NULL;
+
+	dev->net->hard_header_len += KALMIA_HEADER_LENGTH;
+	dev->hard_mtu = 1400;
+	dev->rx_urb_size = dev->hard_mtu * 10; // Found as optimal after testing
+
+	status = kalmia_init_and_get_ethernet_addr(dev, ethernet_addr);
+
+	if (status < 0) {
+		usb_set_intfdata(intf, NULL);
+		usb_driver_release_interface(driver_of(intf), intf);
+		return status;
+	}
+
+	memcpy(dev->net->dev_addr, ethernet_addr, ETH_ALEN);
+	memcpy(dev->net->perm_addr, ethernet_addr, ETH_ALEN);
+
+	return status;
+}
+
+static struct sk_buff *
+kalmia_tx_fixup(struct usbnet *dev, struct sk_buff *skb, gfp_t flags)
+{
+	struct sk_buff *skb2 = NULL;
+	u16 content_len;
+	unsigned char *header_start;
+	unsigned char ether_type_1, ether_type_2;
+	u8 remainder, padlen = 0;
+
+	if (!skb_cloned(skb)) {
+		int headroom = skb_headroom(skb);
+		int tailroom = skb_tailroom(skb);
+
+		if ((tailroom >= KALMIA_ALIGN_SIZE) && (headroom
+			>= KALMIA_HEADER_LENGTH))
+			goto done;
+
+		if ((headroom + tailroom) > (KALMIA_HEADER_LENGTH
+			+ KALMIA_ALIGN_SIZE)) {
+			skb->data = memmove(skb->head + KALMIA_HEADER_LENGTH,
+				skb->data, skb->len);
+			skb_set_tail_pointer(skb, skb->len);
+			goto done;
+		}
+	}
+
+	skb2 = skb_copy_expand(skb, KALMIA_HEADER_LENGTH,
+		KALMIA_ALIGN_SIZE, flags);
+	if (!skb2)
+		return NULL;
+
+	dev_kfree_skb_any(skb);
+	skb = skb2;
+
+	done: header_start = skb_push(skb, KALMIA_HEADER_LENGTH);
+	ether_type_1 = header_start[KALMIA_HEADER_LENGTH + 12];
+	ether_type_2 = header_start[KALMIA_HEADER_LENGTH + 13];
+
+	netdev_dbg(dev->net, "Sending etherType: %02x%02x", ether_type_1,
+		ether_type_2);
+
+	/* According to empiric data for data packages */
+	header_start[0] = 0x57;
+	header_start[1] = 0x44;
+	content_len = skb->len - KALMIA_HEADER_LENGTH;
+	header_start[2] = (content_len & 0xff); /* low byte */
+	header_start[3] = (content_len >> 8); /* high byte */
+
+	header_start[4] = ether_type_1;
+	header_start[5] = ether_type_2;
+
+	/* Align to 4 bytes by padding with zeros */
+	remainder = skb->len % KALMIA_ALIGN_SIZE;
+	if (remainder > 0) {
+		padlen = KALMIA_ALIGN_SIZE - remainder;
+		memset(skb_put(skb, padlen), 0, padlen);
+	}
+
+	netdev_dbg(
+		dev->net,
+		"Sending package with length %i and padding %i. Header: %02x:%02x:%02x:%02x:%02x:%02x.",
+		content_len, padlen, header_start[0], header_start[1],
+		header_start[2], header_start[3], header_start[4],
+		header_start[5]);
+
+	return skb;
+}
+
+static int
+kalmia_rx_fixup(struct usbnet *dev, struct sk_buff *skb)
+{
+	/*
+	 * Our task here is to strip off framing, leaving skb with one
+	 * data frame for the usbnet framework code to process.
+	 */
+	const u8 HEADER_END_OF_USB_PACKET[] =
+		{ 0x57, 0x5a, 0x00, 0x00, 0x08, 0x00 };
+	const u8 EXPECTED_UNKNOWN_HEADER_1[] =
+		{ 0x57, 0x43, 0x1e, 0x00, 0x15, 0x02 };
+	const u8 EXPECTED_UNKNOWN_HEADER_2[] =
+		{ 0x57, 0x50, 0x0e, 0x00, 0x00, 0x00 };
+	u8 i = 0;
+
+	/* incomplete header? */
+	if (skb->len < KALMIA_HEADER_LENGTH)
+		return 0;
+
+	do {
+		struct sk_buff *skb2 = NULL;
+		u8 *header_start;
+		u16 usb_packet_length, ether_packet_length;
+		int is_last;
+
+		header_start = skb->data;
+
+		if (unlikely(header_start[0] != 0x57 || header_start[1] != 0x44)) {
+			if (!memcmp(header_start, EXPECTED_UNKNOWN_HEADER_1,
+				sizeof(EXPECTED_UNKNOWN_HEADER_1)) || !memcmp(
+				header_start, EXPECTED_UNKNOWN_HEADER_2,
+				sizeof(EXPECTED_UNKNOWN_HEADER_2))) {
+				netdev_dbg(
+					dev->net,
+					"Received expected unknown frame header: %02x:%02x:%02x:%02x:%02x:%02x. Package length: %i\n",
+					header_start[0], header_start[1],
+					header_start[2], header_start[3],
+					header_start[4], header_start[5],
+					skb->len - KALMIA_HEADER_LENGTH);
+			}
+			else {
+				netdev_err(
+					dev->net,
+					"Received unknown frame header: %02x:%02x:%02x:%02x:%02x:%02x. Package length: %i\n",
+					header_start[0], header_start[1],
+					header_start[2], header_start[3],
+					header_start[4], header_start[5],
+					skb->len - KALMIA_HEADER_LENGTH);
+				return 0;
+			}
+		}
+		else
+			netdev_dbg(
+				dev->net,
+				"Received header: %02x:%02x:%02x:%02x:%02x:%02x. Package length: %i\n",
+				header_start[0], header_start[1], header_start[2],
+				header_start[3], header_start[4], header_start[5],
+				skb->len - KALMIA_HEADER_LENGTH);
+
+		/* subtract start header and end header */
+		usb_packet_length = skb->len - (2 * KALMIA_HEADER_LENGTH);
+		ether_packet_length = header_start[2] + (header_start[3] << 8);
+		skb_pull(skb, KALMIA_HEADER_LENGTH);
+
+		/* Some small packets misses end marker */
+		if (usb_packet_length < ether_packet_length) {
+			ether_packet_length = usb_packet_length
+				+ KALMIA_HEADER_LENGTH;
+			is_last = true;
+		}
+		else {
+			netdev_dbg(dev->net, "Correct package length #%i", i
+				+ 1);
+
+			is_last = (memcmp(skb->data + ether_packet_length,
+				HEADER_END_OF_USB_PACKET,
+				sizeof(HEADER_END_OF_USB_PACKET)) == 0);
+			if (!is_last) {
+				header_start = skb->data + ether_packet_length;
+				netdev_dbg(
+					dev->net,
+					"End header: %02x:%02x:%02x:%02x:%02x:%02x. Package length: %i\n",
+					header_start[0], header_start[1],
+					header_start[2], header_start[3],
+					header_start[4], header_start[5],
+					skb->len - KALMIA_HEADER_LENGTH);
+			}
+		}
+
+		if (is_last) {
+			skb2 = skb;
+		}
+		else {
+			skb2 = skb_clone(skb, GFP_ATOMIC);
+			if (unlikely(!skb2))
+				return 0;
+		}
+
+		skb_trim(skb2, ether_packet_length);
+
+		if (is_last) {
+			return 1;
+		}
+		else {
+			usbnet_skb_return(dev, skb2);
+			skb_pull(skb, ether_packet_length);
+		}
+
+		i++;
+	}
+	while (skb->len);
+
+	return 1;
+}
+
+static const struct driver_info kalmia_info = {
+	.description = "Samsung Kalmia LTE USB dongle",
+	.flags = FLAG_WWAN,
+	.bind = kalmia_bind,
+	.rx_fixup = kalmia_rx_fixup,
+	.tx_fixup = kalmia_tx_fixup
+};
+
+/*-------------------------------------------------------------------------*/
+
+static const struct usb_device_id products[] = {
+	/* The unswitched USB ID, to get the module auto loaded: */
+	{ USB_DEVICE(0x04e8, 0x689a) },
+	/* The stick swithed into modem (by e.g. usb_modeswitch): */
+	{ USB_DEVICE(0x04e8, 0x6889),
+		.driver_info = (unsigned long) &kalmia_info, },
+	{ /* EMPTY == end of list */} };
+MODULE_DEVICE_TABLE( usb, products);
+
+static struct usb_driver kalmia_driver = {
+	.name = "kalmia",
+	.id_table = products,
+	.probe = usbnet_probe,
+	.disconnect = usbnet_disconnect,
+	.suspend = usbnet_suspend,
+	.resume = usbnet_resume
+};
+
+static int __init kalmia_init(void)
+{
+	return usb_register(&kalmia_driver);
+}
+module_init( kalmia_init);
+
+static void __exit kalmia_exit(void)
+{
+	usb_deregister(&kalmia_driver);
+}
+module_exit( kalmia_exit);
+
+MODULE_AUTHOR("Marius Bjoernstad Kotsbak <marius@kotsbak.com>");
+MODULE_DESCRIPTION("Samsung Kalmia USB network driver");
+MODULE_LICENSE("GPL");
-- 
1.7.4.1


^ permalink raw reply related	[flat|nested] 35+ messages in thread

* Re: [PATCH] net/usb: Add Samsung Kalmia driver for Samsung GT-B3730
       [not found] ` <1307748870-12950-1-git-send-email-marius-iy5w9mehe2BBDgjK7y7TUQ@public.gmane.org>
@ 2011-06-10 23:55   ` Greg KH
       [not found]     ` <20110610235557.GA23443-U8xfFu+wG4EAvxtiuMwx3w@public.gmane.org>
  2011-06-13 14:57   ` Dan Williams
  1 sibling, 1 reply; 35+ messages in thread
From: Greg KH @ 2011-06-10 23:55 UTC (permalink / raw)
  To: Marius B. Kotsbak
  Cc: davem-fT/PcQaiUtIeIZ0/mPfg9Q, netdev-u79uwXL29TY76Z2rM5mHXA,
	linux-usb-u79uwXL29TY76Z2rM5mHXA, Marius B. Kotsbak

On Sat, Jun 11, 2011 at 01:34:30AM +0200, Marius B. Kotsbak wrote:
> Introducing driver for the network port of Samsung Kalmia based USB LTE modems.
> It has also an ACM interface that previous patches associates with the "option"
> module. To access those interfaces, the modem must first be switched from modem
> mode using a tool like usb_modeswitch.

Do we need to blacklist this device from the option driver?  We can do
that easily then you don't need a usb_modeswitch change, right?

> As the proprietary protocol has been discovered by watching the MS Windows driver
> behavior, there might be errors in the protocol handling, but stable and fast
> connection has been established for hours with Norwegian operator NetCom that
> distributes this modem with their LTE/4G subscription.
> 
> More and updated information about how to use this driver is available here:
> 
> http://www.draisberghof.de/usb_modeswitch/bb/viewtopic.php?t=465
> https://github.com/mkotsbak/Samsung-GT-B3730-linux-driver
> 
> Signed-off-by: Marius B. Kotsbak <marius-iy5w9mehe2BBDgjK7y7TUQ@public.gmane.org>

Very nice job, one minor comment nit:

> +/*
> + * USB network interface driver for Samsung Kalmia based LTE USB modem like the
> + * Samsung GT-B3730 and GT-B3710.
> + *
> + * Copyright (C) 2011 Marius Bjoernstad Kotsbak

Email address after your name?

> + *
> + * Sponsored by Quicklink Video Distribution Services Ltd.
> + *
> + * Based on the cdc_eem module.
> + *
> + * This program is free software; you can redistribute it and/or modify
> + * it under the terms of the GNU General Public License as published by
> + * the Free Software Foundation; either version 2 of the License, or
> + * (at your option) any later version.

Do you really mean "any later version"?

> + *
> + * 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.
> + *
> + * You should have received a copy of the GNU General Public License
> + * along with this program; if not, write to the Free Software
> + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA

These two paragraphs are not needed, and unless you want to track the
FSF's office changes for the next 40+ years, I'd really suggest not
putting it in there at all.

thanks,

greg k-h
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 35+ messages in thread

* Re: [PATCH] net/usb: Add Samsung Kalmia driver for Samsung GT-B3730
       [not found]     ` <20110610235557.GA23443-U8xfFu+wG4EAvxtiuMwx3w@public.gmane.org>
@ 2011-06-11  0:25       ` Marius Kotsbak
  2011-06-11 20:06         ` Greg KH
  0 siblings, 1 reply; 35+ messages in thread
From: Marius Kotsbak @ 2011-06-11  0:25 UTC (permalink / raw)
  To: Greg KH
  Cc: davem-fT/PcQaiUtIeIZ0/mPfg9Q, netdev-u79uwXL29TY76Z2rM5mHXA,
	linux-usb-u79uwXL29TY76Z2rM5mHXA, Marius B. Kotsbak

On 11. juni 2011 01:55, Greg KH wrote:
> On Sat, Jun 11, 2011 at 01:34:30AM +0200, Marius B. Kotsbak wrote:
>> Introducing driver for the network port of Samsung Kalmia based USB LTE modems.
>> It has also an ACM interface that previous patches associates with the "option"
>> module. To access those interfaces, the modem must first be switched from modem
>> mode using a tool like usb_modeswitch.
> Do we need to blacklist this device from the option driver?

It is already done, in commits:

80f9df3e0093ad9f1eeefd2ff7fd27daaa518d25
15b2f3204a5c878c32939094775fb7349f707263

>   We can do
> that easily then you don't need a usb_modeswitch change, right?

usb_modeswitch is for turning it into a modem (with network+modem
interface) instead of just a windows driver serving dongle.

It is a tricky story, and it also is a problem using usb_modeswitch
newer than 1.1.4:

https://bugs.launchpad.net/ubuntu/+source/usb-modeswitch/+bug/769816

>> As the proprietary protocol has been discovered by watching the MS Windows driver
>> behavior, there might be errors in the protocol handling, but stable and fast
>> connection has been established for hours with Norwegian operator NetCom that
>> distributes this modem with their LTE/4G subscription.
>>
>> More and updated information about how to use this driver is available here:
>>
>> http://www.draisberghof.de/usb_modeswitch/bb/viewtopic.php?t=465
>> https://github.com/mkotsbak/Samsung-GT-B3730-linux-driver
>>
>> Signed-off-by: Marius B. Kotsbak <marius-iy5w9mehe2BBDgjK7y7TUQ@public.gmane.org>
> Very nice job, one minor comment nit:
>
>> +/*
>> + * USB network interface driver for Samsung Kalmia based LTE USB modem like the
>> + * Samsung GT-B3730 and GT-B3710.
>> + *
>> + * Copyright (C) 2011 Marius Bjoernstad Kotsbak
> Email address after your name?

Will add.

>> + *
>> + * Sponsored by Quicklink Video Distribution Services Ltd.
>> + *
>> + * Based on the cdc_eem module.
>> + *
>> + * This program is free software; you can redistribute it and/or modify
>> + * it under the terms of the GNU General Public License as published by
>> + * the Free Software Foundation; either version 2 of the License, or
>> + * (at your option) any later version.
> Do you really mean "any later version"?
>

I have not considered it much.

>> + *
>> + * 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.
>> + *
>> + * You should have received a copy of the GNU General Public License
>> + * along with this program; if not, write to the Free Software
>> + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
> These two paragraphs are not needed, and unless you want to track the
> FSF's office changes for the next 40+ years, I'd really suggest not
> putting it in there at all.
>

Same here, I have reused what I found in other modules. Do you have an
example of a module with the recommended header?

--
Marius


--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 35+ messages in thread

* Re: [PATCH] net/usb: Add Samsung Kalmia driver for Samsung GT-B3730
  2011-06-11  0:25       ` Marius Kotsbak
@ 2011-06-11 20:06         ` Greg KH
  2011-06-11 21:55           ` Marius B. Kotsbak
  2011-06-11 21:57           ` Marius Kotsbak
  0 siblings, 2 replies; 35+ messages in thread
From: Greg KH @ 2011-06-11 20:06 UTC (permalink / raw)
  To: Marius Kotsbak; +Cc: davem, netdev, linux-usb, Marius B. Kotsbak

On Sat, Jun 11, 2011 at 02:25:08AM +0200, Marius Kotsbak wrote:
> On 11. juni 2011 01:55, Greg KH wrote:
> > On Sat, Jun 11, 2011 at 01:34:30AM +0200, Marius B. Kotsbak wrote:
> >> Introducing driver for the network port of Samsung Kalmia based USB LTE modems.
> >> It has also an ACM interface that previous patches associates with the "option"
> >> module. To access those interfaces, the modem must first be switched from modem
> >> mode using a tool like usb_modeswitch.
> > Do we need to blacklist this device from the option driver?
> 
> It is already done, in commits:
> 
> 80f9df3e0093ad9f1eeefd2ff7fd27daaa518d25
> 15b2f3204a5c878c32939094775fb7349f707263

Ah, nevermind then :)

> >> + * 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.
> >> + *
> >> + * You should have received a copy of the GNU General Public License
> >> + * along with this program; if not, write to the Free Software
> >> + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
> > These two paragraphs are not needed, and unless you want to track the
> > FSF's office changes for the next 40+ years, I'd really suggest not
> > putting it in there at all.
> >
> 
> Same here, I have reused what I found in other modules. Do you have an
> example of a module with the recommended header?

Just take out these two paragraphs and you should be fine, and be sure
that you really mean "any later" for your license and that you didn't
copy any code from a non "any later" file.

thanks,

greg k-h

^ permalink raw reply	[flat|nested] 35+ messages in thread

* [PATCH] net/usb: Add Samsung Kalmia driver for Samsung GT-B3730
  2011-06-11 20:06         ` Greg KH
@ 2011-06-11 21:55           ` Marius B. Kotsbak
  2011-06-11 23:27             ` David Miller
       [not found]             ` <1307829318-18246-1-git-send-email-marius-iy5w9mehe2BBDgjK7y7TUQ@public.gmane.org>
  2011-06-11 21:57           ` Marius Kotsbak
  1 sibling, 2 replies; 35+ messages in thread
From: Marius B. Kotsbak @ 2011-06-11 21:55 UTC (permalink / raw)
  To: davem, netdev; +Cc: linux-usb, Marius B. Kotsbak

Introducing driver for the network port of Samsung Kalmia based USB LTE modems.
It has also an ACM interface that previous patches associates with the "option"
module. To access those interfaces, the modem must first be switched from modem
mode using a tool like usb_modeswitch.

As the proprietary protocol has been discovered by watching the MS Windows driver
behavior, there might be errors in the protocol handling, but stable and fast
connection has been established for hours with Norwegian operator NetCom that
distributes this modem with their LTE/4G subscription.

More and updated information about how to use this driver is available here:

http://www.draisberghof.de/usb_modeswitch/bb/viewtopic.php?t=465
https://github.com/mkotsbak/Samsung-GT-B3730-linux-driver

Signed-off-by: Marius B. Kotsbak <marius@kotsbak.com>
---
 drivers/net/usb/Kconfig  |   10 ++
 drivers/net/usb/Makefile |    1 +
 drivers/net/usb/kalmia.c |  384 ++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 395 insertions(+), 0 deletions(-)
 create mode 100644 drivers/net/usb/kalmia.c

diff --git a/drivers/net/usb/Kconfig b/drivers/net/usb/Kconfig
index 9d4f911..b6e4efc 100644
--- a/drivers/net/usb/Kconfig
+++ b/drivers/net/usb/Kconfig
@@ -385,6 +385,16 @@ config USB_NET_CX82310_ETH
 	  router with USB ethernet port. This driver is for routers only,
 	  it will not work with ADSL modems (use cxacru driver instead).
 
+config CONFIG_USB_NET_KALMIA
+	tristate "Samsung Kalmia based LTE USB modem"
+	depends on USB_USBNET
+	help
+	  Choose this option if you have a Samsung Kalmia based USB modem
+	  as Samsung GT-B3730.
+
+	  To compile this driver as a module, choose M here: the
+	  module will be called kalmia.
+
 config USB_HSO
 	tristate "Option USB High Speed Mobile Devices"
 	depends on USB && RFKILL
diff --git a/drivers/net/usb/Makefile b/drivers/net/usb/Makefile
index c7ec8a5..c203fa2 100644
--- a/drivers/net/usb/Makefile
+++ b/drivers/net/usb/Makefile
@@ -23,6 +23,7 @@ obj-$(CONFIG_USB_NET_MCS7830)	+= mcs7830.o
 obj-$(CONFIG_USB_USBNET)	+= usbnet.o
 obj-$(CONFIG_USB_NET_INT51X1)	+= int51x1.o
 obj-$(CONFIG_USB_CDC_PHONET)	+= cdc-phonet.o
+obj-$(CONFIG_USB_NET_KALMIA)	+= kalmia.o
 obj-$(CONFIG_USB_IPHETH)	+= ipheth.o
 obj-$(CONFIG_USB_SIERRA_NET)	+= sierra_net.o
 obj-$(CONFIG_USB_NET_CX82310_ETH)	+= cx82310_eth.o
diff --git a/drivers/net/usb/kalmia.c b/drivers/net/usb/kalmia.c
new file mode 100644
index 0000000..d965fb1
--- /dev/null
+++ b/drivers/net/usb/kalmia.c
@@ -0,0 +1,384 @@
+/*
+ * USB network interface driver for Samsung Kalmia based LTE USB modem like the
+ * Samsung GT-B3730 and GT-B3710.
+ *
+ * Copyright (C) 2011 Marius Bjoernstad Kotsbak <marius@kotsbak.com>
+ *
+ * Sponsored by Quicklink Video Distribution Services Ltd.
+ *
+ * Based on the cdc_eem module.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ */
+
+#include <linux/module.h>
+#include <linux/init.h>
+#include <linux/netdevice.h>
+#include <linux/etherdevice.h>
+#include <linux/ctype.h>
+#include <linux/ethtool.h>
+#include <linux/workqueue.h>
+#include <linux/mii.h>
+#include <linux/usb.h>
+#include <linux/crc32.h>
+#include <linux/usb/cdc.h>
+#include <linux/usb/usbnet.h>
+#include <linux/gfp.h>
+
+/*
+ * The Samsung Kalmia based LTE USB modems have a CDC ACM port for modem control
+ * handled by the "option" module and an ethernet data port handled by this
+ * module.
+ *
+ * The stick must first be switched into modem mode by usb_modeswitch
+ * or similar tool. Then the modem gets sent two initialization packets by
+ * this module, which gives the MAC address of the device. User space can then
+ * connect the modem using AT commands through the ACM port and then use
+ * DHCP on the network interface exposed by this module. Network packets are
+ * sent to and from the modem in a proprietary format discovered after watching
+ * the behavior of the windows driver for the modem.
+ *
+ * More information about the use of the modem is available in usb_modeswitch
+ * forum and the project page:
+ *
+ * http://www.draisberghof.de/usb_modeswitch/bb/viewtopic.php?t=465
+ * https://github.com/mkotsbak/Samsung-GT-B3730-linux-driver
+ */
+
+/* #define	DEBUG */
+/* #define	VERBOSE */
+
+#define KALMIA_HEADER_LENGTH 6
+#define KALMIA_ALIGN_SIZE 4
+#define KALMIA_USB_TIMEOUT 10000
+
+/*-------------------------------------------------------------------------*/
+
+static int
+kalmia_send_init_packet(struct usbnet *dev, u8 *init_msg, u8 init_msg_len,
+	u8 *buffer, u8 expected_len)
+{
+	int act_len;
+	int status;
+
+	netdev_dbg(dev->net, "Sending init packet");
+
+	status = usb_bulk_msg(dev->udev, usb_sndbulkpipe(dev->udev, 0x02),
+		init_msg, init_msg_len, &act_len, KALMIA_USB_TIMEOUT);
+	if (status != 0) {
+		netdev_err(dev->net,
+			"Error sending init packet. Status %i, length %i\n",
+			status, act_len);
+		return status;
+	}
+	else if (act_len != init_msg_len) {
+		netdev_err(dev->net,
+			"Did not send all of init packet. Bytes sent: %i",
+			act_len);
+	}
+	else {
+		netdev_dbg(dev->net, "Successfully sent init packet.");
+	}
+
+	status = usb_bulk_msg(dev->udev, usb_rcvbulkpipe(dev->udev, 0x81),
+		buffer, expected_len, &act_len, KALMIA_USB_TIMEOUT);
+
+	if (status != 0)
+		netdev_err(dev->net,
+			"Error receiving init result. Status %i, length %i\n",
+			status, act_len);
+	else if (act_len != expected_len)
+		netdev_err(dev->net, "Unexpected init result length: %i\n",
+			act_len);
+
+	return status;
+}
+
+static int
+kalmia_init_and_get_ethernet_addr(struct usbnet *dev, u8 *ethernet_addr)
+{
+	char init_msg_1[] =
+		{ 0x57, 0x50, 0x04, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00,
+		0x00, 0x00 };
+	char init_msg_2[] =
+		{ 0x57, 0x50, 0x04, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0xf4,
+		0x00, 0x00 };
+	char receive_buf[28];
+	int status;
+
+	status = kalmia_send_init_packet(dev, init_msg_1, sizeof(init_msg_1)
+		/ sizeof(init_msg_1[0]), receive_buf, 24);
+	if (status != 0)
+		return status;
+
+	status = kalmia_send_init_packet(dev, init_msg_2, sizeof(init_msg_2)
+		/ sizeof(init_msg_2[0]), receive_buf, 28);
+	if (status != 0)
+		return status;
+
+	memcpy(ethernet_addr, receive_buf + 10, ETH_ALEN);
+
+	return status;
+}
+
+static int
+kalmia_bind(struct usbnet *dev, struct usb_interface *intf)
+{
+	u8 status;
+	u8 ethernet_addr[ETH_ALEN];
+
+	/* Don't bind to AT command interface */
+	if (intf->cur_altsetting->desc.bInterfaceClass != USB_CLASS_VENDOR_SPEC)
+		return -EINVAL;
+
+	dev->in = usb_rcvbulkpipe(dev->udev, 0x81 & USB_ENDPOINT_NUMBER_MASK);
+	dev->out = usb_sndbulkpipe(dev->udev, 0x02 & USB_ENDPOINT_NUMBER_MASK);
+	dev->status = NULL;
+
+	dev->net->hard_header_len += KALMIA_HEADER_LENGTH;
+	dev->hard_mtu = 1400;
+	dev->rx_urb_size = dev->hard_mtu * 10; // Found as optimal after testing
+
+	status = kalmia_init_and_get_ethernet_addr(dev, ethernet_addr);
+
+	if (status < 0) {
+		usb_set_intfdata(intf, NULL);
+		usb_driver_release_interface(driver_of(intf), intf);
+		return status;
+	}
+
+	memcpy(dev->net->dev_addr, ethernet_addr, ETH_ALEN);
+	memcpy(dev->net->perm_addr, ethernet_addr, ETH_ALEN);
+
+	return status;
+}
+
+static struct sk_buff *
+kalmia_tx_fixup(struct usbnet *dev, struct sk_buff *skb, gfp_t flags)
+{
+	struct sk_buff *skb2 = NULL;
+	u16 content_len;
+	unsigned char *header_start;
+	unsigned char ether_type_1, ether_type_2;
+	u8 remainder, padlen = 0;
+
+	if (!skb_cloned(skb)) {
+		int headroom = skb_headroom(skb);
+		int tailroom = skb_tailroom(skb);
+
+		if ((tailroom >= KALMIA_ALIGN_SIZE) && (headroom
+			>= KALMIA_HEADER_LENGTH))
+			goto done;
+
+		if ((headroom + tailroom) > (KALMIA_HEADER_LENGTH
+			+ KALMIA_ALIGN_SIZE)) {
+			skb->data = memmove(skb->head + KALMIA_HEADER_LENGTH,
+				skb->data, skb->len);
+			skb_set_tail_pointer(skb, skb->len);
+			goto done;
+		}
+	}
+
+	skb2 = skb_copy_expand(skb, KALMIA_HEADER_LENGTH,
+		KALMIA_ALIGN_SIZE, flags);
+	if (!skb2)
+		return NULL;
+
+	dev_kfree_skb_any(skb);
+	skb = skb2;
+
+	done: header_start = skb_push(skb, KALMIA_HEADER_LENGTH);
+	ether_type_1 = header_start[KALMIA_HEADER_LENGTH + 12];
+	ether_type_2 = header_start[KALMIA_HEADER_LENGTH + 13];
+
+	netdev_dbg(dev->net, "Sending etherType: %02x%02x", ether_type_1,
+		ether_type_2);
+
+	/* According to empiric data for data packages */
+	header_start[0] = 0x57;
+	header_start[1] = 0x44;
+	content_len = skb->len - KALMIA_HEADER_LENGTH;
+	header_start[2] = (content_len & 0xff); /* low byte */
+	header_start[3] = (content_len >> 8); /* high byte */
+
+	header_start[4] = ether_type_1;
+	header_start[5] = ether_type_2;
+
+	/* Align to 4 bytes by padding with zeros */
+	remainder = skb->len % KALMIA_ALIGN_SIZE;
+	if (remainder > 0) {
+		padlen = KALMIA_ALIGN_SIZE - remainder;
+		memset(skb_put(skb, padlen), 0, padlen);
+	}
+
+	netdev_dbg(
+		dev->net,
+		"Sending package with length %i and padding %i. Header: %02x:%02x:%02x:%02x:%02x:%02x.",
+		content_len, padlen, header_start[0], header_start[1],
+		header_start[2], header_start[3], header_start[4],
+		header_start[5]);
+
+	return skb;
+}
+
+static int
+kalmia_rx_fixup(struct usbnet *dev, struct sk_buff *skb)
+{
+	/*
+	 * Our task here is to strip off framing, leaving skb with one
+	 * data frame for the usbnet framework code to process.
+	 */
+	const u8 HEADER_END_OF_USB_PACKET[] =
+		{ 0x57, 0x5a, 0x00, 0x00, 0x08, 0x00 };
+	const u8 EXPECTED_UNKNOWN_HEADER_1[] =
+		{ 0x57, 0x43, 0x1e, 0x00, 0x15, 0x02 };
+	const u8 EXPECTED_UNKNOWN_HEADER_2[] =
+		{ 0x57, 0x50, 0x0e, 0x00, 0x00, 0x00 };
+	u8 i = 0;
+
+	/* incomplete header? */
+	if (skb->len < KALMIA_HEADER_LENGTH)
+		return 0;
+
+	do {
+		struct sk_buff *skb2 = NULL;
+		u8 *header_start;
+		u16 usb_packet_length, ether_packet_length;
+		int is_last;
+
+		header_start = skb->data;
+
+		if (unlikely(header_start[0] != 0x57 || header_start[1] != 0x44)) {
+			if (!memcmp(header_start, EXPECTED_UNKNOWN_HEADER_1,
+				sizeof(EXPECTED_UNKNOWN_HEADER_1)) || !memcmp(
+				header_start, EXPECTED_UNKNOWN_HEADER_2,
+				sizeof(EXPECTED_UNKNOWN_HEADER_2))) {
+				netdev_dbg(
+					dev->net,
+					"Received expected unknown frame header: %02x:%02x:%02x:%02x:%02x:%02x. Package length: %i\n",
+					header_start[0], header_start[1],
+					header_start[2], header_start[3],
+					header_start[4], header_start[5],
+					skb->len - KALMIA_HEADER_LENGTH);
+			}
+			else {
+				netdev_err(
+					dev->net,
+					"Received unknown frame header: %02x:%02x:%02x:%02x:%02x:%02x. Package length: %i\n",
+					header_start[0], header_start[1],
+					header_start[2], header_start[3],
+					header_start[4], header_start[5],
+					skb->len - KALMIA_HEADER_LENGTH);
+				return 0;
+			}
+		}
+		else
+			netdev_dbg(
+				dev->net,
+				"Received header: %02x:%02x:%02x:%02x:%02x:%02x. Package length: %i\n",
+				header_start[0], header_start[1], header_start[2],
+				header_start[3], header_start[4], header_start[5],
+				skb->len - KALMIA_HEADER_LENGTH);
+
+		/* subtract start header and end header */
+		usb_packet_length = skb->len - (2 * KALMIA_HEADER_LENGTH);
+		ether_packet_length = header_start[2] + (header_start[3] << 8);
+		skb_pull(skb, KALMIA_HEADER_LENGTH);
+
+		/* Some small packets misses end marker */
+		if (usb_packet_length < ether_packet_length) {
+			ether_packet_length = usb_packet_length
+				+ KALMIA_HEADER_LENGTH;
+			is_last = true;
+		}
+		else {
+			netdev_dbg(dev->net, "Correct package length #%i", i
+				+ 1);
+
+			is_last = (memcmp(skb->data + ether_packet_length,
+				HEADER_END_OF_USB_PACKET,
+				sizeof(HEADER_END_OF_USB_PACKET)) == 0);
+			if (!is_last) {
+				header_start = skb->data + ether_packet_length;
+				netdev_dbg(
+					dev->net,
+					"End header: %02x:%02x:%02x:%02x:%02x:%02x. Package length: %i\n",
+					header_start[0], header_start[1],
+					header_start[2], header_start[3],
+					header_start[4], header_start[5],
+					skb->len - KALMIA_HEADER_LENGTH);
+			}
+		}
+
+		if (is_last) {
+			skb2 = skb;
+		}
+		else {
+			skb2 = skb_clone(skb, GFP_ATOMIC);
+			if (unlikely(!skb2))
+				return 0;
+		}
+
+		skb_trim(skb2, ether_packet_length);
+
+		if (is_last) {
+			return 1;
+		}
+		else {
+			usbnet_skb_return(dev, skb2);
+			skb_pull(skb, ether_packet_length);
+		}
+
+		i++;
+	}
+	while (skb->len);
+
+	return 1;
+}
+
+static const struct driver_info kalmia_info = {
+	.description = "Samsung Kalmia LTE USB dongle",
+	.flags = FLAG_WWAN,
+	.bind = kalmia_bind,
+	.rx_fixup = kalmia_rx_fixup,
+	.tx_fixup = kalmia_tx_fixup
+};
+
+/*-------------------------------------------------------------------------*/
+
+static const struct usb_device_id products[] = {
+	/* The unswitched USB ID, to get the module auto loaded: */
+	{ USB_DEVICE(0x04e8, 0x689a) },
+	/* The stick swithed into modem (by e.g. usb_modeswitch): */
+	{ USB_DEVICE(0x04e8, 0x6889),
+		.driver_info = (unsigned long) &kalmia_info, },
+	{ /* EMPTY == end of list */} };
+MODULE_DEVICE_TABLE( usb, products);
+
+static struct usb_driver kalmia_driver = {
+	.name = "kalmia",
+	.id_table = products,
+	.probe = usbnet_probe,
+	.disconnect = usbnet_disconnect,
+	.suspend = usbnet_suspend,
+	.resume = usbnet_resume
+};
+
+static int __init kalmia_init(void)
+{
+	return usb_register(&kalmia_driver);
+}
+module_init( kalmia_init);
+
+static void __exit kalmia_exit(void)
+{
+	usb_deregister(&kalmia_driver);
+}
+module_exit( kalmia_exit);
+
+MODULE_AUTHOR("Marius Bjoernstad Kotsbak <marius@kotsbak.com>");
+MODULE_DESCRIPTION("Samsung Kalmia USB network driver");
+MODULE_LICENSE("GPL");
-- 
1.7.4.1


^ permalink raw reply related	[flat|nested] 35+ messages in thread

* Re: [PATCH] net/usb: Add Samsung Kalmia driver for Samsung GT-B3730
  2011-06-11 20:06         ` Greg KH
  2011-06-11 21:55           ` Marius B. Kotsbak
@ 2011-06-11 21:57           ` Marius Kotsbak
       [not found]             ` <4DF3E4E1.2070309-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
  1 sibling, 1 reply; 35+ messages in thread
From: Marius Kotsbak @ 2011-06-11 21:57 UTC (permalink / raw)
  To: Greg KH; +Cc: davem, netdev, linux-usb, Marius B. Kotsbak

On 11. juni 2011 22:06, Greg KH wrote:
>>>> > >> + * 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.
>>>> > >> + *
>>>> > >> + * You should have received a copy of the GNU General Public License
>>>> > >> + * along with this program; if not, write to the Free Software
>>>> > >> + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
>>> > > These two paragraphs are not needed, and unless you want to track the
>>> > > FSF's office changes for the next 40+ years, I'd really suggest not
>>> > > putting it in there at all.
>>> > >
>> > 
>> > Same here, I have reused what I found in other modules. Do you have an
>> > example of a module with the recommended header?
> Just take out these two paragraphs and you should be fine, and be sure
> that you really mean "any later" for your license and that you didn't
> copy any code from a non "any later" file.
>

Japp, that is fine for me. Fixed the other stuff and sent updated patch
now. How is the possibility of getting a stable backported version of
this one accepted (to Ubuntu LTS/Natty kernel versions)?

--
Marius



^ permalink raw reply	[flat|nested] 35+ messages in thread

* Re: [PATCH] net/usb: Add Samsung Kalmia driver for Samsung GT-B3730
       [not found]             ` <4DF3E4E1.2070309-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
@ 2011-06-11 22:40               ` Greg KH
  0 siblings, 0 replies; 35+ messages in thread
From: Greg KH @ 2011-06-11 22:40 UTC (permalink / raw)
  To: Marius Kotsbak
  Cc: davem-fT/PcQaiUtIeIZ0/mPfg9Q, netdev-u79uwXL29TY76Z2rM5mHXA,
	linux-usb-u79uwXL29TY76Z2rM5mHXA, Marius B. Kotsbak

On Sat, Jun 11, 2011 at 11:57:53PM +0200, Marius Kotsbak wrote:
> On 11. juni 2011 22:06, Greg KH wrote:
> >>>> > >> + * 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.
> >>>> > >> + *
> >>>> > >> + * You should have received a copy of the GNU General Public License
> >>>> > >> + * along with this program; if not, write to the Free Software
> >>>> > >> + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
> >>> > > These two paragraphs are not needed, and unless you want to track the
> >>> > > FSF's office changes for the next 40+ years, I'd really suggest not
> >>> > > putting it in there at all.
> >>> > >
> >> > 
> >> > Same here, I have reused what I found in other modules. Do you have an
> >> > example of a module with the recommended header?
> > Just take out these two paragraphs and you should be fine, and be sure
> > that you really mean "any later" for your license and that you didn't
> > copy any code from a non "any later" file.
> >
> 
> Japp, that is fine for me. Fixed the other stuff and sent updated patch
> now. How is the possibility of getting a stable backported version of
> this one accepted (to Ubuntu LTS/Natty kernel versions)?

Talk to the Ubuntu developers, they are the ones in charge of that.
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 35+ messages in thread

* Re: [PATCH] net/usb: Add Samsung Kalmia driver for Samsung GT-B3730
  2011-06-11 21:55           ` Marius B. Kotsbak
@ 2011-06-11 23:27             ` David Miller
  2011-06-11 23:29               ` David Miller
       [not found]             ` <1307829318-18246-1-git-send-email-marius-iy5w9mehe2BBDgjK7y7TUQ@public.gmane.org>
  1 sibling, 1 reply; 35+ messages in thread
From: David Miller @ 2011-06-11 23:27 UTC (permalink / raw)
  To: marius.kotsbak; +Cc: netdev, linux-usb, marius

From: "Marius B. Kotsbak" <marius.kotsbak@gmail.com>
Date: Sat, 11 Jun 2011 23:55:18 +0200

> Introducing driver for the network port of Samsung Kalmia based USB LTE modems.
> It has also an ACM interface that previous patches associates with the "option"
> module. To access those interfaces, the modem must first be switched from modem
> mode using a tool like usb_modeswitch.
> 
> As the proprietary protocol has been discovered by watching the MS Windows driver
> behavior, there might be errors in the protocol handling, but stable and fast
> connection has been established for hours with Norwegian operator NetCom that
> distributes this modem with their LTE/4G subscription.
> 
> More and updated information about how to use this driver is available here:
> 
> http://www.draisberghof.de/usb_modeswitch/bb/viewtopic.php?t=465
> https://github.com/mkotsbak/Samsung-GT-B3730-linux-driver
> 
> Signed-off-by: Marius B. Kotsbak <marius@kotsbak.com>

Applied, thanks.

^ permalink raw reply	[flat|nested] 35+ messages in thread

* Re: [PATCH] net/usb: Add Samsung Kalmia driver for Samsung GT-B3730
  2011-06-11 23:27             ` David Miller
@ 2011-06-11 23:29               ` David Miller
       [not found]                 ` <20110611.162942.1706711069327005315.davem-fT/PcQaiUtIeIZ0/mPfg9Q@public.gmane.org>
  0 siblings, 1 reply; 35+ messages in thread
From: David Miller @ 2011-06-11 23:29 UTC (permalink / raw)
  To: marius.kotsbak; +Cc: netdev, linux-usb, marius

From: David Miller <davem@davemloft.net>
Date: Sat, 11 Jun 2011 16:27:11 -0700 (PDT)

> From: "Marius B. Kotsbak" <marius.kotsbak@gmail.com>
> Date: Sat, 11 Jun 2011 23:55:18 +0200
> 
>> Introducing driver for the network port of Samsung Kalmia based USB LTE modems.
>> It has also an ACM interface that previous patches associates with the "option"
>> module. To access those interfaces, the modem must first be switched from modem
>> mode using a tool like usb_modeswitch.
>> 
>> As the proprietary protocol has been discovered by watching the MS Windows driver
>> behavior, there might be errors in the protocol handling, but stable and fast
>> connection has been established for hours with Norwegian operator NetCom that
>> distributes this modem with their LTE/4G subscription.
>> 
>> More and updated information about how to use this driver is available here:
>> 
>> http://www.draisberghof.de/usb_modeswitch/bb/viewtopic.php?t=465
>> https://github.com/mkotsbak/Samsung-GT-B3730-linux-driver
>> 
>> Signed-off-by: Marius B. Kotsbak <marius@kotsbak.com>
> 
> Applied, thanks.

Actually, reverted.

There's a typo in your Makefile patch, and because of this it
won't even build the new driver.

People are so damn anxious to get this backported into stable
and various distributions, yet this patch wasn't even tested
properly.

That really drives me crazy.

^ permalink raw reply	[flat|nested] 35+ messages in thread

* Re: [PATCH] net/usb: Add Samsung Kalmia driver for Samsung GT-B3730
       [not found]                 ` <20110611.162942.1706711069327005315.davem-fT/PcQaiUtIeIZ0/mPfg9Q@public.gmane.org>
@ 2011-06-12  3:46                   ` Ben Hutchings
  2011-06-12 12:35                   ` Marius B. Kotsbak
  2011-06-12 12:36                   ` Marius Kotsbak
  2 siblings, 0 replies; 35+ messages in thread
From: Ben Hutchings @ 2011-06-12  3:46 UTC (permalink / raw)
  To: David Miller
  Cc: marius.kotsbak-Re5JQEeQqe8AvxtiuMwx3w,
	netdev-u79uwXL29TY76Z2rM5mHXA, linux-usb-u79uwXL29TY76Z2rM5mHXA,
	marius-iy5w9mehe2BBDgjK7y7TUQ

On Sat, 2011-06-11 at 16:29 -0700, David Miller wrote:
> From: David Miller <davem-fT/PcQaiUtIeIZ0/mPfg9Q@public.gmane.org>
> Date: Sat, 11 Jun 2011 16:27:11 -0700 (PDT)
> 
> > From: "Marius B. Kotsbak" <marius.kotsbak-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
> > Date: Sat, 11 Jun 2011 23:55:18 +0200
> > 
> >> Introducing driver for the network port of Samsung Kalmia based USB LTE modems.
> >> It has also an ACM interface that previous patches associates with the "option"
> >> module. To access those interfaces, the modem must first be switched from modem
> >> mode using a tool like usb_modeswitch.
> >> 
> >> As the proprietary protocol has been discovered by watching the MS Windows driver
> >> behavior, there might be errors in the protocol handling, but stable and fast
> >> connection has been established for hours with Norwegian operator NetCom that
> >> distributes this modem with their LTE/4G subscription.
> >> 
> >> More and updated information about how to use this driver is available here:
> >> 
> >> http://www.draisberghof.de/usb_modeswitch/bb/viewtopic.php?t=465
> >> https://github.com/mkotsbak/Samsung-GT-B3730-linux-driver
> >> 
> >> Signed-off-by: Marius B. Kotsbak <marius-iy5w9mehe2BBDgjK7y7TUQ@public.gmane.org>
> > 
> > Applied, thanks.
> 
> Actually, reverted.
> 
> There's a typo in your Makefile patch, and because of this it
> won't even build the new driver.
[...]

Surely the error is in the Kconfig - the 'CONFIG_' prefix should not be
there.

Ben.

-- 
Ben Hutchings, Senior Software Engineer, Solarflare
Not speaking for my employer; that's the marketing department's job.
They asked us to note that Solarflare product names are trademarked.

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 35+ messages in thread

* [PATCH] net/usb: Add Samsung Kalmia driver for Samsung GT-B3730
       [not found]                 ` <20110611.162942.1706711069327005315.davem-fT/PcQaiUtIeIZ0/mPfg9Q@public.gmane.org>
  2011-06-12  3:46                   ` Ben Hutchings
@ 2011-06-12 12:35                   ` Marius B. Kotsbak
  2011-06-17  2:01                     ` David Miller
  2011-06-12 12:36                   ` Marius Kotsbak
  2 siblings, 1 reply; 35+ messages in thread
From: Marius B. Kotsbak @ 2011-06-12 12:35 UTC (permalink / raw)
  To: davem-fT/PcQaiUtIeIZ0/mPfg9Q, netdev-u79uwXL29TY76Z2rM5mHXA
  Cc: linux-usb-u79uwXL29TY76Z2rM5mHXA, Marius B. Kotsbak

Introducing driver for the network port of Samsung Kalmia based USB LTE modems.
It has also an ACM interface that previous patches associates with the "option"
module. To access those interfaces, the modem must first be switched from modem
mode using a tool like usb_modeswitch.

As the proprietary protocol has been discovered by watching the MS Windows driver
behavior, there might be errors in the protocol handling, but stable and fast
connection has been established for hours with Norwegian operator NetCom that
distributes this modem with their LTE/4G subscription.

More and updated information about how to use this driver is available here:

http://www.draisberghof.de/usb_modeswitch/bb/viewtopic.php?t=465
https://github.com/mkotsbak/Samsung-GT-B3730-linux-driver

Signed-off-by: Marius B. Kotsbak <marius-iy5w9mehe2BBDgjK7y7TUQ@public.gmane.org>
---
 drivers/net/usb/Kconfig  |   10 ++
 drivers/net/usb/Makefile |    1 +
 drivers/net/usb/kalmia.c |  384 ++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 395 insertions(+), 0 deletions(-)
 create mode 100644 drivers/net/usb/kalmia.c

diff --git a/drivers/net/usb/Kconfig b/drivers/net/usb/Kconfig
index 9d4f911..84d4608 100644
--- a/drivers/net/usb/Kconfig
+++ b/drivers/net/usb/Kconfig
@@ -385,6 +385,16 @@ config USB_NET_CX82310_ETH
 	  router with USB ethernet port. This driver is for routers only,
 	  it will not work with ADSL modems (use cxacru driver instead).
 
+config USB_NET_KALMIA
+	tristate "Samsung Kalmia based LTE USB modem"
+	depends on USB_USBNET
+	help
+	  Choose this option if you have a Samsung Kalmia based USB modem
+	  as Samsung GT-B3730.
+
+	  To compile this driver as a module, choose M here: the
+	  module will be called kalmia.
+
 config USB_HSO
 	tristate "Option USB High Speed Mobile Devices"
 	depends on USB && RFKILL
diff --git a/drivers/net/usb/Makefile b/drivers/net/usb/Makefile
index c7ec8a5..c203fa2 100644
--- a/drivers/net/usb/Makefile
+++ b/drivers/net/usb/Makefile
@@ -23,6 +23,7 @@ obj-$(CONFIG_USB_NET_MCS7830)	+= mcs7830.o
 obj-$(CONFIG_USB_USBNET)	+= usbnet.o
 obj-$(CONFIG_USB_NET_INT51X1)	+= int51x1.o
 obj-$(CONFIG_USB_CDC_PHONET)	+= cdc-phonet.o
+obj-$(CONFIG_USB_NET_KALMIA)	+= kalmia.o
 obj-$(CONFIG_USB_IPHETH)	+= ipheth.o
 obj-$(CONFIG_USB_SIERRA_NET)	+= sierra_net.o
 obj-$(CONFIG_USB_NET_CX82310_ETH)	+= cx82310_eth.o
diff --git a/drivers/net/usb/kalmia.c b/drivers/net/usb/kalmia.c
new file mode 100644
index 0000000..d965fb1
--- /dev/null
+++ b/drivers/net/usb/kalmia.c
@@ -0,0 +1,384 @@
+/*
+ * USB network interface driver for Samsung Kalmia based LTE USB modem like the
+ * Samsung GT-B3730 and GT-B3710.
+ *
+ * Copyright (C) 2011 Marius Bjoernstad Kotsbak <marius-iy5w9mehe2BBDgjK7y7TUQ@public.gmane.org>
+ *
+ * Sponsored by Quicklink Video Distribution Services Ltd.
+ *
+ * Based on the cdc_eem module.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ */
+
+#include <linux/module.h>
+#include <linux/init.h>
+#include <linux/netdevice.h>
+#include <linux/etherdevice.h>
+#include <linux/ctype.h>
+#include <linux/ethtool.h>
+#include <linux/workqueue.h>
+#include <linux/mii.h>
+#include <linux/usb.h>
+#include <linux/crc32.h>
+#include <linux/usb/cdc.h>
+#include <linux/usb/usbnet.h>
+#include <linux/gfp.h>
+
+/*
+ * The Samsung Kalmia based LTE USB modems have a CDC ACM port for modem control
+ * handled by the "option" module and an ethernet data port handled by this
+ * module.
+ *
+ * The stick must first be switched into modem mode by usb_modeswitch
+ * or similar tool. Then the modem gets sent two initialization packets by
+ * this module, which gives the MAC address of the device. User space can then
+ * connect the modem using AT commands through the ACM port and then use
+ * DHCP on the network interface exposed by this module. Network packets are
+ * sent to and from the modem in a proprietary format discovered after watching
+ * the behavior of the windows driver for the modem.
+ *
+ * More information about the use of the modem is available in usb_modeswitch
+ * forum and the project page:
+ *
+ * http://www.draisberghof.de/usb_modeswitch/bb/viewtopic.php?t=465
+ * https://github.com/mkotsbak/Samsung-GT-B3730-linux-driver
+ */
+
+/* #define	DEBUG */
+/* #define	VERBOSE */
+
+#define KALMIA_HEADER_LENGTH 6
+#define KALMIA_ALIGN_SIZE 4
+#define KALMIA_USB_TIMEOUT 10000
+
+/*-------------------------------------------------------------------------*/
+
+static int
+kalmia_send_init_packet(struct usbnet *dev, u8 *init_msg, u8 init_msg_len,
+	u8 *buffer, u8 expected_len)
+{
+	int act_len;
+	int status;
+
+	netdev_dbg(dev->net, "Sending init packet");
+
+	status = usb_bulk_msg(dev->udev, usb_sndbulkpipe(dev->udev, 0x02),
+		init_msg, init_msg_len, &act_len, KALMIA_USB_TIMEOUT);
+	if (status != 0) {
+		netdev_err(dev->net,
+			"Error sending init packet. Status %i, length %i\n",
+			status, act_len);
+		return status;
+	}
+	else if (act_len != init_msg_len) {
+		netdev_err(dev->net,
+			"Did not send all of init packet. Bytes sent: %i",
+			act_len);
+	}
+	else {
+		netdev_dbg(dev->net, "Successfully sent init packet.");
+	}
+
+	status = usb_bulk_msg(dev->udev, usb_rcvbulkpipe(dev->udev, 0x81),
+		buffer, expected_len, &act_len, KALMIA_USB_TIMEOUT);
+
+	if (status != 0)
+		netdev_err(dev->net,
+			"Error receiving init result. Status %i, length %i\n",
+			status, act_len);
+	else if (act_len != expected_len)
+		netdev_err(dev->net, "Unexpected init result length: %i\n",
+			act_len);
+
+	return status;
+}
+
+static int
+kalmia_init_and_get_ethernet_addr(struct usbnet *dev, u8 *ethernet_addr)
+{
+	char init_msg_1[] =
+		{ 0x57, 0x50, 0x04, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00,
+		0x00, 0x00 };
+	char init_msg_2[] =
+		{ 0x57, 0x50, 0x04, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0xf4,
+		0x00, 0x00 };
+	char receive_buf[28];
+	int status;
+
+	status = kalmia_send_init_packet(dev, init_msg_1, sizeof(init_msg_1)
+		/ sizeof(init_msg_1[0]), receive_buf, 24);
+	if (status != 0)
+		return status;
+
+	status = kalmia_send_init_packet(dev, init_msg_2, sizeof(init_msg_2)
+		/ sizeof(init_msg_2[0]), receive_buf, 28);
+	if (status != 0)
+		return status;
+
+	memcpy(ethernet_addr, receive_buf + 10, ETH_ALEN);
+
+	return status;
+}
+
+static int
+kalmia_bind(struct usbnet *dev, struct usb_interface *intf)
+{
+	u8 status;
+	u8 ethernet_addr[ETH_ALEN];
+
+	/* Don't bind to AT command interface */
+	if (intf->cur_altsetting->desc.bInterfaceClass != USB_CLASS_VENDOR_SPEC)
+		return -EINVAL;
+
+	dev->in = usb_rcvbulkpipe(dev->udev, 0x81 & USB_ENDPOINT_NUMBER_MASK);
+	dev->out = usb_sndbulkpipe(dev->udev, 0x02 & USB_ENDPOINT_NUMBER_MASK);
+	dev->status = NULL;
+
+	dev->net->hard_header_len += KALMIA_HEADER_LENGTH;
+	dev->hard_mtu = 1400;
+	dev->rx_urb_size = dev->hard_mtu * 10; // Found as optimal after testing
+
+	status = kalmia_init_and_get_ethernet_addr(dev, ethernet_addr);
+
+	if (status < 0) {
+		usb_set_intfdata(intf, NULL);
+		usb_driver_release_interface(driver_of(intf), intf);
+		return status;
+	}
+
+	memcpy(dev->net->dev_addr, ethernet_addr, ETH_ALEN);
+	memcpy(dev->net->perm_addr, ethernet_addr, ETH_ALEN);
+
+	return status;
+}
+
+static struct sk_buff *
+kalmia_tx_fixup(struct usbnet *dev, struct sk_buff *skb, gfp_t flags)
+{
+	struct sk_buff *skb2 = NULL;
+	u16 content_len;
+	unsigned char *header_start;
+	unsigned char ether_type_1, ether_type_2;
+	u8 remainder, padlen = 0;
+
+	if (!skb_cloned(skb)) {
+		int headroom = skb_headroom(skb);
+		int tailroom = skb_tailroom(skb);
+
+		if ((tailroom >= KALMIA_ALIGN_SIZE) && (headroom
+			>= KALMIA_HEADER_LENGTH))
+			goto done;
+
+		if ((headroom + tailroom) > (KALMIA_HEADER_LENGTH
+			+ KALMIA_ALIGN_SIZE)) {
+			skb->data = memmove(skb->head + KALMIA_HEADER_LENGTH,
+				skb->data, skb->len);
+			skb_set_tail_pointer(skb, skb->len);
+			goto done;
+		}
+	}
+
+	skb2 = skb_copy_expand(skb, KALMIA_HEADER_LENGTH,
+		KALMIA_ALIGN_SIZE, flags);
+	if (!skb2)
+		return NULL;
+
+	dev_kfree_skb_any(skb);
+	skb = skb2;
+
+	done: header_start = skb_push(skb, KALMIA_HEADER_LENGTH);
+	ether_type_1 = header_start[KALMIA_HEADER_LENGTH + 12];
+	ether_type_2 = header_start[KALMIA_HEADER_LENGTH + 13];
+
+	netdev_dbg(dev->net, "Sending etherType: %02x%02x", ether_type_1,
+		ether_type_2);
+
+	/* According to empiric data for data packages */
+	header_start[0] = 0x57;
+	header_start[1] = 0x44;
+	content_len = skb->len - KALMIA_HEADER_LENGTH;
+	header_start[2] = (content_len & 0xff); /* low byte */
+	header_start[3] = (content_len >> 8); /* high byte */
+
+	header_start[4] = ether_type_1;
+	header_start[5] = ether_type_2;
+
+	/* Align to 4 bytes by padding with zeros */
+	remainder = skb->len % KALMIA_ALIGN_SIZE;
+	if (remainder > 0) {
+		padlen = KALMIA_ALIGN_SIZE - remainder;
+		memset(skb_put(skb, padlen), 0, padlen);
+	}
+
+	netdev_dbg(
+		dev->net,
+		"Sending package with length %i and padding %i. Header: %02x:%02x:%02x:%02x:%02x:%02x.",
+		content_len, padlen, header_start[0], header_start[1],
+		header_start[2], header_start[3], header_start[4],
+		header_start[5]);
+
+	return skb;
+}
+
+static int
+kalmia_rx_fixup(struct usbnet *dev, struct sk_buff *skb)
+{
+	/*
+	 * Our task here is to strip off framing, leaving skb with one
+	 * data frame for the usbnet framework code to process.
+	 */
+	const u8 HEADER_END_OF_USB_PACKET[] =
+		{ 0x57, 0x5a, 0x00, 0x00, 0x08, 0x00 };
+	const u8 EXPECTED_UNKNOWN_HEADER_1[] =
+		{ 0x57, 0x43, 0x1e, 0x00, 0x15, 0x02 };
+	const u8 EXPECTED_UNKNOWN_HEADER_2[] =
+		{ 0x57, 0x50, 0x0e, 0x00, 0x00, 0x00 };
+	u8 i = 0;
+
+	/* incomplete header? */
+	if (skb->len < KALMIA_HEADER_LENGTH)
+		return 0;
+
+	do {
+		struct sk_buff *skb2 = NULL;
+		u8 *header_start;
+		u16 usb_packet_length, ether_packet_length;
+		int is_last;
+
+		header_start = skb->data;
+
+		if (unlikely(header_start[0] != 0x57 || header_start[1] != 0x44)) {
+			if (!memcmp(header_start, EXPECTED_UNKNOWN_HEADER_1,
+				sizeof(EXPECTED_UNKNOWN_HEADER_1)) || !memcmp(
+				header_start, EXPECTED_UNKNOWN_HEADER_2,
+				sizeof(EXPECTED_UNKNOWN_HEADER_2))) {
+				netdev_dbg(
+					dev->net,
+					"Received expected unknown frame header: %02x:%02x:%02x:%02x:%02x:%02x. Package length: %i\n",
+					header_start[0], header_start[1],
+					header_start[2], header_start[3],
+					header_start[4], header_start[5],
+					skb->len - KALMIA_HEADER_LENGTH);
+			}
+			else {
+				netdev_err(
+					dev->net,
+					"Received unknown frame header: %02x:%02x:%02x:%02x:%02x:%02x. Package length: %i\n",
+					header_start[0], header_start[1],
+					header_start[2], header_start[3],
+					header_start[4], header_start[5],
+					skb->len - KALMIA_HEADER_LENGTH);
+				return 0;
+			}
+		}
+		else
+			netdev_dbg(
+				dev->net,
+				"Received header: %02x:%02x:%02x:%02x:%02x:%02x. Package length: %i\n",
+				header_start[0], header_start[1], header_start[2],
+				header_start[3], header_start[4], header_start[5],
+				skb->len - KALMIA_HEADER_LENGTH);
+
+		/* subtract start header and end header */
+		usb_packet_length = skb->len - (2 * KALMIA_HEADER_LENGTH);
+		ether_packet_length = header_start[2] + (header_start[3] << 8);
+		skb_pull(skb, KALMIA_HEADER_LENGTH);
+
+		/* Some small packets misses end marker */
+		if (usb_packet_length < ether_packet_length) {
+			ether_packet_length = usb_packet_length
+				+ KALMIA_HEADER_LENGTH;
+			is_last = true;
+		}
+		else {
+			netdev_dbg(dev->net, "Correct package length #%i", i
+				+ 1);
+
+			is_last = (memcmp(skb->data + ether_packet_length,
+				HEADER_END_OF_USB_PACKET,
+				sizeof(HEADER_END_OF_USB_PACKET)) == 0);
+			if (!is_last) {
+				header_start = skb->data + ether_packet_length;
+				netdev_dbg(
+					dev->net,
+					"End header: %02x:%02x:%02x:%02x:%02x:%02x. Package length: %i\n",
+					header_start[0], header_start[1],
+					header_start[2], header_start[3],
+					header_start[4], header_start[5],
+					skb->len - KALMIA_HEADER_LENGTH);
+			}
+		}
+
+		if (is_last) {
+			skb2 = skb;
+		}
+		else {
+			skb2 = skb_clone(skb, GFP_ATOMIC);
+			if (unlikely(!skb2))
+				return 0;
+		}
+
+		skb_trim(skb2, ether_packet_length);
+
+		if (is_last) {
+			return 1;
+		}
+		else {
+			usbnet_skb_return(dev, skb2);
+			skb_pull(skb, ether_packet_length);
+		}
+
+		i++;
+	}
+	while (skb->len);
+
+	return 1;
+}
+
+static const struct driver_info kalmia_info = {
+	.description = "Samsung Kalmia LTE USB dongle",
+	.flags = FLAG_WWAN,
+	.bind = kalmia_bind,
+	.rx_fixup = kalmia_rx_fixup,
+	.tx_fixup = kalmia_tx_fixup
+};
+
+/*-------------------------------------------------------------------------*/
+
+static const struct usb_device_id products[] = {
+	/* The unswitched USB ID, to get the module auto loaded: */
+	{ USB_DEVICE(0x04e8, 0x689a) },
+	/* The stick swithed into modem (by e.g. usb_modeswitch): */
+	{ USB_DEVICE(0x04e8, 0x6889),
+		.driver_info = (unsigned long) &kalmia_info, },
+	{ /* EMPTY == end of list */} };
+MODULE_DEVICE_TABLE( usb, products);
+
+static struct usb_driver kalmia_driver = {
+	.name = "kalmia",
+	.id_table = products,
+	.probe = usbnet_probe,
+	.disconnect = usbnet_disconnect,
+	.suspend = usbnet_suspend,
+	.resume = usbnet_resume
+};
+
+static int __init kalmia_init(void)
+{
+	return usb_register(&kalmia_driver);
+}
+module_init( kalmia_init);
+
+static void __exit kalmia_exit(void)
+{
+	usb_deregister(&kalmia_driver);
+}
+module_exit( kalmia_exit);
+
+MODULE_AUTHOR("Marius Bjoernstad Kotsbak <marius-iy5w9mehe2BBDgjK7y7TUQ@public.gmane.org>");
+MODULE_DESCRIPTION("Samsung Kalmia USB network driver");
+MODULE_LICENSE("GPL");
-- 
1.7.4.1

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply related	[flat|nested] 35+ messages in thread

* Re: [PATCH] net/usb: Add Samsung Kalmia driver for Samsung GT-B3730
       [not found]                 ` <20110611.162942.1706711069327005315.davem-fT/PcQaiUtIeIZ0/mPfg9Q@public.gmane.org>
  2011-06-12  3:46                   ` Ben Hutchings
  2011-06-12 12:35                   ` Marius B. Kotsbak
@ 2011-06-12 12:36                   ` Marius Kotsbak
  2 siblings, 0 replies; 35+ messages in thread
From: Marius Kotsbak @ 2011-06-12 12:36 UTC (permalink / raw)
  To: David Miller
  Cc: netdev-u79uwXL29TY76Z2rM5mHXA, linux-usb-u79uwXL29TY76Z2rM5mHXA

On 12. juni 2011 01:29, David Miller wrote:
> From: David Miller <davem-fT/PcQaiUtIeIZ0/mPfg9Q@public.gmane.org>
> Date: Sat, 11 Jun 2011 16:27:11 -0700 (PDT)
>
>> From: "Marius B. Kotsbak" <marius.kotsbak-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
>> Date: Sat, 11 Jun 2011 23:55:18 +0200
>>
>>> Introducing driver for the network port of Samsung Kalmia based USB LTE modems.
>>> It has also an ACM interface that previous patches associates with the "option"
>>> module. To access those interfaces, the modem must first be switched from modem
>>> mode using a tool like usb_modeswitch.
>>>
>>> As the proprietary protocol has been discovered by watching the MS Windows driver
>>> behavior, there might be errors in the protocol handling, but stable and fast
>>> connection has been established for hours with Norwegian operator NetCom that
>>> distributes this modem with their LTE/4G subscription.
>>>
>>> More and updated information about how to use this driver is available here:
>>>
>>> http://www.draisberghof.de/usb_modeswitch/bb/viewtopic.php?t=465
>>> https://github.com/mkotsbak/Samsung-GT-B3730-linux-driver
>>>
>>> Signed-off-by: Marius B. Kotsbak <marius-iy5w9mehe2BBDgjK7y7TUQ@public.gmane.org>
>> Applied, thanks.
> Actually, reverted.
>
> There's a typo in your Makefile patch, and because of this it
> won't even build the new driver.

Oh sorry, I did make on the actual kalmia.ko to avoid building all
modules, so I did not notice. Sending a fixed patch. Ben, thanks for
pointing out.

> People are so damn anxious to get this backported into stable
> and various distributions,

Japp, people keeps asking for a version that compiles with kernel 2.6.32
for the Ubuntu LTS...
>  yet this patch wasn't even tested
> properly.

We were compiling it out of the kernel tree until now.

--
Marius


--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 35+ messages in thread

* Re: [PATCH] net/usb: Add Samsung Kalmia driver for Samsung GT-B3730
       [not found] ` <1307748870-12950-1-git-send-email-marius-iy5w9mehe2BBDgjK7y7TUQ@public.gmane.org>
  2011-06-10 23:55   ` Greg KH
@ 2011-06-13 14:57   ` Dan Williams
       [not found]     ` <1307977039.2117.7.camel-wKZy7rqYPVb5EHUCmHmTqw@public.gmane.org>
  1 sibling, 1 reply; 35+ messages in thread
From: Dan Williams @ 2011-06-13 14:57 UTC (permalink / raw)
  To: Marius B. Kotsbak
  Cc: davem-fT/PcQaiUtIeIZ0/mPfg9Q, netdev-u79uwXL29TY76Z2rM5mHXA,
	linux-usb-u79uwXL29TY76Z2rM5mHXA, Marius B. Kotsbak

On Sat, 2011-06-11 at 01:34 +0200, Marius B. Kotsbak wrote:
> Introducing driver for the network port of Samsung Kalmia based USB LTE modems.
> It has also an ACM interface that previous patches associates with the "option"
> module. To access those interfaces, the modem must first be switched from modem
> mode using a tool like usb_modeswitch.
> 
> As the proprietary protocol has been discovered by watching the MS Windows driver
> behavior, there might be errors in the protocol handling, but stable and fast
> connection has been established for hours with Norwegian operator NetCom that
> distributes this modem with their LTE/4G subscription.

Why make the driver bind to both the switched and unswitched USB IDs?
Shouldn't the kernel bind the driver after switch when the device
reconnects with the new IDs?

Dan

> More and updated information about how to use this driver is available here:
> 
> http://www.draisberghof.de/usb_modeswitch/bb/viewtopic.php?t=465
> https://github.com/mkotsbak/Samsung-GT-B3730-linux-driver
> 
> Signed-off-by: Marius B. Kotsbak <marius-iy5w9mehe2BBDgjK7y7TUQ@public.gmane.org>
> ---
>  drivers/net/usb/Kconfig  |   10 ++
>  drivers/net/usb/Makefile |    2 +-
>  drivers/net/usb/kalmia.c |  393 ++++++++++++++++++++++++++++++++++++++++++++++
>  3 files changed, 404 insertions(+), 1 deletions(-)
>  create mode 100644 drivers/net/usb/kalmia.c
> 
> diff --git a/drivers/net/usb/Kconfig b/drivers/net/usb/Kconfig
> index 9d4f911..b6e4efc 100644
> --- a/drivers/net/usb/Kconfig
> +++ b/drivers/net/usb/Kconfig
> @@ -385,6 +385,16 @@ config USB_NET_CX82310_ETH
>  	  router with USB ethernet port. This driver is for routers only,
>  	  it will not work with ADSL modems (use cxacru driver instead).
>  
> +config CONFIG_USB_NET_KALMIA
> +	tristate "Samsung Kalmia based LTE USB modem"
> +	depends on USB_USBNET
> +	help
> +	  Choose this option if you have a Samsung Kalmia based USB modem
> +	  as Samsung GT-B3730.
> +
> +	  To compile this driver as a module, choose M here: the
> +	  module will be called kalmia.
> +
>  config USB_HSO
>  	tristate "Option USB High Speed Mobile Devices"
>  	depends on USB && RFKILL
> diff --git a/drivers/net/usb/Makefile b/drivers/net/usb/Makefile
> index c7ec8a5..6091249 100644
> --- a/drivers/net/usb/Makefile
> +++ b/drivers/net/usb/Makefile
> @@ -28,4 +28,4 @@ obj-$(CONFIG_USB_SIERRA_NET)	+= sierra_net.o
>  obj-$(CONFIG_USB_NET_CX82310_ETH)	+= cx82310_eth.o
>  obj-$(CONFIG_USB_NET_CDC_NCM)	+= cdc_ncm.o
>  obj-$(CONFIG_USB_VL600)		+= lg-vl600.o
> -
> +obj-$(CONFIG_USB_NET_KALMIA)	+= kalmia.o
> diff --git a/drivers/net/usb/kalmia.c b/drivers/net/usb/kalmia.c
> new file mode 100644
> index 0000000..d1e80e0
> --- /dev/null
> +++ b/drivers/net/usb/kalmia.c
> @@ -0,0 +1,393 @@
> +/*
> + * USB network interface driver for Samsung Kalmia based LTE USB modem like the
> + * Samsung GT-B3730 and GT-B3710.
> + *
> + * Copyright (C) 2011 Marius Bjoernstad Kotsbak
> + *
> + * Sponsored by Quicklink Video Distribution Services Ltd.
> + *
> + * Based on the cdc_eem module.
> + *
> + * This program is free software; you can redistribute it and/or modify
> + * it under the terms of the GNU General Public License as published by
> + * the Free Software Foundation; either version 2 of the License, or
> + * (at your option) any later version.
> + *
> + * 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.
> + *
> + * You should have received a copy of the GNU General Public License
> + * along with this program; if not, write to the Free Software
> + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
> + */
> +
> +#include <linux/module.h>
> +#include <linux/init.h>
> +#include <linux/netdevice.h>
> +#include <linux/etherdevice.h>
> +#include <linux/ctype.h>
> +#include <linux/ethtool.h>
> +#include <linux/workqueue.h>
> +#include <linux/mii.h>
> +#include <linux/usb.h>
> +#include <linux/crc32.h>
> +#include <linux/usb/cdc.h>
> +#include <linux/usb/usbnet.h>
> +#include <linux/gfp.h>
> +
> +/*
> + * The Samsung Kalmia based LTE USB modems have a CDC ACM port for modem control
> + * handled by the "option" module and an ethernet data port handled by this
> + * module.
> + *
> + * The stick must first be switched into modem mode by usb_modeswitch
> + * or similar tool. Then the modem gets sent two initialization packets by
> + * this module, which gives the MAC address of the device. User space can then
> + * connect the modem using AT commands through the ACM port and then use
> + * DHCP on the network interface exposed by this module. Network packets are
> + * sent to and from the modem in a proprietary format discovered after watching
> + * the behavior of the windows driver for the modem.
> + *
> + * More information about the use of the modem is available in usb_modeswitch
> + * forum and the project page:
> + *
> + * http://www.draisberghof.de/usb_modeswitch/bb/viewtopic.php?t=465
> + * https://github.com/mkotsbak/Samsung-GT-B3730-linux-driver
> + */
> +
> +/* #define	DEBUG */
> +/* #define	VERBOSE */
> +
> +#define KALMIA_HEADER_LENGTH 6
> +#define KALMIA_ALIGN_SIZE 4
> +#define KALMIA_USB_TIMEOUT 10000
> +
> +/*-------------------------------------------------------------------------*/
> +
> +static int
> +kalmia_send_init_packet(struct usbnet *dev, u8 *init_msg, u8 init_msg_len,
> +	u8 *buffer, u8 expected_len)
> +{
> +	int act_len;
> +	int status;
> +
> +	netdev_dbg(dev->net, "Sending init packet");
> +
> +	status = usb_bulk_msg(dev->udev, usb_sndbulkpipe(dev->udev, 0x02),
> +		init_msg, init_msg_len, &act_len, KALMIA_USB_TIMEOUT);
> +	if (status != 0) {
> +		netdev_err(dev->net,
> +			"Error sending init packet. Status %i, length %i\n",
> +			status, act_len);
> +		return status;
> +	}
> +	else if (act_len != init_msg_len) {
> +		netdev_err(dev->net,
> +			"Did not send all of init packet. Bytes sent: %i",
> +			act_len);
> +	}
> +	else {
> +		netdev_dbg(dev->net, "Successfully sent init packet.");
> +	}
> +
> +	status = usb_bulk_msg(dev->udev, usb_rcvbulkpipe(dev->udev, 0x81),
> +		buffer, expected_len, &act_len, KALMIA_USB_TIMEOUT);
> +
> +	if (status != 0)
> +		netdev_err(dev->net,
> +			"Error receiving init result. Status %i, length %i\n",
> +			status, act_len);
> +	else if (act_len != expected_len)
> +		netdev_err(dev->net, "Unexpected init result length: %i\n",
> +			act_len);
> +
> +	return status;
> +}
> +
> +static int
> +kalmia_init_and_get_ethernet_addr(struct usbnet *dev, u8 *ethernet_addr)
> +{
> +	char init_msg_1[] =
> +		{ 0x57, 0x50, 0x04, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00,
> +		0x00, 0x00 };
> +	char init_msg_2[] =
> +		{ 0x57, 0x50, 0x04, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0xf4,
> +		0x00, 0x00 };
> +	char receive_buf[28];
> +	int status;
> +
> +	status = kalmia_send_init_packet(dev, init_msg_1, sizeof(init_msg_1)
> +		/ sizeof(init_msg_1[0]), receive_buf, 24);
> +	if (status != 0)
> +		return status;
> +
> +	status = kalmia_send_init_packet(dev, init_msg_2, sizeof(init_msg_2)
> +		/ sizeof(init_msg_2[0]), receive_buf, 28);
> +	if (status != 0)
> +		return status;
> +
> +	memcpy(ethernet_addr, receive_buf + 10, ETH_ALEN);
> +
> +	return status;
> +}
> +
> +static int
> +kalmia_bind(struct usbnet *dev, struct usb_interface *intf)
> +{
> +	u8 status;
> +	u8 ethernet_addr[ETH_ALEN];
> +
> +	/* Don't bind to AT command interface */
> +	if (intf->cur_altsetting->desc.bInterfaceClass != USB_CLASS_VENDOR_SPEC)
> +		return -EINVAL;
> +
> +	dev->in = usb_rcvbulkpipe(dev->udev, 0x81 & USB_ENDPOINT_NUMBER_MASK);
> +	dev->out = usb_sndbulkpipe(dev->udev, 0x02 & USB_ENDPOINT_NUMBER_MASK);
> +	dev->status = NULL;
> +
> +	dev->net->hard_header_len += KALMIA_HEADER_LENGTH;
> +	dev->hard_mtu = 1400;
> +	dev->rx_urb_size = dev->hard_mtu * 10; // Found as optimal after testing
> +
> +	status = kalmia_init_and_get_ethernet_addr(dev, ethernet_addr);
> +
> +	if (status < 0) {
> +		usb_set_intfdata(intf, NULL);
> +		usb_driver_release_interface(driver_of(intf), intf);
> +		return status;
> +	}
> +
> +	memcpy(dev->net->dev_addr, ethernet_addr, ETH_ALEN);
> +	memcpy(dev->net->perm_addr, ethernet_addr, ETH_ALEN);
> +
> +	return status;
> +}
> +
> +static struct sk_buff *
> +kalmia_tx_fixup(struct usbnet *dev, struct sk_buff *skb, gfp_t flags)
> +{
> +	struct sk_buff *skb2 = NULL;
> +	u16 content_len;
> +	unsigned char *header_start;
> +	unsigned char ether_type_1, ether_type_2;
> +	u8 remainder, padlen = 0;
> +
> +	if (!skb_cloned(skb)) {
> +		int headroom = skb_headroom(skb);
> +		int tailroom = skb_tailroom(skb);
> +
> +		if ((tailroom >= KALMIA_ALIGN_SIZE) && (headroom
> +			>= KALMIA_HEADER_LENGTH))
> +			goto done;
> +
> +		if ((headroom + tailroom) > (KALMIA_HEADER_LENGTH
> +			+ KALMIA_ALIGN_SIZE)) {
> +			skb->data = memmove(skb->head + KALMIA_HEADER_LENGTH,
> +				skb->data, skb->len);
> +			skb_set_tail_pointer(skb, skb->len);
> +			goto done;
> +		}
> +	}
> +
> +	skb2 = skb_copy_expand(skb, KALMIA_HEADER_LENGTH,
> +		KALMIA_ALIGN_SIZE, flags);
> +	if (!skb2)
> +		return NULL;
> +
> +	dev_kfree_skb_any(skb);
> +	skb = skb2;
> +
> +	done: header_start = skb_push(skb, KALMIA_HEADER_LENGTH);
> +	ether_type_1 = header_start[KALMIA_HEADER_LENGTH + 12];
> +	ether_type_2 = header_start[KALMIA_HEADER_LENGTH + 13];
> +
> +	netdev_dbg(dev->net, "Sending etherType: %02x%02x", ether_type_1,
> +		ether_type_2);
> +
> +	/* According to empiric data for data packages */
> +	header_start[0] = 0x57;
> +	header_start[1] = 0x44;
> +	content_len = skb->len - KALMIA_HEADER_LENGTH;
> +	header_start[2] = (content_len & 0xff); /* low byte */
> +	header_start[3] = (content_len >> 8); /* high byte */
> +
> +	header_start[4] = ether_type_1;
> +	header_start[5] = ether_type_2;
> +
> +	/* Align to 4 bytes by padding with zeros */
> +	remainder = skb->len % KALMIA_ALIGN_SIZE;
> +	if (remainder > 0) {
> +		padlen = KALMIA_ALIGN_SIZE - remainder;
> +		memset(skb_put(skb, padlen), 0, padlen);
> +	}
> +
> +	netdev_dbg(
> +		dev->net,
> +		"Sending package with length %i and padding %i. Header: %02x:%02x:%02x:%02x:%02x:%02x.",
> +		content_len, padlen, header_start[0], header_start[1],
> +		header_start[2], header_start[3], header_start[4],
> +		header_start[5]);
> +
> +	return skb;
> +}
> +
> +static int
> +kalmia_rx_fixup(struct usbnet *dev, struct sk_buff *skb)
> +{
> +	/*
> +	 * Our task here is to strip off framing, leaving skb with one
> +	 * data frame for the usbnet framework code to process.
> +	 */
> +	const u8 HEADER_END_OF_USB_PACKET[] =
> +		{ 0x57, 0x5a, 0x00, 0x00, 0x08, 0x00 };
> +	const u8 EXPECTED_UNKNOWN_HEADER_1[] =
> +		{ 0x57, 0x43, 0x1e, 0x00, 0x15, 0x02 };
> +	const u8 EXPECTED_UNKNOWN_HEADER_2[] =
> +		{ 0x57, 0x50, 0x0e, 0x00, 0x00, 0x00 };
> +	u8 i = 0;
> +
> +	/* incomplete header? */
> +	if (skb->len < KALMIA_HEADER_LENGTH)
> +		return 0;
> +
> +	do {
> +		struct sk_buff *skb2 = NULL;
> +		u8 *header_start;
> +		u16 usb_packet_length, ether_packet_length;
> +		int is_last;
> +
> +		header_start = skb->data;
> +
> +		if (unlikely(header_start[0] != 0x57 || header_start[1] != 0x44)) {
> +			if (!memcmp(header_start, EXPECTED_UNKNOWN_HEADER_1,
> +				sizeof(EXPECTED_UNKNOWN_HEADER_1)) || !memcmp(
> +				header_start, EXPECTED_UNKNOWN_HEADER_2,
> +				sizeof(EXPECTED_UNKNOWN_HEADER_2))) {
> +				netdev_dbg(
> +					dev->net,
> +					"Received expected unknown frame header: %02x:%02x:%02x:%02x:%02x:%02x. Package length: %i\n",
> +					header_start[0], header_start[1],
> +					header_start[2], header_start[3],
> +					header_start[4], header_start[5],
> +					skb->len - KALMIA_HEADER_LENGTH);
> +			}
> +			else {
> +				netdev_err(
> +					dev->net,
> +					"Received unknown frame header: %02x:%02x:%02x:%02x:%02x:%02x. Package length: %i\n",
> +					header_start[0], header_start[1],
> +					header_start[2], header_start[3],
> +					header_start[4], header_start[5],
> +					skb->len - KALMIA_HEADER_LENGTH);
> +				return 0;
> +			}
> +		}
> +		else
> +			netdev_dbg(
> +				dev->net,
> +				"Received header: %02x:%02x:%02x:%02x:%02x:%02x. Package length: %i\n",
> +				header_start[0], header_start[1], header_start[2],
> +				header_start[3], header_start[4], header_start[5],
> +				skb->len - KALMIA_HEADER_LENGTH);
> +
> +		/* subtract start header and end header */
> +		usb_packet_length = skb->len - (2 * KALMIA_HEADER_LENGTH);
> +		ether_packet_length = header_start[2] + (header_start[3] << 8);
> +		skb_pull(skb, KALMIA_HEADER_LENGTH);
> +
> +		/* Some small packets misses end marker */
> +		if (usb_packet_length < ether_packet_length) {
> +			ether_packet_length = usb_packet_length
> +				+ KALMIA_HEADER_LENGTH;
> +			is_last = true;
> +		}
> +		else {
> +			netdev_dbg(dev->net, "Correct package length #%i", i
> +				+ 1);
> +
> +			is_last = (memcmp(skb->data + ether_packet_length,
> +				HEADER_END_OF_USB_PACKET,
> +				sizeof(HEADER_END_OF_USB_PACKET)) == 0);
> +			if (!is_last) {
> +				header_start = skb->data + ether_packet_length;
> +				netdev_dbg(
> +					dev->net,
> +					"End header: %02x:%02x:%02x:%02x:%02x:%02x. Package length: %i\n",
> +					header_start[0], header_start[1],
> +					header_start[2], header_start[3],
> +					header_start[4], header_start[5],
> +					skb->len - KALMIA_HEADER_LENGTH);
> +			}
> +		}
> +
> +		if (is_last) {
> +			skb2 = skb;
> +		}
> +		else {
> +			skb2 = skb_clone(skb, GFP_ATOMIC);
> +			if (unlikely(!skb2))
> +				return 0;
> +		}
> +
> +		skb_trim(skb2, ether_packet_length);
> +
> +		if (is_last) {
> +			return 1;
> +		}
> +		else {
> +			usbnet_skb_return(dev, skb2);
> +			skb_pull(skb, ether_packet_length);
> +		}
> +
> +		i++;
> +	}
> +	while (skb->len);
> +
> +	return 1;
> +}
> +
> +static const struct driver_info kalmia_info = {
> +	.description = "Samsung Kalmia LTE USB dongle",
> +	.flags = FLAG_WWAN,
> +	.bind = kalmia_bind,
> +	.rx_fixup = kalmia_rx_fixup,
> +	.tx_fixup = kalmia_tx_fixup
> +};
> +
> +/*-------------------------------------------------------------------------*/
> +
> +static const struct usb_device_id products[] = {
> +	/* The unswitched USB ID, to get the module auto loaded: */
> +	{ USB_DEVICE(0x04e8, 0x689a) },
> +	/* The stick swithed into modem (by e.g. usb_modeswitch): */
> +	{ USB_DEVICE(0x04e8, 0x6889),
> +		.driver_info = (unsigned long) &kalmia_info, },
> +	{ /* EMPTY == end of list */} };
> +MODULE_DEVICE_TABLE( usb, products);
> +
> +static struct usb_driver kalmia_driver = {
> +	.name = "kalmia",
> +	.id_table = products,
> +	.probe = usbnet_probe,
> +	.disconnect = usbnet_disconnect,
> +	.suspend = usbnet_suspend,
> +	.resume = usbnet_resume
> +};
> +
> +static int __init kalmia_init(void)
> +{
> +	return usb_register(&kalmia_driver);
> +}
> +module_init( kalmia_init);
> +
> +static void __exit kalmia_exit(void)
> +{
> +	usb_deregister(&kalmia_driver);
> +}
> +module_exit( kalmia_exit);
> +
> +MODULE_AUTHOR("Marius Bjoernstad Kotsbak <marius-iy5w9mehe2BBDgjK7y7TUQ@public.gmane.org>");
> +MODULE_DESCRIPTION("Samsung Kalmia USB network driver");
> +MODULE_LICENSE("GPL");


--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 35+ messages in thread

* Re: [PATCH] net/usb: Add Samsung Kalmia driver for Samsung GT-B3730
       [not found]     ` <1307977039.2117.7.camel-wKZy7rqYPVb5EHUCmHmTqw@public.gmane.org>
@ 2011-06-13 15:01       ` Marius Kotsbak
       [not found]         ` <4DF62656.8060506-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
  0 siblings, 1 reply; 35+ messages in thread
From: Marius Kotsbak @ 2011-06-13 15:01 UTC (permalink / raw)
  To: Dan Williams
  Cc: davem-fT/PcQaiUtIeIZ0/mPfg9Q, netdev-u79uwXL29TY76Z2rM5mHXA,
	linux-usb-u79uwXL29TY76Z2rM5mHXA, Marius B. Kotsbak

On 13. juni 2011 16:57, Dan Williams wrote:
> On Sat, 2011-06-11 at 01:34 +0200, Marius B. Kotsbak wrote:
>> Introducing driver for the network port of Samsung Kalmia based USB LTE modems.
>> It has also an ACM interface that previous patches associates with the "option"
>> module. To access those interfaces, the modem must first be switched from modem
>> mode using a tool like usb_modeswitch.
>>
>> As the proprietary protocol has been discovered by watching the MS Windows driver
>> behavior, there might be errors in the protocol handling, but stable and fast
>> connection has been established for hours with Norwegian operator NetCom that
>> distributes this modem with their LTE/4G subscription.
> Why make the driver bind to both the switched and unswitched USB IDs?
> Shouldn't the kernel bind the driver after switch when the device
> reconnects with the new IDs?

No, I tried and it did not happen, so I assumed that the kernel modules
are only loaded at USB insertion event, not when the interfaces changes.
Does anyone here know if my observation is right?

Usb_modeswitch autoloads "option" module after switching, but not my
kalmia module.

--
Marius


--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 35+ messages in thread

* Re: [PATCH] net/usb: Add Samsung Kalmia driver for Samsung GT-B3730
       [not found]         ` <4DF62656.8060506-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
@ 2011-06-13 15:19           ` Dan Williams
       [not found]             ` <1307978364.2117.11.camel-wKZy7rqYPVb5EHUCmHmTqw@public.gmane.org>
  0 siblings, 1 reply; 35+ messages in thread
From: Dan Williams @ 2011-06-13 15:19 UTC (permalink / raw)
  To: Marius Kotsbak
  Cc: davem-fT/PcQaiUtIeIZ0/mPfg9Q, netdev-u79uwXL29TY76Z2rM5mHXA,
	linux-usb-u79uwXL29TY76Z2rM5mHXA, Marius B. Kotsbak

On Mon, 2011-06-13 at 17:01 +0200, Marius Kotsbak wrote:
> On 13. juni 2011 16:57, Dan Williams wrote:
> > On Sat, 2011-06-11 at 01:34 +0200, Marius B. Kotsbak wrote:
> >> Introducing driver for the network port of Samsung Kalmia based USB LTE modems.
> >> It has also an ACM interface that previous patches associates with the "option"
> >> module. To access those interfaces, the modem must first be switched from modem
> >> mode using a tool like usb_modeswitch.
> >>
> >> As the proprietary protocol has been discovered by watching the MS Windows driver
> >> behavior, there might be errors in the protocol handling, but stable and fast
> >> connection has been established for hours with Norwegian operator NetCom that
> >> distributes this modem with their LTE/4G subscription.
> > Why make the driver bind to both the switched and unswitched USB IDs?
> > Shouldn't the kernel bind the driver after switch when the device
> > reconnects with the new IDs?
> 
> No, I tried and it did not happen, so I assumed that the kernel modules
> are only loaded at USB insertion event, not when the interfaces changes.
> Does anyone here know if my observation is right?
> 
> Usb_modeswitch autoloads "option" module after switching, but not my
> kalmia module.

Try killing the modeswitch autoload thing first by moving the udev
script out of the way.  Then plug your device in, and run
"usb-modeswitch -c /path/to/config" so that the usb_modeswitch autoload
thing doesn't run.  Does that work?  I don't want to slander
usb_modeswitch but I've seen some odd behavior which I suspect is it's
module force-loading feature, though I haven't investigated too much
yet.  But ruling that out could be helpful.

Dan


--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 35+ messages in thread

* Re: [PATCH] net/usb: Add Samsung Kalmia driver for Samsung GT-B3730
       [not found]             ` <1307829318-18246-1-git-send-email-marius-iy5w9mehe2BBDgjK7y7TUQ@public.gmane.org>
@ 2011-06-14  8:49               ` Oliver Neukum
       [not found]                 ` <201106141049.39150.oneukum-l3A5Bk7waGM@public.gmane.org>
  0 siblings, 1 reply; 35+ messages in thread
From: Oliver Neukum @ 2011-06-14  8:49 UTC (permalink / raw)
  To: Marius B. Kotsbak
  Cc: davem-fT/PcQaiUtIeIZ0/mPfg9Q, netdev-u79uwXL29TY76Z2rM5mHXA,
	linux-usb-u79uwXL29TY76Z2rM5mHXA, Marius B. Kotsbak

Am Samstag, 11. Juni 2011, 23:55:18 schrieb Marius B. Kotsbak:

Hi,

thanks for writing a new driver. My comments are included in the quote.

	Regards
		Oliver

> +static int
> +kalmia_init_and_get_ethernet_addr(struct usbnet *dev, u8 *ethernet_addr)
> +{
> +	char init_msg_1[] =
> +		{ 0x57, 0x50, 0x04, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00,
> +		0x00, 0x00 };
> +	char init_msg_2[] =
> +		{ 0x57, 0x50, 0x04, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0xf4,
> +		0x00, 0x00 };
> +	char receive_buf[28];

You are doing DMA on the stack. This will fail on some architectures.

> +	int status;
> +
> +	status = kalmia_send_init_packet(dev, init_msg_1, sizeof(init_msg_1)
> +		/ sizeof(init_msg_1[0]), receive_buf, 24);
> +	if (status != 0)
> +		return status;
> +
> +	status = kalmia_send_init_packet(dev, init_msg_2, sizeof(init_msg_2)
> +		/ sizeof(init_msg_2[0]), receive_buf, 28);
> +	if (status != 0)
> +		return status;
> +
> +	memcpy(ethernet_addr, receive_buf + 10, ETH_ALEN);
> +
> +	return status;
> +}
> +
> +static int
> +kalmia_bind(struct usbnet *dev, struct usb_interface *intf)
> +{
> +	u8 status;
> +	u8 ethernet_addr[ETH_ALEN];
> +
> +	/* Don't bind to AT command interface */
> +	if (intf->cur_altsetting->desc.bInterfaceClass != USB_CLASS_VENDOR_SPEC)
> +		return -EINVAL;
> +
> +	dev->in = usb_rcvbulkpipe(dev->udev, 0x81 & USB_ENDPOINT_NUMBER_MASK);
> +	dev->out = usb_sndbulkpipe(dev->udev, 0x02 & USB_ENDPOINT_NUMBER_MASK);
> +	dev->status = NULL;
> +
> +	dev->net->hard_header_len += KALMIA_HEADER_LENGTH;
> +	dev->hard_mtu = 1400;
> +	dev->rx_urb_size = dev->hard_mtu * 10; // Found as optimal after testing
> +
> +	status = kalmia_init_and_get_ethernet_addr(dev, ethernet_addr);
> +
> +	if (status < 0) {
> +		usb_set_intfdata(intf, NULL);
> +		usb_driver_release_interface(driver_of(intf), intf);
> +		return status;

Why are you doing this? What is to be undone?

> +	}
> +
> +	memcpy(dev->net->dev_addr, ethernet_addr, ETH_ALEN);
> +	memcpy(dev->net->perm_addr, ethernet_addr, ETH_ALEN);
> +
> +	return status;
> +}
> +
> +static struct sk_buff *
> +kalmia_tx_fixup(struct usbnet *dev, struct sk_buff *skb, gfp_t flags)
> +{
> +	struct sk_buff *skb2 = NULL;
> +	u16 content_len;
> +	unsigned char *header_start;
> +	unsigned char ether_type_1, ether_type_2;
> +	u8 remainder, padlen = 0;
> +
> +	if (!skb_cloned(skb)) {
> +		int headroom = skb_headroom(skb);
> +		int tailroom = skb_tailroom(skb);
> +
> +		if ((tailroom >= KALMIA_ALIGN_SIZE) && (headroom
> +			>= KALMIA_HEADER_LENGTH))
> +			goto done;
> +
> +		if ((headroom + tailroom) > (KALMIA_HEADER_LENGTH
> +			+ KALMIA_ALIGN_SIZE)) {
> +			skb->data = memmove(skb->head + KALMIA_HEADER_LENGTH,
> +				skb->data, skb->len);
> +			skb_set_tail_pointer(skb, skb->len);
> +			goto done;
> +		}
> +	}
> +
> +	skb2 = skb_copy_expand(skb, KALMIA_HEADER_LENGTH,
> +		KALMIA_ALIGN_SIZE, flags);
> +	if (!skb2)
> +		return NULL;
> +
> +	dev_kfree_skb_any(skb);
> +	skb = skb2;
> +
> +	done: header_start = skb_push(skb, KALMIA_HEADER_LENGTH);

coding style

> +	ether_type_1 = header_start[KALMIA_HEADER_LENGTH + 12];
> +	ether_type_2 = header_start[KALMIA_HEADER_LENGTH + 13];
> +
> +	netdev_dbg(dev->net, "Sending etherType: %02x%02x", ether_type_1,
> +		ether_type_2);
> +
> +	/* According to empiric data for data packages */
> +	header_start[0] = 0x57;
> +	header_start[1] = 0x44;
> +	content_len = skb->len - KALMIA_HEADER_LENGTH;
> +	header_start[2] = (content_len & 0xff); /* low byte */
> +	header_start[3] = (content_len >> 8); /* high byte */

Please use an endianness macro

> +	header_start[4] = ether_type_1;
> +	header_start[5] = ether_type_2;
> +
> +	/* Align to 4 bytes by padding with zeros */
> +	remainder = skb->len % KALMIA_ALIGN_SIZE;
> +	if (remainder > 0) {
> +		padlen = KALMIA_ALIGN_SIZE - remainder;
> +		memset(skb_put(skb, padlen), 0, padlen);
> +	}
> +
> +	netdev_dbg(
> +		dev->net,
> +		"Sending package with length %i and padding %i. Header: %02x:%02x:%02x:%02x:%02x:%02x.",
> +		content_len, padlen, header_start[0], header_start[1],
> +		header_start[2], header_start[3], header_start[4],
> +		header_start[5]);
> +
> +	return skb;
> +}
> +
> +static int
> +kalmia_rx_fixup(struct usbnet *dev, struct sk_buff *skb)
> +{
> +	/*
> +	 * Our task here is to strip off framing, leaving skb with one
> +	 * data frame for the usbnet framework code to process.
> +	 */
> +	const u8 HEADER_END_OF_USB_PACKET[] =
> +		{ 0x57, 0x5a, 0x00, 0x00, 0x08, 0x00 };
> +	const u8 EXPECTED_UNKNOWN_HEADER_1[] =
> +		{ 0x57, 0x43, 0x1e, 0x00, 0x15, 0x02 };
> +	const u8 EXPECTED_UNKNOWN_HEADER_2[] =
> +		{ 0x57, 0x50, 0x0e, 0x00, 0x00, 0x00 };

What does the compiler do to this declaration?

> +	u8 i = 0;

Why not int?

> +
> +	/* incomplete header? */
> +	if (skb->len < KALMIA_HEADER_LENGTH)
> +		return 0;
> +
> +	do {
> +		struct sk_buff *skb2 = NULL;
> +		u8 *header_start;
> +		u16 usb_packet_length, ether_packet_length;
> +		int is_last;
> +
> +		header_start = skb->data;
> +
> +		if (unlikely(header_start[0] != 0x57 || header_start[1] != 0x44)) {
> +			if (!memcmp(header_start, EXPECTED_UNKNOWN_HEADER_1,
> +				sizeof(EXPECTED_UNKNOWN_HEADER_1)) || !memcmp(
> +				header_start, EXPECTED_UNKNOWN_HEADER_2,
> +				sizeof(EXPECTED_UNKNOWN_HEADER_2))) {
> +				netdev_dbg(
> +					dev->net,
> +					"Received expected unknown frame header: %02x:%02x:%02x:%02x:%02x:%02x. Package length: %i\n",
> +					header_start[0], header_start[1],
> +					header_start[2], header_start[3],
> +					header_start[4], header_start[5],
> +					skb->len - KALMIA_HEADER_LENGTH);
> +			}
> +			else {
> +				netdev_err(
> +					dev->net,
> +					"Received unknown frame header: %02x:%02x:%02x:%02x:%02x:%02x. Package length: %i\n",
> +					header_start[0], header_start[1],
> +					header_start[2], header_start[3],
> +					header_start[4], header_start[5],
> +					skb->len - KALMIA_HEADER_LENGTH);
> +				return 0;
> +			}
> +		}
> +		else
> +			netdev_dbg(
> +				dev->net,
> +				"Received header: %02x:%02x:%02x:%02x:%02x:%02x. Package length: %i\n",
> +				header_start[0], header_start[1], header_start[2],
> +				header_start[3], header_start[4], header_start[5],
> +				skb->len - KALMIA_HEADER_LENGTH);
> +
> +		/* subtract start header and end header */
> +		usb_packet_length = skb->len - (2 * KALMIA_HEADER_LENGTH);
> +		ether_packet_length = header_start[2] + (header_start[3] << 8);

Please use an endianness macro

> +		skb_pull(skb, KALMIA_HEADER_LENGTH);
> +
> +		/* Some small packets misses end marker */
> +		if (usb_packet_length < ether_packet_length) {
> +			ether_packet_length = usb_packet_length
> +				+ KALMIA_HEADER_LENGTH;
> +			is_last = true;
> +		}
> +		else {
> +			netdev_dbg(dev->net, "Correct package length #%i", i
> +				+ 1);
> +
> +			is_last = (memcmp(skb->data + ether_packet_length,
> +				HEADER_END_OF_USB_PACKET,
> +				sizeof(HEADER_END_OF_USB_PACKET)) == 0);
> +			if (!is_last) {
> +				header_start = skb->data + ether_packet_length;
> +				netdev_dbg(
> +					dev->net,
> +					"End header: %02x:%02x:%02x:%02x:%02x:%02x. Package length: %i\n",
> +					header_start[0], header_start[1],
> +					header_start[2], header_start[3],
> +					header_start[4], header_start[5],
> +					skb->len - KALMIA_HEADER_LENGTH);
> +			}
> +		}
> +
> +		if (is_last) {
> +			skb2 = skb;
> +		}
> +		else {
> +			skb2 = skb_clone(skb, GFP_ATOMIC);
> +			if (unlikely(!skb2))
> +				return 0;
> +		}
> +
> +		skb_trim(skb2, ether_packet_length);
> +
> +		if (is_last) {
> +			return 1;
> +		}
> +		else {
> +			usbnet_skb_return(dev, skb2);
> +			skb_pull(skb, ether_packet_length);
> +		}
> +
> +		i++;
> +	}
> +	while (skb->len);
> +
> +	return 1;
> +}
> +
> +static const struct driver_info kalmia_info = {
> +	.description = "Samsung Kalmia LTE USB dongle",
> +	.flags = FLAG_WWAN,
> +	.bind = kalmia_bind,
> +	.rx_fixup = kalmia_rx_fixup,
> +	.tx_fixup = kalmia_tx_fixup
> +};
> +
> +/*-------------------------------------------------------------------------*/
> +
> +static const struct usb_device_id products[] = {
> +	/* The unswitched USB ID, to get the module auto loaded: */
> +	{ USB_DEVICE(0x04e8, 0x689a) },

Why is this needed? Doesn't the switch trigger an autoload?

> +	/* The stick swithed into modem (by e.g. usb_modeswitch): */
> +	{ USB_DEVICE(0x04e8, 0x6889),
> +		.driver_info = (unsigned long) &kalmia_info, },
> +	{ /* EMPTY == end of list */} };
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 35+ messages in thread

* Re: [PATCH] net/usb: Add Samsung Kalmia driver for Samsung GT-B3730
       [not found]                 ` <201106141049.39150.oneukum-l3A5Bk7waGM@public.gmane.org>
@ 2011-06-14  9:32                   ` Marius Kotsbak
       [not found]                     ` <4DF72A90.1070702-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
  0 siblings, 1 reply; 35+ messages in thread
From: Marius Kotsbak @ 2011-06-14  9:32 UTC (permalink / raw)
  To: Oliver Neukum
  Cc: davem-fT/PcQaiUtIeIZ0/mPfg9Q, netdev-u79uwXL29TY76Z2rM5mHXA,
	linux-usb-u79uwXL29TY76Z2rM5mHXA, Marius B. Kotsbak

Den 14. juni 2011 10:49, skrev Oliver Neukum:
> Am Samstag, 11. Juni 2011, 23:55:18 schrieb Marius B. Kotsbak:
>
>> +static int
>> +kalmia_init_and_get_ethernet_addr(struct usbnet *dev, u8 *ethernet_addr)
>> +{
>> +	char init_msg_1[] =
>> +		{ 0x57, 0x50, 0x04, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00,
>> +		0x00, 0x00 };
>> +	char init_msg_2[] =
>> +		{ 0x57, 0x50, 0x04, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0xf4,
>> +		0x00, 0x00 };
>> +	char receive_buf[28];
> You are doing DMA on the stack. This will fail on some architectures.
>

Okay, a bit strange that this API is available then. Which API functions 
should be used in this case?

>> +	int status;
>> +
>> +	status = kalmia_send_init_packet(dev, init_msg_1, sizeof(init_msg_1)
>> +		/ sizeof(init_msg_1[0]), receive_buf, 24);
>> +	if (status != 0)
>> +		return status;
>> +
>> +	status = kalmia_send_init_packet(dev, init_msg_2, sizeof(init_msg_2)
>> +		/ sizeof(init_msg_2[0]), receive_buf, 28);
>> +	if (status != 0)
>> +		return status;
>> +
>> +	memcpy(ethernet_addr, receive_buf + 10, ETH_ALEN);
>> +
>> +	return status;
>> +}
>> +
>> +static int
>> +kalmia_bind(struct usbnet *dev, struct usb_interface *intf)
>> +{
>> +	u8 status;
>> +	u8 ethernet_addr[ETH_ALEN];
>> +
>> +	/* Don't bind to AT command interface */
>> +	if (intf->cur_altsetting->desc.bInterfaceClass != USB_CLASS_VENDOR_SPEC)
>> +		return -EINVAL;
>> +
>> +	dev->in = usb_rcvbulkpipe(dev->udev, 0x81&  USB_ENDPOINT_NUMBER_MASK);
>> +	dev->out = usb_sndbulkpipe(dev->udev, 0x02&  USB_ENDPOINT_NUMBER_MASK);
>> +	dev->status = NULL;
>> +
>> +	dev->net->hard_header_len += KALMIA_HEADER_LENGTH;
>> +	dev->hard_mtu = 1400;
>> +	dev->rx_urb_size = dev->hard_mtu * 10; // Found as optimal after testing
>> +
>> +	status = kalmia_init_and_get_ethernet_addr(dev, ethernet_addr);
>> +
>> +	if (status<  0) {
>> +		usb_set_intfdata(intf, NULL);
>> +		usb_driver_release_interface(driver_of(intf), intf);
>> +		return status;
> Why are you doing this? What is to be undone?

You mean the 3 last lines? I just did the same as done in another 
similar usbnet based driver. Is it incorrect if the init fails?

>> +	}
>> +
>> +	memcpy(dev->net->dev_addr, ethernet_addr, ETH_ALEN);
>> +	memcpy(dev->net->perm_addr, ethernet_addr, ETH_ALEN);
>> +
>> +	return status;
>> +}
>> +
>> +static struct sk_buff *
>> +kalmia_tx_fixup(struct usbnet *dev, struct sk_buff *skb, gfp_t flags)
>> +{
>> +	struct sk_buff *skb2 = NULL;
>> +	u16 content_len;
>> +	unsigned char *header_start;
>> +	unsigned char ether_type_1, ether_type_2;
>> +	u8 remainder, padlen = 0;
>> +
>> +	if (!skb_cloned(skb)) {
>> +		int headroom = skb_headroom(skb);
>> +		int tailroom = skb_tailroom(skb);
>> +
>> +		if ((tailroom>= KALMIA_ALIGN_SIZE)&&  (headroom
>> +			>= KALMIA_HEADER_LENGTH))
>> +			goto done;
>> +
>> +		if ((headroom + tailroom)>  (KALMIA_HEADER_LENGTH
>> +			+ KALMIA_ALIGN_SIZE)) {
>> +			skb->data = memmove(skb->head + KALMIA_HEADER_LENGTH,
>> +				skb->data, skb->len);
>> +			skb_set_tail_pointer(skb, skb->len);
>> +			goto done;
>> +		}
>> +	}
>> +
>> +	skb2 = skb_copy_expand(skb, KALMIA_HEADER_LENGTH,
>> +		KALMIA_ALIGN_SIZE, flags);
>> +	if (!skb2)
>> +		return NULL;
>> +
>> +	dev_kfree_skb_any(skb);
>> +	skb = skb2;
>> +
>> +	done: header_start = skb_push(skb, KALMIA_HEADER_LENGTH);
> coding style

The last line? I see.

>> +	ether_type_1 = header_start[KALMIA_HEADER_LENGTH + 12];
>> +	ether_type_2 = header_start[KALMIA_HEADER_LENGTH + 13];
>> +
>> +	netdev_dbg(dev->net, "Sending etherType: %02x%02x", ether_type_1,
>> +		ether_type_2);
>> +
>> +	/* According to empiric data for data packages */
>> +	header_start[0] = 0x57;
>> +	header_start[1] = 0x44;
>> +	content_len = skb->len - KALMIA_HEADER_LENGTH;
>> +	header_start[2] = (content_len&  0xff); /* low byte */
>> +	header_start[3] = (content_len>>  8); /* high byte */
> Please use an endianness macro

Wil fix. It will be very relevant to support other architectures for 
this driver, as I want to run it on a ARM based NAS as LTE router.

>> +	header_start[4] = ether_type_1;
>> +	header_start[5] = ether_type_2;
>> +
>> +	/* Align to 4 bytes by padding with zeros */
>> +	remainder = skb->len % KALMIA_ALIGN_SIZE;
>> +	if (remainder>  0) {
>> +		padlen = KALMIA_ALIGN_SIZE - remainder;
>> +		memset(skb_put(skb, padlen), 0, padlen);
>> +	}
>> +
>> +	netdev_dbg(
>> +		dev->net,
>> +		"Sending package with length %i and padding %i. Header: %02x:%02x:%02x:%02x:%02x:%02x.",
>> +		content_len, padlen, header_start[0], header_start[1],
>> +		header_start[2], header_start[3], header_start[4],
>> +		header_start[5]);
>> +
>> +	return skb;
>> +}
>> +
>> +static int
>> +kalmia_rx_fixup(struct usbnet *dev, struct sk_buff *skb)
>> +{
>> +	/*
>> +	 * Our task here is to strip off framing, leaving skb with one
>> +	 * data frame for the usbnet framework code to process.
>> +	 */
>> +	const u8 HEADER_END_OF_USB_PACKET[] =
>> +		{ 0x57, 0x5a, 0x00, 0x00, 0x08, 0x00 };
>> +	const u8 EXPECTED_UNKNOWN_HEADER_1[] =
>> +		{ 0x57, 0x43, 0x1e, 0x00, 0x15, 0x02 };
>> +	const u8 EXPECTED_UNKNOWN_HEADER_2[] =
>> +		{ 0x57, 0x50, 0x0e, 0x00, 0x00, 0x00 };
> What does the compiler do to this declaration?

Not sure I understand what you mean here.

>> +	u8 i = 0;
> Why not int?

I can change that. Thought int was not to be used because it is of 
unknown size.
>> +
>> +	/* incomplete header? */
>> +	if (skb->len<  KALMIA_HEADER_LENGTH)
>> +		return 0;
>> +
>> +	do {
>> +		struct sk_buff *skb2 = NULL;
>> +		u8 *header_start;
>> +		u16 usb_packet_length, ether_packet_length;
>> +		int is_last;
>> +
>> +		header_start = skb->data;
>> +
>> +		if (unlikely(header_start[0] != 0x57 || header_start[1] != 0x44)) {
>> +			if (!memcmp(header_start, EXPECTED_UNKNOWN_HEADER_1,
>> +				sizeof(EXPECTED_UNKNOWN_HEADER_1)) || !memcmp(
>> +				header_start, EXPECTED_UNKNOWN_HEADER_2,
>> +				sizeof(EXPECTED_UNKNOWN_HEADER_2))) {
>> +				netdev_dbg(
>> +					dev->net,
>> +					"Received expected unknown frame header: %02x:%02x:%02x:%02x:%02x:%02x. Package length: %i\n",
>> +					header_start[0], header_start[1],
>> +					header_start[2], header_start[3],
>> +					header_start[4], header_start[5],
>> +					skb->len - KALMIA_HEADER_LENGTH);
>> +			}
>> +			else {
>> +				netdev_err(
>> +					dev->net,
>> +					"Received unknown frame header: %02x:%02x:%02x:%02x:%02x:%02x. Package length: %i\n",
>> +					header_start[0], header_start[1],
>> +					header_start[2], header_start[3],
>> +					header_start[4], header_start[5],
>> +					skb->len - KALMIA_HEADER_LENGTH);
>> +				return 0;
>> +			}
>> +		}
>> +		else
>> +			netdev_dbg(
>> +				dev->net,
>> +				"Received header: %02x:%02x:%02x:%02x:%02x:%02x. Package length: %i\n",
>> +				header_start[0], header_start[1], header_start[2],
>> +				header_start[3], header_start[4], header_start[5],
>> +				skb->len - KALMIA_HEADER_LENGTH);
>> +
>> +		/* subtract start header and end header */
>> +		usb_packet_length = skb->len - (2 * KALMIA_HEADER_LENGTH);
>> +		ether_packet_length = header_start[2] + (header_start[3]<<  8);
> Please use an endianness macro

Oki.
>> +		skb_pull(skb, KALMIA_HEADER_LENGTH);
>> +
>> +		/* Some small packets misses end marker */
>> +		if (usb_packet_length<  ether_packet_length) {
>> +			ether_packet_length = usb_packet_length
>> +				+ KALMIA_HEADER_LENGTH;
>> +			is_last = true;
>> +		}
>> +		else {
>> +			netdev_dbg(dev->net, "Correct package length #%i", i
>> +				+ 1);
>> +
>> +			is_last = (memcmp(skb->data + ether_packet_length,
>> +				HEADER_END_OF_USB_PACKET,
>> +				sizeof(HEADER_END_OF_USB_PACKET)) == 0);
>> +			if (!is_last) {
>> +				header_start = skb->data + ether_packet_length;
>> +				netdev_dbg(
>> +					dev->net,
>> +					"End header: %02x:%02x:%02x:%02x:%02x:%02x. Package length: %i\n",
>> +					header_start[0], header_start[1],
>> +					header_start[2], header_start[3],
>> +					header_start[4], header_start[5],
>> +					skb->len - KALMIA_HEADER_LENGTH);
>> +			}
>> +		}
>> +
>> +		if (is_last) {
>> +			skb2 = skb;
>> +		}
>> +		else {
>> +			skb2 = skb_clone(skb, GFP_ATOMIC);
>> +			if (unlikely(!skb2))
>> +				return 0;
>> +		}
>> +
>> +		skb_trim(skb2, ether_packet_length);
>> +
>> +		if (is_last) {
>> +			return 1;
>> +		}
>> +		else {
>> +			usbnet_skb_return(dev, skb2);
>> +			skb_pull(skb, ether_packet_length);
>> +		}
>> +
>> +		i++;
>> +	}
>> +	while (skb->len);
>> +
>> +	return 1;
>> +}
>> +
>> +static const struct driver_info kalmia_info = {
>> +	.description = "Samsung Kalmia LTE USB dongle",
>> +	.flags = FLAG_WWAN,
>> +	.bind = kalmia_bind,
>> +	.rx_fixup = kalmia_rx_fixup,
>> +	.tx_fixup = kalmia_tx_fixup
>> +};
>> +
>> +/*-------------------------------------------------------------------------*/
>> +
>> +static const struct usb_device_id products[] = {
>> +	/* The unswitched USB ID, to get the module auto loaded: */
>> +	{ USB_DEVICE(0x04e8, 0x689a) },
> Why is this needed? Doesn't the switch trigger an autoload?

Please see the comment from Dan Williams. Will test his proposal.

Anyway it should not do any damage for anyone (I think even the driver 
disk is available with this included). The module could in fact also do 
the switch into modem mode to avoid the dependency on usb_modeswitch.

--
Marius


--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 35+ messages in thread

* Re: [PATCH] net/usb: Add Samsung Kalmia driver for Samsung GT-B3730
       [not found]                     ` <4DF72A90.1070702-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
@ 2011-06-14  9:46                       ` Oliver Neukum
       [not found]                         ` <201106141146.19097.oneukum-l3A5Bk7waGM@public.gmane.org>
  0 siblings, 1 reply; 35+ messages in thread
From: Oliver Neukum @ 2011-06-14  9:46 UTC (permalink / raw)
  To: Marius Kotsbak
  Cc: davem-fT/PcQaiUtIeIZ0/mPfg9Q, netdev-u79uwXL29TY76Z2rM5mHXA,
	linux-usb-u79uwXL29TY76Z2rM5mHXA, Marius B. Kotsbak

Am Dienstag, 14. Juni 2011, 11:32:00 schrieb Marius Kotsbak:
> Den 14. juni 2011 10:49, skrev Oliver Neukum:
> > Am Samstag, 11. Juni 2011, 23:55:18 schrieb Marius B. Kotsbak:
> >
> >> +static int
> >> +kalmia_init_and_get_ethernet_addr(struct usbnet *dev, u8 *ethernet_addr)
> >> +{
> >> +	char init_msg_1[] =
> >> +		{ 0x57, 0x50, 0x04, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00,
> >> +		0x00, 0x00 };
> >> +	char init_msg_2[] =
> >> +		{ 0x57, 0x50, 0x04, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0xf4,
> >> +		0x00, 0x00 };
> >> +	char receive_buf[28];
> > You are doing DMA on the stack. This will fail on some architectures.
> >
> 
> Okay, a bit strange that this API is available then. Which API functions 
> should be used in this case?

The API is correct. You just need to copy the init strings into buffers
allocated with kmalloc.

> >> +	if (status<  0) {
> >> +		usb_set_intfdata(intf, NULL);
> >> +		usb_driver_release_interface(driver_of(intf), intf);
> >> +		return status;
> > Why are you doing this? What is to be undone?
> 
> You mean the 3 last lines? I just did the same as done in another 
> similar usbnet based driver. Is it incorrect if the init fails?

Yes, the last three lines. If all drivers do that this is an opportunity to
share common code in usbnet. I'll look at it. 

> >> +static int
> >> +kalmia_rx_fixup(struct usbnet *dev, struct sk_buff *skb)
> >> +{
> >> +	/*
> >> +	 * Our task here is to strip off framing, leaving skb with one
> >> +	 * data frame for the usbnet framework code to process.
> >> +	 */
> >> +	const u8 HEADER_END_OF_USB_PACKET[] =
> >> +		{ 0x57, 0x5a, 0x00, 0x00, 0x08, 0x00 };
> >> +	const u8 EXPECTED_UNKNOWN_HEADER_1[] =
> >> +		{ 0x57, 0x43, 0x1e, 0x00, 0x15, 0x02 };
> >> +	const u8 EXPECTED_UNKNOWN_HEADER_2[] =
> >> +		{ 0x57, 0x50, 0x0e, 0x00, 0x00, 0x00 };
> > What does the compiler do to this declaration?
> 
> Not sure I understand what you mean here.

Will the compiler put those strings into the image or build them on
the stack each time the function is called? Shouldn't they be static?

> >> +	u8 i = 0;
> > Why not int?
> 
> I can change that. Thought int was not to be used because it is of 
> unknown size.

Well, then are you sure i will never be larger than 255?

> Anyway it should not do any damage for anyone (I think even the driver 
> disk is available with this included). The module could in fact also do 
> the switch into modem mode to avoid the dependency on usb_modeswitch.

Please don't do that. It has been decided to put such things into usb_modeswitch
for now.

	Regards
		Oliver
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 35+ messages in thread

* Re: [PATCH] net/usb: Add Samsung Kalmia driver for Samsung GT-B3730
  2011-06-12 12:35                   ` Marius B. Kotsbak
@ 2011-06-17  2:01                     ` David Miller
       [not found]                       ` <20110616.220112.882657314456163072.davem-fT/PcQaiUtIeIZ0/mPfg9Q@public.gmane.org>
  0 siblings, 1 reply; 35+ messages in thread
From: David Miller @ 2011-06-17  2:01 UTC (permalink / raw)
  To: marius.kotsbak; +Cc: netdev, linux-usb, marius

From: "Marius B. Kotsbak" <marius.kotsbak@gmail.com>
Date: Sun, 12 Jun 2011 14:35:02 +0200

> Introducing driver for the network port of Samsung Kalmia based USB LTE modems.
> It has also an ACM interface that previous patches associates with the "option"
> module. To access those interfaces, the modem must first be switched from modem
> mode using a tool like usb_modeswitch.
> 
> As the proprietary protocol has been discovered by watching the MS Windows driver
> behavior, there might be errors in the protocol handling, but stable and fast
> connection has been established for hours with Norwegian operator NetCom that
> distributes this modem with their LTE/4G subscription.
> 
> More and updated information about how to use this driver is available here:
> 
> http://www.draisberghof.de/usb_modeswitch/bb/viewtopic.php?t=465
> https://github.com/mkotsbak/Samsung-GT-B3730-linux-driver
> 
> Signed-off-by: Marius B. Kotsbak <marius@kotsbak.com>

Applied, thanks.

^ permalink raw reply	[flat|nested] 35+ messages in thread

* Re: [PATCH] net/usb: Add Samsung Kalmia driver for Samsung GT-B3730
       [not found]                       ` <20110616.220112.882657314456163072.davem-fT/PcQaiUtIeIZ0/mPfg9Q@public.gmane.org>
@ 2011-06-17 10:31                         ` Marius Bjørnstad Kotsbak
  0 siblings, 0 replies; 35+ messages in thread
From: Marius Bjørnstad Kotsbak @ 2011-06-17 10:31 UTC (permalink / raw)
  To: David Miller
  Cc: netdev-u79uwXL29TY76Z2rM5mHXA, linux-usb-u79uwXL29TY76Z2rM5mHXA,
	marius-iy5w9mehe2BBDgjK7y7TUQ

Den 17. juni 2011 04:01, skrev David Miller:
> From: "Marius B. Kotsbak"<marius.kotsbak-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
> Date: Sun, 12 Jun 2011 14:35:02 +0200
>
>> Introducing driver for the network port of Samsung Kalmia based USB LTE modems.
>> It has also an ACM interface that previous patches associates with the "option"
>> module. To access those interfaces, the modem must first be switched from modem
>> mode using a tool like usb_modeswitch.
>>
>> As the proprietary protocol has been discovered by watching the MS Windows driver
>> behavior, there might be errors in the protocol handling, but stable and fast
>> connection has been established for hours with Norwegian operator NetCom that
>> distributes this modem with their LTE/4G subscription.
>>
>> More and updated information about how to use this driver is available here:
>>
>> http://www.draisberghof.de/usb_modeswitch/bb/viewtopic.php?t=465
>> https://github.com/mkotsbak/Samsung-GT-B3730-linux-driver
>>
>> Signed-off-by: Marius B. Kotsbak<marius-iy5w9mehe2BBDgjK7y7TUQ@public.gmane.org>
> Applied, thanks.

Thanks, will send additional patches with improvements for non-x86 
proposed by Oliver soon.

--
Marius


--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 35+ messages in thread

* Re: [PATCH] net/usb: Add Samsung Kalmia driver for Samsung GT-B3730
       [not found]             ` <1307978364.2117.11.camel-wKZy7rqYPVb5EHUCmHmTqw@public.gmane.org>
@ 2011-06-18 20:03               ` Marius Kotsbak
  0 siblings, 0 replies; 35+ messages in thread
From: Marius Kotsbak @ 2011-06-18 20:03 UTC (permalink / raw)
  To: Dan Williams
  Cc: davem-fT/PcQaiUtIeIZ0/mPfg9Q, netdev-u79uwXL29TY76Z2rM5mHXA,
	linux-usb-u79uwXL29TY76Z2rM5mHXA, Marius B. Kotsbak

On 13. juni 2011 17:19, Dan Williams wrote:
> On Mon, 2011-06-13 at 17:01 +0200, Marius Kotsbak wrote:
>> On 13. juni 2011 16:57, Dan Williams wrote:
>>>
>>> Why make the driver bind to both the switched and unswitched USB IDs?
>>> Shouldn't the kernel bind the driver after switch when the device
>>> reconnects with the new IDs?
>> No, I tried and it did not happen, so I assumed that the kernel modules
>> are only loaded at USB insertion event, not when the interfaces changes.
>> Does anyone here know if my observation is right?
>>
>> Usb_modeswitch autoloads "option" module after switching, but not my
>> kalmia module.
> Try killing the modeswitch autoload thing first by moving the udev
> script out of the way.  Then plug your device in, and run
> "usb-modeswitch -c /path/to/config" so that the usb_modeswitch autoload
> thing doesn't run.  Does that work?  I don't want to slander
> usb_modeswitch but I've seen some odd behavior which I suspect is it's
> module force-loading feature, though I haven't investigated too much
> yet.  But ruling that out could be helpful.

I tried that now, and the "option" module does not load after switch,
even though it is supposed to recognize the switched modem interface
(but not the unswitched):

alias:          usb:v04E8p6889d*dc*dsc*dp*ic0Aisc00ip00*

I guess what is happening is that the modem just changes it internal
state to give another usb configuration, but only when requested by the
host (as at modem insertion). The reason "option" module is normally
loaded is that usb_modeswitch does it explicit, but it does not know
that it should insert the "kalmia" module.

Thus I leave the unswitched USB ID there if not anyone has any better
working solution.

--
Marius


--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 35+ messages in thread

* [PATCH 1/2] net/usb: Add Samsung Kalmia driver for Samsung GT-B3730
       [not found]                         ` <201106141146.19097.oneukum-l3A5Bk7waGM@public.gmane.org>
@ 2011-06-19 21:45                           ` Marius B. Kotsbak
  2011-06-19 21:45                             ` [PATCH 2/2] Various fixes for better support of non-x86 architectures Marius B. Kotsbak
  2011-06-19 22:57                             ` [PATCH 1/2] net/usb: Add Samsung Kalmia driver for Samsung GT-B3730 David Miller
  2011-06-19 21:53                           ` [PATCH] net/usb: Add Samsung Kalmia driver for Samsung GT-B3730 Marius Kotsbak
  1 sibling, 2 replies; 35+ messages in thread
From: Marius B. Kotsbak @ 2011-06-19 21:45 UTC (permalink / raw)
  To: davem-fT/PcQaiUtIeIZ0/mPfg9Q, netdev-u79uwXL29TY76Z2rM5mHXA
  Cc: linux-usb-u79uwXL29TY76Z2rM5mHXA, Marius B. Kotsbak

Introducing driver for the network port of Samsung Kalmia based USB LTE modems.
It has also an ACM interface that previous patches associates with the "option"
module. To access those interfaces, the modem must first be switched from modem
mode using a tool like usb_modeswitch.

As the proprietary protocol has been discovered by watching the MS Windows driver
behavior, there might be errors in the protocol handling, but stable and fast
connection has been established for hours with Norwegian operator NetCom that
distributes this modem with their LTE/4G subscription.

More and updated information about how to use this driver is available here:

http://www.draisberghof.de/usb_modeswitch/bb/viewtopic.php?t=465
https://github.com/mkotsbak/Samsung-GT-B3730-linux-driver

Signed-off-by: Marius B. Kotsbak <marius-iy5w9mehe2BBDgjK7y7TUQ@public.gmane.org>
---
 drivers/net/usb/Kconfig  |   10 ++
 drivers/net/usb/Makefile |    1 +
 drivers/net/usb/kalmia.c |  384 ++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 395 insertions(+), 0 deletions(-)
 create mode 100644 drivers/net/usb/kalmia.c

diff --git a/drivers/net/usb/Kconfig b/drivers/net/usb/Kconfig
index 9d4f911..84d4608 100644
--- a/drivers/net/usb/Kconfig
+++ b/drivers/net/usb/Kconfig
@@ -385,6 +385,16 @@ config USB_NET_CX82310_ETH
 	  router with USB ethernet port. This driver is for routers only,
 	  it will not work with ADSL modems (use cxacru driver instead).
 
+config USB_NET_KALMIA
+	tristate "Samsung Kalmia based LTE USB modem"
+	depends on USB_USBNET
+	help
+	  Choose this option if you have a Samsung Kalmia based USB modem
+	  as Samsung GT-B3730.
+
+	  To compile this driver as a module, choose M here: the
+	  module will be called kalmia.
+
 config USB_HSO
 	tristate "Option USB High Speed Mobile Devices"
 	depends on USB && RFKILL
diff --git a/drivers/net/usb/Makefile b/drivers/net/usb/Makefile
index c7ec8a5..c203fa2 100644
--- a/drivers/net/usb/Makefile
+++ b/drivers/net/usb/Makefile
@@ -23,6 +23,7 @@ obj-$(CONFIG_USB_NET_MCS7830)	+= mcs7830.o
 obj-$(CONFIG_USB_USBNET)	+= usbnet.o
 obj-$(CONFIG_USB_NET_INT51X1)	+= int51x1.o
 obj-$(CONFIG_USB_CDC_PHONET)	+= cdc-phonet.o
+obj-$(CONFIG_USB_NET_KALMIA)	+= kalmia.o
 obj-$(CONFIG_USB_IPHETH)	+= ipheth.o
 obj-$(CONFIG_USB_SIERRA_NET)	+= sierra_net.o
 obj-$(CONFIG_USB_NET_CX82310_ETH)	+= cx82310_eth.o
diff --git a/drivers/net/usb/kalmia.c b/drivers/net/usb/kalmia.c
new file mode 100644
index 0000000..d965fb1
--- /dev/null
+++ b/drivers/net/usb/kalmia.c
@@ -0,0 +1,384 @@
+/*
+ * USB network interface driver for Samsung Kalmia based LTE USB modem like the
+ * Samsung GT-B3730 and GT-B3710.
+ *
+ * Copyright (C) 2011 Marius Bjoernstad Kotsbak <marius-iy5w9mehe2BBDgjK7y7TUQ@public.gmane.org>
+ *
+ * Sponsored by Quicklink Video Distribution Services Ltd.
+ *
+ * Based on the cdc_eem module.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ */
+
+#include <linux/module.h>
+#include <linux/init.h>
+#include <linux/netdevice.h>
+#include <linux/etherdevice.h>
+#include <linux/ctype.h>
+#include <linux/ethtool.h>
+#include <linux/workqueue.h>
+#include <linux/mii.h>
+#include <linux/usb.h>
+#include <linux/crc32.h>
+#include <linux/usb/cdc.h>
+#include <linux/usb/usbnet.h>
+#include <linux/gfp.h>
+
+/*
+ * The Samsung Kalmia based LTE USB modems have a CDC ACM port for modem control
+ * handled by the "option" module and an ethernet data port handled by this
+ * module.
+ *
+ * The stick must first be switched into modem mode by usb_modeswitch
+ * or similar tool. Then the modem gets sent two initialization packets by
+ * this module, which gives the MAC address of the device. User space can then
+ * connect the modem using AT commands through the ACM port and then use
+ * DHCP on the network interface exposed by this module. Network packets are
+ * sent to and from the modem in a proprietary format discovered after watching
+ * the behavior of the windows driver for the modem.
+ *
+ * More information about the use of the modem is available in usb_modeswitch
+ * forum and the project page:
+ *
+ * http://www.draisberghof.de/usb_modeswitch/bb/viewtopic.php?t=465
+ * https://github.com/mkotsbak/Samsung-GT-B3730-linux-driver
+ */
+
+/* #define	DEBUG */
+/* #define	VERBOSE */
+
+#define KALMIA_HEADER_LENGTH 6
+#define KALMIA_ALIGN_SIZE 4
+#define KALMIA_USB_TIMEOUT 10000
+
+/*-------------------------------------------------------------------------*/
+
+static int
+kalmia_send_init_packet(struct usbnet *dev, u8 *init_msg, u8 init_msg_len,
+	u8 *buffer, u8 expected_len)
+{
+	int act_len;
+	int status;
+
+	netdev_dbg(dev->net, "Sending init packet");
+
+	status = usb_bulk_msg(dev->udev, usb_sndbulkpipe(dev->udev, 0x02),
+		init_msg, init_msg_len, &act_len, KALMIA_USB_TIMEOUT);
+	if (status != 0) {
+		netdev_err(dev->net,
+			"Error sending init packet. Status %i, length %i\n",
+			status, act_len);
+		return status;
+	}
+	else if (act_len != init_msg_len) {
+		netdev_err(dev->net,
+			"Did not send all of init packet. Bytes sent: %i",
+			act_len);
+	}
+	else {
+		netdev_dbg(dev->net, "Successfully sent init packet.");
+	}
+
+	status = usb_bulk_msg(dev->udev, usb_rcvbulkpipe(dev->udev, 0x81),
+		buffer, expected_len, &act_len, KALMIA_USB_TIMEOUT);
+
+	if (status != 0)
+		netdev_err(dev->net,
+			"Error receiving init result. Status %i, length %i\n",
+			status, act_len);
+	else if (act_len != expected_len)
+		netdev_err(dev->net, "Unexpected init result length: %i\n",
+			act_len);
+
+	return status;
+}
+
+static int
+kalmia_init_and_get_ethernet_addr(struct usbnet *dev, u8 *ethernet_addr)
+{
+	char init_msg_1[] =
+		{ 0x57, 0x50, 0x04, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00,
+		0x00, 0x00 };
+	char init_msg_2[] =
+		{ 0x57, 0x50, 0x04, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0xf4,
+		0x00, 0x00 };
+	char receive_buf[28];
+	int status;
+
+	status = kalmia_send_init_packet(dev, init_msg_1, sizeof(init_msg_1)
+		/ sizeof(init_msg_1[0]), receive_buf, 24);
+	if (status != 0)
+		return status;
+
+	status = kalmia_send_init_packet(dev, init_msg_2, sizeof(init_msg_2)
+		/ sizeof(init_msg_2[0]), receive_buf, 28);
+	if (status != 0)
+		return status;
+
+	memcpy(ethernet_addr, receive_buf + 10, ETH_ALEN);
+
+	return status;
+}
+
+static int
+kalmia_bind(struct usbnet *dev, struct usb_interface *intf)
+{
+	u8 status;
+	u8 ethernet_addr[ETH_ALEN];
+
+	/* Don't bind to AT command interface */
+	if (intf->cur_altsetting->desc.bInterfaceClass != USB_CLASS_VENDOR_SPEC)
+		return -EINVAL;
+
+	dev->in = usb_rcvbulkpipe(dev->udev, 0x81 & USB_ENDPOINT_NUMBER_MASK);
+	dev->out = usb_sndbulkpipe(dev->udev, 0x02 & USB_ENDPOINT_NUMBER_MASK);
+	dev->status = NULL;
+
+	dev->net->hard_header_len += KALMIA_HEADER_LENGTH;
+	dev->hard_mtu = 1400;
+	dev->rx_urb_size = dev->hard_mtu * 10; // Found as optimal after testing
+
+	status = kalmia_init_and_get_ethernet_addr(dev, ethernet_addr);
+
+	if (status < 0) {
+		usb_set_intfdata(intf, NULL);
+		usb_driver_release_interface(driver_of(intf), intf);
+		return status;
+	}
+
+	memcpy(dev->net->dev_addr, ethernet_addr, ETH_ALEN);
+	memcpy(dev->net->perm_addr, ethernet_addr, ETH_ALEN);
+
+	return status;
+}
+
+static struct sk_buff *
+kalmia_tx_fixup(struct usbnet *dev, struct sk_buff *skb, gfp_t flags)
+{
+	struct sk_buff *skb2 = NULL;
+	u16 content_len;
+	unsigned char *header_start;
+	unsigned char ether_type_1, ether_type_2;
+	u8 remainder, padlen = 0;
+
+	if (!skb_cloned(skb)) {
+		int headroom = skb_headroom(skb);
+		int tailroom = skb_tailroom(skb);
+
+		if ((tailroom >= KALMIA_ALIGN_SIZE) && (headroom
+			>= KALMIA_HEADER_LENGTH))
+			goto done;
+
+		if ((headroom + tailroom) > (KALMIA_HEADER_LENGTH
+			+ KALMIA_ALIGN_SIZE)) {
+			skb->data = memmove(skb->head + KALMIA_HEADER_LENGTH,
+				skb->data, skb->len);
+			skb_set_tail_pointer(skb, skb->len);
+			goto done;
+		}
+	}
+
+	skb2 = skb_copy_expand(skb, KALMIA_HEADER_LENGTH,
+		KALMIA_ALIGN_SIZE, flags);
+	if (!skb2)
+		return NULL;
+
+	dev_kfree_skb_any(skb);
+	skb = skb2;
+
+	done: header_start = skb_push(skb, KALMIA_HEADER_LENGTH);
+	ether_type_1 = header_start[KALMIA_HEADER_LENGTH + 12];
+	ether_type_2 = header_start[KALMIA_HEADER_LENGTH + 13];
+
+	netdev_dbg(dev->net, "Sending etherType: %02x%02x", ether_type_1,
+		ether_type_2);
+
+	/* According to empiric data for data packages */
+	header_start[0] = 0x57;
+	header_start[1] = 0x44;
+	content_len = skb->len - KALMIA_HEADER_LENGTH;
+	header_start[2] = (content_len & 0xff); /* low byte */
+	header_start[3] = (content_len >> 8); /* high byte */
+
+	header_start[4] = ether_type_1;
+	header_start[5] = ether_type_2;
+
+	/* Align to 4 bytes by padding with zeros */
+	remainder = skb->len % KALMIA_ALIGN_SIZE;
+	if (remainder > 0) {
+		padlen = KALMIA_ALIGN_SIZE - remainder;
+		memset(skb_put(skb, padlen), 0, padlen);
+	}
+
+	netdev_dbg(
+		dev->net,
+		"Sending package with length %i and padding %i. Header: %02x:%02x:%02x:%02x:%02x:%02x.",
+		content_len, padlen, header_start[0], header_start[1],
+		header_start[2], header_start[3], header_start[4],
+		header_start[5]);
+
+	return skb;
+}
+
+static int
+kalmia_rx_fixup(struct usbnet *dev, struct sk_buff *skb)
+{
+	/*
+	 * Our task here is to strip off framing, leaving skb with one
+	 * data frame for the usbnet framework code to process.
+	 */
+	const u8 HEADER_END_OF_USB_PACKET[] =
+		{ 0x57, 0x5a, 0x00, 0x00, 0x08, 0x00 };
+	const u8 EXPECTED_UNKNOWN_HEADER_1[] =
+		{ 0x57, 0x43, 0x1e, 0x00, 0x15, 0x02 };
+	const u8 EXPECTED_UNKNOWN_HEADER_2[] =
+		{ 0x57, 0x50, 0x0e, 0x00, 0x00, 0x00 };
+	u8 i = 0;
+
+	/* incomplete header? */
+	if (skb->len < KALMIA_HEADER_LENGTH)
+		return 0;
+
+	do {
+		struct sk_buff *skb2 = NULL;
+		u8 *header_start;
+		u16 usb_packet_length, ether_packet_length;
+		int is_last;
+
+		header_start = skb->data;
+
+		if (unlikely(header_start[0] != 0x57 || header_start[1] != 0x44)) {
+			if (!memcmp(header_start, EXPECTED_UNKNOWN_HEADER_1,
+				sizeof(EXPECTED_UNKNOWN_HEADER_1)) || !memcmp(
+				header_start, EXPECTED_UNKNOWN_HEADER_2,
+				sizeof(EXPECTED_UNKNOWN_HEADER_2))) {
+				netdev_dbg(
+					dev->net,
+					"Received expected unknown frame header: %02x:%02x:%02x:%02x:%02x:%02x. Package length: %i\n",
+					header_start[0], header_start[1],
+					header_start[2], header_start[3],
+					header_start[4], header_start[5],
+					skb->len - KALMIA_HEADER_LENGTH);
+			}
+			else {
+				netdev_err(
+					dev->net,
+					"Received unknown frame header: %02x:%02x:%02x:%02x:%02x:%02x. Package length: %i\n",
+					header_start[0], header_start[1],
+					header_start[2], header_start[3],
+					header_start[4], header_start[5],
+					skb->len - KALMIA_HEADER_LENGTH);
+				return 0;
+			}
+		}
+		else
+			netdev_dbg(
+				dev->net,
+				"Received header: %02x:%02x:%02x:%02x:%02x:%02x. Package length: %i\n",
+				header_start[0], header_start[1], header_start[2],
+				header_start[3], header_start[4], header_start[5],
+				skb->len - KALMIA_HEADER_LENGTH);
+
+		/* subtract start header and end header */
+		usb_packet_length = skb->len - (2 * KALMIA_HEADER_LENGTH);
+		ether_packet_length = header_start[2] + (header_start[3] << 8);
+		skb_pull(skb, KALMIA_HEADER_LENGTH);
+
+		/* Some small packets misses end marker */
+		if (usb_packet_length < ether_packet_length) {
+			ether_packet_length = usb_packet_length
+				+ KALMIA_HEADER_LENGTH;
+			is_last = true;
+		}
+		else {
+			netdev_dbg(dev->net, "Correct package length #%i", i
+				+ 1);
+
+			is_last = (memcmp(skb->data + ether_packet_length,
+				HEADER_END_OF_USB_PACKET,
+				sizeof(HEADER_END_OF_USB_PACKET)) == 0);
+			if (!is_last) {
+				header_start = skb->data + ether_packet_length;
+				netdev_dbg(
+					dev->net,
+					"End header: %02x:%02x:%02x:%02x:%02x:%02x. Package length: %i\n",
+					header_start[0], header_start[1],
+					header_start[2], header_start[3],
+					header_start[4], header_start[5],
+					skb->len - KALMIA_HEADER_LENGTH);
+			}
+		}
+
+		if (is_last) {
+			skb2 = skb;
+		}
+		else {
+			skb2 = skb_clone(skb, GFP_ATOMIC);
+			if (unlikely(!skb2))
+				return 0;
+		}
+
+		skb_trim(skb2, ether_packet_length);
+
+		if (is_last) {
+			return 1;
+		}
+		else {
+			usbnet_skb_return(dev, skb2);
+			skb_pull(skb, ether_packet_length);
+		}
+
+		i++;
+	}
+	while (skb->len);
+
+	return 1;
+}
+
+static const struct driver_info kalmia_info = {
+	.description = "Samsung Kalmia LTE USB dongle",
+	.flags = FLAG_WWAN,
+	.bind = kalmia_bind,
+	.rx_fixup = kalmia_rx_fixup,
+	.tx_fixup = kalmia_tx_fixup
+};
+
+/*-------------------------------------------------------------------------*/
+
+static const struct usb_device_id products[] = {
+	/* The unswitched USB ID, to get the module auto loaded: */
+	{ USB_DEVICE(0x04e8, 0x689a) },
+	/* The stick swithed into modem (by e.g. usb_modeswitch): */
+	{ USB_DEVICE(0x04e8, 0x6889),
+		.driver_info = (unsigned long) &kalmia_info, },
+	{ /* EMPTY == end of list */} };
+MODULE_DEVICE_TABLE( usb, products);
+
+static struct usb_driver kalmia_driver = {
+	.name = "kalmia",
+	.id_table = products,
+	.probe = usbnet_probe,
+	.disconnect = usbnet_disconnect,
+	.suspend = usbnet_suspend,
+	.resume = usbnet_resume
+};
+
+static int __init kalmia_init(void)
+{
+	return usb_register(&kalmia_driver);
+}
+module_init( kalmia_init);
+
+static void __exit kalmia_exit(void)
+{
+	usb_deregister(&kalmia_driver);
+}
+module_exit( kalmia_exit);
+
+MODULE_AUTHOR("Marius Bjoernstad Kotsbak <marius-iy5w9mehe2BBDgjK7y7TUQ@public.gmane.org>");
+MODULE_DESCRIPTION("Samsung Kalmia USB network driver");
+MODULE_LICENSE("GPL");
-- 
1.7.4.1

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply related	[flat|nested] 35+ messages in thread

* [PATCH 2/2] Various fixes for better support of non-x86 architectures.
  2011-06-19 21:45                           ` [PATCH 1/2] " Marius B. Kotsbak
@ 2011-06-19 21:45                             ` Marius B. Kotsbak
  2011-06-19 22:57                             ` [PATCH 1/2] net/usb: Add Samsung Kalmia driver for Samsung GT-B3730 David Miller
  1 sibling, 0 replies; 35+ messages in thread
From: Marius B. Kotsbak @ 2011-06-19 21:45 UTC (permalink / raw)
  To: davem, netdev; +Cc: linux-usb, Marius B. Kotsbak

-Support for big endian.
-Do not use USB buffers at the stack.
-Safer/more efficient code for local constants.

Signed-off-by: Marius B. Kotsbak <marius@kotsbak.com>
---
 drivers/net/usb/kalmia.c |   40 ++++++++++++++++++++++++----------------
 1 files changed, 24 insertions(+), 16 deletions(-)

diff --git a/drivers/net/usb/kalmia.c b/drivers/net/usb/kalmia.c
index d965fb1..d4edeb2 100644
--- a/drivers/net/usb/kalmia.c
+++ b/drivers/net/usb/kalmia.c
@@ -100,27 +100,35 @@ kalmia_send_init_packet(struct usbnet *dev, u8 *init_msg, u8 init_msg_len,
 static int
 kalmia_init_and_get_ethernet_addr(struct usbnet *dev, u8 *ethernet_addr)
 {
-	char init_msg_1[] =
+	const static char init_msg_1[] =
 		{ 0x57, 0x50, 0x04, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00,
 		0x00, 0x00 };
-	char init_msg_2[] =
+	const static char init_msg_2[] =
 		{ 0x57, 0x50, 0x04, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0xf4,
 		0x00, 0x00 };
-	char receive_buf[28];
+	const static int buflen = 28;
+	char *usb_buf;
 	int status;
 
-	status = kalmia_send_init_packet(dev, init_msg_1, sizeof(init_msg_1)
-		/ sizeof(init_msg_1[0]), receive_buf, 24);
+	usb_buf = kmalloc(buflen, GFP_DMA | GFP_KERNEL);
+	if (!usb_buf)
+		return -ENOMEM;
+
+	memcpy(usb_buf, init_msg_1, 12);
+	status = kalmia_send_init_packet(dev, usb_buf, sizeof(init_msg_1)
+		/ sizeof(init_msg_1[0]), usb_buf, 24);
 	if (status != 0)
 		return status;
 
-	status = kalmia_send_init_packet(dev, init_msg_2, sizeof(init_msg_2)
-		/ sizeof(init_msg_2[0]), receive_buf, 28);
+	memcpy(usb_buf, init_msg_2, 12);
+	status = kalmia_send_init_packet(dev, usb_buf, sizeof(init_msg_2)
+		/ sizeof(init_msg_2[0]), usb_buf, 28);
 	if (status != 0)
 		return status;
 
-	memcpy(ethernet_addr, receive_buf + 10, ETH_ALEN);
+	memcpy(ethernet_addr, usb_buf + 10, ETH_ALEN);
 
+	kfree(usb_buf);
 	return status;
 }
 
@@ -190,7 +198,8 @@ kalmia_tx_fixup(struct usbnet *dev, struct sk_buff *skb, gfp_t flags)
 	dev_kfree_skb_any(skb);
 	skb = skb2;
 
-	done: header_start = skb_push(skb, KALMIA_HEADER_LENGTH);
+done:
+	header_start = skb_push(skb, KALMIA_HEADER_LENGTH);
 	ether_type_1 = header_start[KALMIA_HEADER_LENGTH + 12];
 	ether_type_2 = header_start[KALMIA_HEADER_LENGTH + 13];
 
@@ -201,9 +210,8 @@ kalmia_tx_fixup(struct usbnet *dev, struct sk_buff *skb, gfp_t flags)
 	header_start[0] = 0x57;
 	header_start[1] = 0x44;
 	content_len = skb->len - KALMIA_HEADER_LENGTH;
-	header_start[2] = (content_len & 0xff); /* low byte */
-	header_start[3] = (content_len >> 8); /* high byte */
 
+	put_unaligned_le16(content_len, &header_start[2]);
 	header_start[4] = ether_type_1;
 	header_start[5] = ether_type_2;
 
@@ -231,13 +239,13 @@ kalmia_rx_fixup(struct usbnet *dev, struct sk_buff *skb)
 	 * Our task here is to strip off framing, leaving skb with one
 	 * data frame for the usbnet framework code to process.
 	 */
-	const u8 HEADER_END_OF_USB_PACKET[] =
+	const static u8 HEADER_END_OF_USB_PACKET[] =
 		{ 0x57, 0x5a, 0x00, 0x00, 0x08, 0x00 };
-	const u8 EXPECTED_UNKNOWN_HEADER_1[] =
+	const static u8 EXPECTED_UNKNOWN_HEADER_1[] =
 		{ 0x57, 0x43, 0x1e, 0x00, 0x15, 0x02 };
-	const u8 EXPECTED_UNKNOWN_HEADER_2[] =
+	const static u8 EXPECTED_UNKNOWN_HEADER_2[] =
 		{ 0x57, 0x50, 0x0e, 0x00, 0x00, 0x00 };
-	u8 i = 0;
+	int i = 0;
 
 	/* incomplete header? */
 	if (skb->len < KALMIA_HEADER_LENGTH)
@@ -285,7 +293,7 @@ kalmia_rx_fixup(struct usbnet *dev, struct sk_buff *skb)
 
 		/* subtract start header and end header */
 		usb_packet_length = skb->len - (2 * KALMIA_HEADER_LENGTH);
-		ether_packet_length = header_start[2] + (header_start[3] << 8);
+		ether_packet_length = get_unaligned_le16(&header_start[2]);
 		skb_pull(skb, KALMIA_HEADER_LENGTH);
 
 		/* Some small packets misses end marker */
-- 
1.7.4.1


^ permalink raw reply related	[flat|nested] 35+ messages in thread

* Re: [PATCH] net/usb: Add Samsung Kalmia driver for Samsung GT-B3730
       [not found]                         ` <201106141146.19097.oneukum-l3A5Bk7waGM@public.gmane.org>
  2011-06-19 21:45                           ` [PATCH 1/2] " Marius B. Kotsbak
@ 2011-06-19 21:53                           ` Marius Kotsbak
       [not found]                             ` <4DFE6FD8.1080003-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
  1 sibling, 1 reply; 35+ messages in thread
From: Marius Kotsbak @ 2011-06-19 21:53 UTC (permalink / raw)
  To: Oliver Neukum
  Cc: davem-fT/PcQaiUtIeIZ0/mPfg9Q, netdev-u79uwXL29TY76Z2rM5mHXA,
	linux-usb-u79uwXL29TY76Z2rM5mHXA, Marius B. Kotsbak

On 14. juni 2011 11:46, Oliver Neukum wrote:
> Am Dienstag, 14. Juni 2011, 11:32:00 schrieb Marius Kotsbak:
>> Den 14. juni 2011 10:49, skrev Oliver Neukum:
>>> Am Samstag, 11. Juni 2011, 23:55:18 schrieb Marius B. Kotsbak:
>>>
>>>> +static int
>>>> +kalmia_init_and_get_ethernet_addr(struct usbnet *dev, u8 *ethernet_addr)
>>>> +{
>>>> +	char init_msg_1[] =
>>>> +		{ 0x57, 0x50, 0x04, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00,
>>>> +		0x00, 0x00 };
>>>> +	char init_msg_2[] =
>>>> +		{ 0x57, 0x50, 0x04, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0xf4,
>>>> +		0x00, 0x00 };
>>>> +	char receive_buf[28];
>>> You are doing DMA on the stack. This will fail on some architectures.
>>>
>> Okay, a bit strange that this API is available then. Which API functions 
>> should be used in this case?
> The API is correct. You just need to copy the init strings into buffers
> allocated with kmalloc.
>

This should be addressed in the extra patch just sent. And it still
works on my x86-64.

The 2 patches might be squashed if desired.

>
> Will the compiler put those strings into the image or build them on
> the stack each time the function is called? Shouldn't they be static?
>

Fixed. It probably improves performance too.
>> Anyway it should not do any damage for anyone (I think even the driver 
>> disk is available with this included). The module could in fact also do 
>> the switch into modem mode to avoid the dependency on usb_modeswitch.
> Please don't do that. It has been decided to put such things into usb_modeswitch
> for now.

Okay, I can see the reasoning behind that. The problem is just that it
would be nice to avoid it because >1.1.4 versions of it does not work
with this modem, but that can be addressed there as well.

--
Marius


--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 35+ messages in thread

* Re: [PATCH 1/2] net/usb: Add Samsung Kalmia driver for Samsung GT-B3730
  2011-06-19 21:45                           ` [PATCH 1/2] " Marius B. Kotsbak
  2011-06-19 21:45                             ` [PATCH 2/2] Various fixes for better support of non-x86 architectures Marius B. Kotsbak
@ 2011-06-19 22:57                             ` David Miller
       [not found]                               ` <20110619.155755.1854488306547854947.davem-fT/PcQaiUtIeIZ0/mPfg9Q@public.gmane.org>
  1 sibling, 1 reply; 35+ messages in thread
From: David Miller @ 2011-06-19 22:57 UTC (permalink / raw)
  To: marius.kotsbak; +Cc: netdev, linux-usb, marius

From: "Marius B. Kotsbak" <marius.kotsbak@gmail.com>
Date: Sun, 19 Jun 2011 23:45:56 +0200

> Introducing driver for the network port of Samsung Kalmia based USB LTE modems.
> It has also an ACM interface that previous patches associates with the "option"
> module. To access those interfaces, the modem must first be switched from modem
> mode using a tool like usb_modeswitch.
> 
> As the proprietary protocol has been discovered by watching the MS Windows driver
> behavior, there might be errors in the protocol handling, but stable and fast
> connection has been established for hours with Norwegian operator NetCom that
> distributes this modem with their LTE/4G subscription.
> 
> More and updated information about how to use this driver is available here:
> 
> http://www.draisberghof.de/usb_modeswitch/bb/viewtopic.php?t=465
> https://github.com/mkotsbak/Samsung-GT-B3730-linux-driver
> 
> Signed-off-by: Marius B. Kotsbak <marius@kotsbak.com>

Please submit only one patch for adding a new driver.

Adding a second patch that fixes the driver in various ways is
just noise, put those fixes into this one initial patch instead.

Thanks.

^ permalink raw reply	[flat|nested] 35+ messages in thread

* Re: [PATCH] net/usb: Add Samsung Kalmia driver for Samsung GT-B3730
       [not found]                             ` <4DFE6FD8.1080003-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
@ 2011-06-20  6:47                               ` Oliver Neukum
  0 siblings, 0 replies; 35+ messages in thread
From: Oliver Neukum @ 2011-06-20  6:47 UTC (permalink / raw)
  To: Marius Kotsbak
  Cc: davem-fT/PcQaiUtIeIZ0/mPfg9Q, netdev-u79uwXL29TY76Z2rM5mHXA,
	linux-usb-u79uwXL29TY76Z2rM5mHXA, Marius B. Kotsbak

Am Sonntag, 19. Juni 2011, 23:53:28 schrieb Marius Kotsbak:
> On 14. juni 2011 11:46, Oliver Neukum wrote:
> > Am Dienstag, 14. Juni 2011, 11:32:00 schrieb Marius Kotsbak:
> >> Den 14. juni 2011 10:49, skrev Oliver Neukum:

> > The API is correct. You just need to copy the init strings into buffers
> > allocated with kmalloc.
> >
> 
> This should be addressed in the extra patch just sent. And it still
> works on my x86-64.

x86-64 works. ppc and arm are hurt.

> The 2 patches might be squashed if desired.

 David?

> Okay, I can see the reasoning behind that. The problem is just that it
> would be nice to avoid it because >1.1.4 versions of it does not work
> with this modem, but that can be addressed there as well.

All's well, as far as I can see.

	Regards
		Oliver
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 35+ messages in thread

* Re: [PATCH 1/2] net/usb: Add Samsung Kalmia driver for Samsung GT-B3730
       [not found]                               ` <20110619.155755.1854488306547854947.davem-fT/PcQaiUtIeIZ0/mPfg9Q@public.gmane.org>
@ 2011-06-22 15:24                                 ` Marius Kotsbak
  2011-06-22 15:26                                 ` [PATCH] net/usb: kalmia: Various fixes for better support of non-x86 architectures Marius B. Kotsbak
  1 sibling, 0 replies; 35+ messages in thread
From: Marius Kotsbak @ 2011-06-22 15:24 UTC (permalink / raw)
  To: David Miller
  Cc: netdev-u79uwXL29TY76Z2rM5mHXA, linux-usb-u79uwXL29TY76Z2rM5mHXA,
	marius-iy5w9mehe2BBDgjK7y7TUQ

On 20. juni 2011 00:57, David Miller wrote:
> From: "Marius B. Kotsbak" <marius.kotsbak-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
> Date: Sun, 19 Jun 2011 23:45:56 +0200
>
>> Introducing driver for the network port of Samsung Kalmia based USB LTE modems.
>> It has also an ACM interface that previous patches associates with the "option"
>> module. To access those interfaces, the modem must first be switched from modem
>> mode using a tool like usb_modeswitch.
>>
>> As the proprietary protocol has been discovered by watching the MS Windows driver
>> behavior, there might be errors in the protocol handling, but stable and fast
>> connection has been established for hours with Norwegian operator NetCom that
>> distributes this modem with their LTE/4G subscription.
>>
>> More and updated information about how to use this driver is available here:
>>
>> http://www.draisberghof.de/usb_modeswitch/bb/viewtopic.php?t=465
>> https://github.com/mkotsbak/Samsung-GT-B3730-linux-driver
>>
>> Signed-off-by: Marius B. Kotsbak <marius-iy5w9mehe2BBDgjK7y7TUQ@public.gmane.org>
> Please submit only one patch for adding a new driver.
>
> Adding a second patch that fixes the driver in various ways is
> just noise, put those fixes into this one initial patch instead.

Turned out the first patch already is accepted into Linus tree, so then
I send again just the second.

--
Marius


--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 35+ messages in thread

* [PATCH] net/usb: kalmia: Various fixes for better support of non-x86 architectures.
       [not found]                               ` <20110619.155755.1854488306547854947.davem-fT/PcQaiUtIeIZ0/mPfg9Q@public.gmane.org>
  2011-06-22 15:24                                 ` Marius Kotsbak
@ 2011-06-22 15:26                                 ` Marius B. Kotsbak
  2011-06-22 20:41                                   ` David Miller
       [not found]                                   ` <1308756376-9920-1-git-send-email-marius-iy5w9mehe2BBDgjK7y7TUQ@public.gmane.org>
  1 sibling, 2 replies; 35+ messages in thread
From: Marius B. Kotsbak @ 2011-06-22 15:26 UTC (permalink / raw)
  To: davem-fT/PcQaiUtIeIZ0/mPfg9Q, netdev-u79uwXL29TY76Z2rM5mHXA
  Cc: linux-usb-u79uwXL29TY76Z2rM5mHXA, Marius B. Kotsbak

-Support for big endian.
-Do not use USB buffers at the stack.
-Safer/more efficient code for local constants.

Signed-off-by: Marius B. Kotsbak <marius-iy5w9mehe2BBDgjK7y7TUQ@public.gmane.org>
---
 drivers/net/usb/kalmia.c |   40 ++++++++++++++++++++++++----------------
 1 files changed, 24 insertions(+), 16 deletions(-)

diff --git a/drivers/net/usb/kalmia.c b/drivers/net/usb/kalmia.c
index d965fb1..d4edeb2 100644
--- a/drivers/net/usb/kalmia.c
+++ b/drivers/net/usb/kalmia.c
@@ -100,27 +100,35 @@ kalmia_send_init_packet(struct usbnet *dev, u8 *init_msg, u8 init_msg_len,
 static int
 kalmia_init_and_get_ethernet_addr(struct usbnet *dev, u8 *ethernet_addr)
 {
-	char init_msg_1[] =
+	const static char init_msg_1[] =
 		{ 0x57, 0x50, 0x04, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00,
 		0x00, 0x00 };
-	char init_msg_2[] =
+	const static char init_msg_2[] =
 		{ 0x57, 0x50, 0x04, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0xf4,
 		0x00, 0x00 };
-	char receive_buf[28];
+	const static int buflen = 28;
+	char *usb_buf;
 	int status;
 
-	status = kalmia_send_init_packet(dev, init_msg_1, sizeof(init_msg_1)
-		/ sizeof(init_msg_1[0]), receive_buf, 24);
+	usb_buf = kmalloc(buflen, GFP_DMA | GFP_KERNEL);
+	if (!usb_buf)
+		return -ENOMEM;
+
+	memcpy(usb_buf, init_msg_1, 12);
+	status = kalmia_send_init_packet(dev, usb_buf, sizeof(init_msg_1)
+		/ sizeof(init_msg_1[0]), usb_buf, 24);
 	if (status != 0)
 		return status;
 
-	status = kalmia_send_init_packet(dev, init_msg_2, sizeof(init_msg_2)
-		/ sizeof(init_msg_2[0]), receive_buf, 28);
+	memcpy(usb_buf, init_msg_2, 12);
+	status = kalmia_send_init_packet(dev, usb_buf, sizeof(init_msg_2)
+		/ sizeof(init_msg_2[0]), usb_buf, 28);
 	if (status != 0)
 		return status;
 
-	memcpy(ethernet_addr, receive_buf + 10, ETH_ALEN);
+	memcpy(ethernet_addr, usb_buf + 10, ETH_ALEN);
 
+	kfree(usb_buf);
 	return status;
 }
 
@@ -190,7 +198,8 @@ kalmia_tx_fixup(struct usbnet *dev, struct sk_buff *skb, gfp_t flags)
 	dev_kfree_skb_any(skb);
 	skb = skb2;
 
-	done: header_start = skb_push(skb, KALMIA_HEADER_LENGTH);
+done:
+	header_start = skb_push(skb, KALMIA_HEADER_LENGTH);
 	ether_type_1 = header_start[KALMIA_HEADER_LENGTH + 12];
 	ether_type_2 = header_start[KALMIA_HEADER_LENGTH + 13];
 
@@ -201,9 +210,8 @@ kalmia_tx_fixup(struct usbnet *dev, struct sk_buff *skb, gfp_t flags)
 	header_start[0] = 0x57;
 	header_start[1] = 0x44;
 	content_len = skb->len - KALMIA_HEADER_LENGTH;
-	header_start[2] = (content_len & 0xff); /* low byte */
-	header_start[3] = (content_len >> 8); /* high byte */
 
+	put_unaligned_le16(content_len, &header_start[2]);
 	header_start[4] = ether_type_1;
 	header_start[5] = ether_type_2;
 
@@ -231,13 +239,13 @@ kalmia_rx_fixup(struct usbnet *dev, struct sk_buff *skb)
 	 * Our task here is to strip off framing, leaving skb with one
 	 * data frame for the usbnet framework code to process.
 	 */
-	const u8 HEADER_END_OF_USB_PACKET[] =
+	const static u8 HEADER_END_OF_USB_PACKET[] =
 		{ 0x57, 0x5a, 0x00, 0x00, 0x08, 0x00 };
-	const u8 EXPECTED_UNKNOWN_HEADER_1[] =
+	const static u8 EXPECTED_UNKNOWN_HEADER_1[] =
 		{ 0x57, 0x43, 0x1e, 0x00, 0x15, 0x02 };
-	const u8 EXPECTED_UNKNOWN_HEADER_2[] =
+	const static u8 EXPECTED_UNKNOWN_HEADER_2[] =
 		{ 0x57, 0x50, 0x0e, 0x00, 0x00, 0x00 };
-	u8 i = 0;
+	int i = 0;
 
 	/* incomplete header? */
 	if (skb->len < KALMIA_HEADER_LENGTH)
@@ -285,7 +293,7 @@ kalmia_rx_fixup(struct usbnet *dev, struct sk_buff *skb)
 
 		/* subtract start header and end header */
 		usb_packet_length = skb->len - (2 * KALMIA_HEADER_LENGTH);
-		ether_packet_length = header_start[2] + (header_start[3] << 8);
+		ether_packet_length = get_unaligned_le16(&header_start[2]);
 		skb_pull(skb, KALMIA_HEADER_LENGTH);
 
 		/* Some small packets misses end marker */
-- 
1.7.4.1

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply related	[flat|nested] 35+ messages in thread

* Re: [PATCH] net/usb: kalmia: Various fixes for better support of non-x86 architectures.
  2011-06-22 15:26                                 ` [PATCH] net/usb: kalmia: Various fixes for better support of non-x86 architectures Marius B. Kotsbak
@ 2011-06-22 20:41                                   ` David Miller
       [not found]                                   ` <1308756376-9920-1-git-send-email-marius-iy5w9mehe2BBDgjK7y7TUQ@public.gmane.org>
  1 sibling, 0 replies; 35+ messages in thread
From: David Miller @ 2011-06-22 20:41 UTC (permalink / raw)
  To: marius.kotsbak; +Cc: netdev, linux-usb, marius

From: "Marius B. Kotsbak" <marius.kotsbak@gmail.com>
Date: Wed, 22 Jun 2011 17:26:16 +0200

> -Support for big endian.
> -Do not use USB buffers at the stack.
> -Safer/more efficient code for local constants.
> 
> Signed-off-by: Marius B. Kotsbak <marius@kotsbak.com>

Applied, thanks.

^ permalink raw reply	[flat|nested] 35+ messages in thread

* Re: [PATCH] net/usb: kalmia: Various fixes for better support of non-x86 architectures.
       [not found]                                   ` <1308756376-9920-1-git-send-email-marius-iy5w9mehe2BBDgjK7y7TUQ@public.gmane.org>
@ 2011-06-23 10:46                                     ` Sergei Shtylyov
       [not found]                                       ` <4E03198A.2060600-hkdhdckH98+B+jHODAdFcQ@public.gmane.org>
  2011-06-23 20:56                                       ` Marius Kotsbak
  0 siblings, 2 replies; 35+ messages in thread
From: Sergei Shtylyov @ 2011-06-23 10:46 UTC (permalink / raw)
  To: Marius B. Kotsbak
  Cc: davem-fT/PcQaiUtIeIZ0/mPfg9Q, netdev-u79uwXL29TY76Z2rM5mHXA,
	linux-usb-u79uwXL29TY76Z2rM5mHXA, Marius B. Kotsbak

Hello.

On 22-06-2011 19:26, Marius B. Kotsbak wrote:

> -Support for big endian.
> -Do not use USB buffers at the stack.
> -Safer/more efficient code for local constants.

> Signed-off-by: Marius B. Kotsbak<marius-iy5w9mehe2BBDgjK7y7TUQ@public.gmane.org>
> ---
>   drivers/net/usb/kalmia.c |   40 ++++++++++++++++++++++++----------------
>   1 files changed, 24 insertions(+), 16 deletions(-)

> diff --git a/drivers/net/usb/kalmia.c b/drivers/net/usb/kalmia.c
> index d965fb1..d4edeb2 100644
> --- a/drivers/net/usb/kalmia.c
> +++ b/drivers/net/usb/kalmia.c
> @@ -100,27 +100,35 @@ kalmia_send_init_packet(struct usbnet *dev, u8 *init_msg, u8 init_msg_len,
>   static int
>   kalmia_init_and_get_ethernet_addr(struct usbnet *dev, u8 *ethernet_addr)
>   {
> -	char init_msg_1[] =
> +	const static char init_msg_1[] =
>   		{ 0x57, 0x50, 0x04, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00,
>   		0x00, 0x00 };
> -	char init_msg_2[] =
> +	const static char init_msg_2[] =
>   		{ 0x57, 0x50, 0x04, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0xf4,
>   		0x00, 0x00 };

    Actually 'const' alone should've been enough for the variable to be placed 
in the data section ISO stack.

> -	char receive_buf[28];
> +	const static int buflen = 28;

    Why declare it at all, when it's used only once?

> +	char *usb_buf;
>   	int status;
>
> -	status = kalmia_send_init_packet(dev, init_msg_1, sizeof(init_msg_1)
> -		/ sizeof(init_msg_1[0]), receive_buf, 24);
> +	usb_buf = kmalloc(buflen, GFP_DMA | GFP_KERNEL);
> +	if (!usb_buf)
> +		return -ENOMEM;
> +
> +	memcpy(usb_buf, init_msg_1, 12);

    s/12/sizeof(init_msg_1)/

> +	status = kalmia_send_init_packet(dev, usb_buf, sizeof(init_msg_1)
> +		/ sizeof(init_msg_1[0]), usb_buf, 24);

    There's ARRAY_SIZE() macro to replace:

sizeof(init_msg_1) / sizeof(init_msg_1[0])

    and why not use just sizeof(init_msg_1)?

>   	if (status != 0)
>   		return status;
>
> -	status = kalmia_send_init_packet(dev, init_msg_2, sizeof(init_msg_2)
> -		/ sizeof(init_msg_2[0]), receive_buf, 28);
> +	memcpy(usb_buf, init_msg_2, 12);

    s/12/sizeof(init_msg_2)/

> +	status = kalmia_send_init_packet(dev, usb_buf, sizeof(init_msg_2)
> +		/ sizeof(init_msg_2[0]), usb_buf, 28);

    The same comment here about:

sizeof(init_msg_2) / sizeof(init_msg_2[0])

WBR, Sergei

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 35+ messages in thread

* Re: [PATCH] net/usb: kalmia: Various fixes for better support of non-x86 architectures.
       [not found]                                       ` <4E03198A.2060600-hkdhdckH98+B+jHODAdFcQ@public.gmane.org>
@ 2011-06-23 14:28                                         ` Alan Stern
  2011-06-23 14:55                                           ` Sergei Shtylyov
  0 siblings, 1 reply; 35+ messages in thread
From: Alan Stern @ 2011-06-23 14:28 UTC (permalink / raw)
  To: Sergei Shtylyov
  Cc: Marius B. Kotsbak, davem-fT/PcQaiUtIeIZ0/mPfg9Q,
	netdev-u79uwXL29TY76Z2rM5mHXA, linux-usb-u79uwXL29TY76Z2rM5mHXA,
	Marius B. Kotsbak

On Thu, 23 Jun 2011, Sergei Shtylyov wrote:

> Hello.
> 
> On 22-06-2011 19:26, Marius B. Kotsbak wrote:
> 
> > -Support for big endian.
> > -Do not use USB buffers at the stack.
> > -Safer/more efficient code for local constants.
> 
> > Signed-off-by: Marius B. Kotsbak<marius-iy5w9mehe2BBDgjK7y7TUQ@public.gmane.org>
> > ---
> >   drivers/net/usb/kalmia.c |   40 ++++++++++++++++++++++++----------------
> >   1 files changed, 24 insertions(+), 16 deletions(-)
> 
> > diff --git a/drivers/net/usb/kalmia.c b/drivers/net/usb/kalmia.c
> > index d965fb1..d4edeb2 100644
> > --- a/drivers/net/usb/kalmia.c
> > +++ b/drivers/net/usb/kalmia.c
> > @@ -100,27 +100,35 @@ kalmia_send_init_packet(struct usbnet *dev, u8 *init_msg, u8 init_msg_len,
> >   static int
> >   kalmia_init_and_get_ethernet_addr(struct usbnet *dev, u8 *ethernet_addr)
> >   {
> > -	char init_msg_1[] =
> > +	const static char init_msg_1[] =
> >   		{ 0x57, 0x50, 0x04, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00,
> >   		0x00, 0x00 };
> > -	char init_msg_2[] =
> > +	const static char init_msg_2[] =
> >   		{ 0x57, 0x50, 0x04, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0xf4,
> >   		0x00, 0x00 };
> 
>     Actually 'const' alone should've been enough for the variable to be placed 
> in the data section ISO stack.

I don't understand what "ISO stack" means here.

I would think that "const" might or might not cause the array to be 
allocated statically.  All it really tells the compiler is that the 
function will not change the contents of the array.

To be certain that the array is allocated statically (not on the 
stack), it's best to use "static".

Alan Stern

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 35+ messages in thread

* Re: [PATCH] net/usb: kalmia: Various fixes for better support of non-x86 architectures.
  2011-06-23 14:28                                         ` Alan Stern
@ 2011-06-23 14:55                                           ` Sergei Shtylyov
       [not found]                                             ` <4E0353D0.1060604-hkdhdckH98+B+jHODAdFcQ@public.gmane.org>
  0 siblings, 1 reply; 35+ messages in thread
From: Sergei Shtylyov @ 2011-06-23 14:55 UTC (permalink / raw)
  To: Alan Stern
  Cc: Sergei Shtylyov, Marius B. Kotsbak, davem, netdev, linux-usb,
	Marius B. Kotsbak

Alan Stern wrote:

>>> -Support for big endian.
>>> -Do not use USB buffers at the stack.
>>> -Safer/more efficient code for local constants.

>>> Signed-off-by: Marius B. Kotsbak<marius@kotsbak.com>

>>> ---
>>>   drivers/net/usb/kalmia.c |   40 ++++++++++++++++++++++++----------------
>>>   1 files changed, 24 insertions(+), 16 deletions(-)

>>> diff --git a/drivers/net/usb/kalmia.c b/drivers/net/usb/kalmia.c
>>> index d965fb1..d4edeb2 100644
>>> --- a/drivers/net/usb/kalmia.c
>>> +++ b/drivers/net/usb/kalmia.c
>>> @@ -100,27 +100,35 @@ kalmia_send_init_packet(struct usbnet *dev, u8 *init_msg, u8 init_msg_len,
>>>   static int
>>>   kalmia_init_and_get_ethernet_addr(struct usbnet *dev, u8 *ethernet_addr)
>>>   {
>>> -	char init_msg_1[] =
>>> +	const static char init_msg_1[] =
>>>   		{ 0x57, 0x50, 0x04, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00,
>>>   		0x00, 0x00 };
>>> -	char init_msg_2[] =
>>> +	const static char init_msg_2[] =
>>>   		{ 0x57, 0x50, 0x04, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0xf4,
>>>   		0x00, 0x00 };

>>     Actually 'const' alone should've been enough for the variable to be placed 
>> in the data section ISO stack.

> I don't understand what "ISO stack" means here.

    ISO == instead of.

> I would think that "const" might or might not cause the array to be 
> allocated statically.

    At least with gcc, it will be allocated statically.

> Alan Stern

WBR, Sergei

^ permalink raw reply	[flat|nested] 35+ messages in thread

* Re: [PATCH] net/usb: kalmia: Various fixes for better support of non-x86 architectures.
  2011-06-23 10:46                                     ` Sergei Shtylyov
       [not found]                                       ` <4E03198A.2060600-hkdhdckH98+B+jHODAdFcQ@public.gmane.org>
@ 2011-06-23 20:56                                       ` Marius Kotsbak
  1 sibling, 0 replies; 35+ messages in thread
From: Marius Kotsbak @ 2011-06-23 20:56 UTC (permalink / raw)
  To: Sergei Shtylyov; +Cc: davem, netdev, linux-usb, Marius B. Kotsbak

Den 23. juni 2011 12:46, skrev Sergei Shtylyov:
> Hello.
>
> On 22-06-2011 19:26, Marius B. Kotsbak wrote:
>
>> -Support for big endian.
>> -Do not use USB buffers at the stack.
>> -Safer/more efficient code for local constants.
>
>> Signed-off-by: Marius B. Kotsbak<marius@kotsbak.com>
>> ---
>>   drivers/net/usb/kalmia.c |   40 
>> ++++++++++++++++++++++++----------------
>>   1 files changed, 24 insertions(+), 16 deletions(-)
>
>
>> -    char receive_buf[28];
>> +    const static int buflen = 28;
>
>    Why declare it at all, when it's used only once?
>
>> +    char *usb_buf;
>>       int status;
>>
>> -    status = kalmia_send_init_packet(dev, init_msg_1, 
>> sizeof(init_msg_1)
>> -        / sizeof(init_msg_1[0]), receive_buf, 24);
>> +    usb_buf = kmalloc(buflen, GFP_DMA | GFP_KERNEL);
>> +    if (!usb_buf)
>> +        return -ENOMEM;
>> +
>> +    memcpy(usb_buf, init_msg_1, 12);
>
>    s/12/sizeof(init_msg_1)/
>
>> +    status = kalmia_send_init_packet(dev, usb_buf, sizeof(init_msg_1)
>> +        / sizeof(init_msg_1[0]), usb_buf, 24);
>
>    There's ARRAY_SIZE() macro to replace:
>
> sizeof(init_msg_1) / sizeof(init_msg_1[0])
>
>    and why not use just sizeof(init_msg_1)?
>
>>       if (status != 0)
>>           return status;
>>
>> -    status = kalmia_send_init_packet(dev, init_msg_2, 
>> sizeof(init_msg_2)
>> -        / sizeof(init_msg_2[0]), receive_buf, 28);
>> +    memcpy(usb_buf, init_msg_2, 12);
>
>    s/12/sizeof(init_msg_2)/
>
>> +    status = kalmia_send_init_packet(dev, usb_buf, sizeof(init_msg_2)
>> +        / sizeof(init_msg_2[0]), usb_buf, 28);
>
>    The same comment here about:
>
> sizeof(init_msg_2) / sizeof(init_msg_2[0])
>

Thanks for the tips. I know some parts of the code are a bit ugly, but 
the primary goal was to get it working despite the quirky state of the 
current modem firmware. I have noted it for later fixing.

--
Marius


^ permalink raw reply	[flat|nested] 35+ messages in thread

* Re: [PATCH] net/usb: kalmia: Various fixes for better support of non-x86 architectures.
       [not found]                                             ` <4E0353D0.1060604-hkdhdckH98+B+jHODAdFcQ@public.gmane.org>
@ 2011-06-24  5:42                                               ` Oliver Neukum
       [not found]                                                 ` <201106240742.38806.oliver-GvhC2dPhHPQdnm+yROfE0A@public.gmane.org>
  0 siblings, 1 reply; 35+ messages in thread
From: Oliver Neukum @ 2011-06-24  5:42 UTC (permalink / raw)
  To: Sergei Shtylyov
  Cc: Alan Stern, Marius B. Kotsbak, davem-fT/PcQaiUtIeIZ0/mPfg9Q,
	netdev-u79uwXL29TY76Z2rM5mHXA, linux-usb-u79uwXL29TY76Z2rM5mHXA,
	Marius B. Kotsbak

Am Donnerstag, 23. Juni 2011, 16:55:12 schrieb Sergei Shtylyov:
> >>     Actually 'const' alone should've been enough for the variable to be placed 
> >> in the data section ISO stack.
> 
> > I don't understand what "ISO stack" means here.
> 
>     ISO == instead of.

That doesn't matter. If you are sufficiently unlucky it will land on
a page boundary. You must not do DMA on the data section either.

	Regards
		Oliver

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 35+ messages in thread

* Re: [PATCH] net/usb: kalmia: Various fixes for better support of non-x86 architectures.
       [not found]                                                 ` <201106240742.38806.oliver-GvhC2dPhHPQdnm+yROfE0A@public.gmane.org>
@ 2011-06-24 11:55                                                   ` Sergei Shtylyov
  0 siblings, 0 replies; 35+ messages in thread
From: Sergei Shtylyov @ 2011-06-24 11:55 UTC (permalink / raw)
  To: Oliver Neukum
  Cc: Sergei Shtylyov, Alan Stern, Marius B. Kotsbak,
	davem-fT/PcQaiUtIeIZ0/mPfg9Q, netdev-u79uwXL29TY76Z2rM5mHXA,
	linux-usb-u79uwXL29TY76Z2rM5mHXA, Marius B. Kotsbak

Hello.

On 24-06-2011 9:42, Oliver Neukum wrote:

>>>>      Actually 'const' alone should've been enough for the variable to be placed
>>>> in the data section ISO stack.

>>> I don't understand what "ISO stack" means here.

>>      ISO == instead of.

> That doesn't matter. If you are sufficiently unlucky it will land on
> a page boundary. You must not do DMA on the data section either.

    Who said it was going to do DMA on the data section? The arrays got copied 
to heap-allocated buffer before DMA. But allocating those arrays on stack was 
not optimal anyway.

> 	Regards
> 		Oliver
>

WBR, Sergei
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 35+ messages in thread

end of thread, other threads:[~2011-06-24 11:55 UTC | newest]

Thread overview: 35+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-06-10 23:34 [PATCH] net/usb: Add Samsung Kalmia driver for Samsung GT-B3730 Marius B. Kotsbak
     [not found] ` <1307748870-12950-1-git-send-email-marius-iy5w9mehe2BBDgjK7y7TUQ@public.gmane.org>
2011-06-10 23:55   ` Greg KH
     [not found]     ` <20110610235557.GA23443-U8xfFu+wG4EAvxtiuMwx3w@public.gmane.org>
2011-06-11  0:25       ` Marius Kotsbak
2011-06-11 20:06         ` Greg KH
2011-06-11 21:55           ` Marius B. Kotsbak
2011-06-11 23:27             ` David Miller
2011-06-11 23:29               ` David Miller
     [not found]                 ` <20110611.162942.1706711069327005315.davem-fT/PcQaiUtIeIZ0/mPfg9Q@public.gmane.org>
2011-06-12  3:46                   ` Ben Hutchings
2011-06-12 12:35                   ` Marius B. Kotsbak
2011-06-17  2:01                     ` David Miller
     [not found]                       ` <20110616.220112.882657314456163072.davem-fT/PcQaiUtIeIZ0/mPfg9Q@public.gmane.org>
2011-06-17 10:31                         ` Marius Bjørnstad Kotsbak
2011-06-12 12:36                   ` Marius Kotsbak
     [not found]             ` <1307829318-18246-1-git-send-email-marius-iy5w9mehe2BBDgjK7y7TUQ@public.gmane.org>
2011-06-14  8:49               ` Oliver Neukum
     [not found]                 ` <201106141049.39150.oneukum-l3A5Bk7waGM@public.gmane.org>
2011-06-14  9:32                   ` Marius Kotsbak
     [not found]                     ` <4DF72A90.1070702-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2011-06-14  9:46                       ` Oliver Neukum
     [not found]                         ` <201106141146.19097.oneukum-l3A5Bk7waGM@public.gmane.org>
2011-06-19 21:45                           ` [PATCH 1/2] " Marius B. Kotsbak
2011-06-19 21:45                             ` [PATCH 2/2] Various fixes for better support of non-x86 architectures Marius B. Kotsbak
2011-06-19 22:57                             ` [PATCH 1/2] net/usb: Add Samsung Kalmia driver for Samsung GT-B3730 David Miller
     [not found]                               ` <20110619.155755.1854488306547854947.davem-fT/PcQaiUtIeIZ0/mPfg9Q@public.gmane.org>
2011-06-22 15:24                                 ` Marius Kotsbak
2011-06-22 15:26                                 ` [PATCH] net/usb: kalmia: Various fixes for better support of non-x86 architectures Marius B. Kotsbak
2011-06-22 20:41                                   ` David Miller
     [not found]                                   ` <1308756376-9920-1-git-send-email-marius-iy5w9mehe2BBDgjK7y7TUQ@public.gmane.org>
2011-06-23 10:46                                     ` Sergei Shtylyov
     [not found]                                       ` <4E03198A.2060600-hkdhdckH98+B+jHODAdFcQ@public.gmane.org>
2011-06-23 14:28                                         ` Alan Stern
2011-06-23 14:55                                           ` Sergei Shtylyov
     [not found]                                             ` <4E0353D0.1060604-hkdhdckH98+B+jHODAdFcQ@public.gmane.org>
2011-06-24  5:42                                               ` Oliver Neukum
     [not found]                                                 ` <201106240742.38806.oliver-GvhC2dPhHPQdnm+yROfE0A@public.gmane.org>
2011-06-24 11:55                                                   ` Sergei Shtylyov
2011-06-23 20:56                                       ` Marius Kotsbak
2011-06-19 21:53                           ` [PATCH] net/usb: Add Samsung Kalmia driver for Samsung GT-B3730 Marius Kotsbak
     [not found]                             ` <4DFE6FD8.1080003-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2011-06-20  6:47                               ` Oliver Neukum
2011-06-11 21:57           ` Marius Kotsbak
     [not found]             ` <4DF3E4E1.2070309-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2011-06-11 22:40               ` Greg KH
2011-06-13 14:57   ` Dan Williams
     [not found]     ` <1307977039.2117.7.camel-wKZy7rqYPVb5EHUCmHmTqw@public.gmane.org>
2011-06-13 15:01       ` Marius Kotsbak
     [not found]         ` <4DF62656.8060506-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2011-06-13 15:19           ` Dan Williams
     [not found]             ` <1307978364.2117.11.camel-wKZy7rqYPVb5EHUCmHmTqw@public.gmane.org>
2011-06-18 20:03               ` Marius Kotsbak

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.