netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Bjørn Mork" <bjorn@mork.no>
To: netdev@vger.kernel.org
Cc: linux-usb@vger.kernel.org, "Oliver Neukum" <oliver@neukum.org>,
	"Greg Kroah-Hartman" <gregkh@linuxfoundation.org>,
	"Alexey Orishko" <alexey.orishko@gmail.com>,
	"Greg Suarez" <gpsuarez2512@gmail.com>,
	"Fangxiaozhi (Franko)" <fangxiaozhi@huawei.com>,
	"Dan Williams" <dcbw@redhat.com>,
	"Aleksander Morgado" <aleksander@lanedo.com>,
	"Greg Suarez" <gsuarez@smithmicro.com>,
	"Bjørn Mork" <bjorn@mork.no>
Subject: [PATCH net-next 04/14] net: cdc_ncm: adding MBIM support to ncm_setup
Date: Thu, 18 Oct 2012 22:40:57 +0200	[thread overview]
Message-ID: <1350592867-25651-5-git-send-email-bjorn@mork.no> (raw)
In-Reply-To: <1350592867-25651-1-git-send-email-bjorn@mork.no>

From: Greg Suarez <gsuarez@smithmicro.com>

MBIM and NCM are very similar, so we can reuse most of the
setup and bind logic in cdc_ncm for CDC MBIM devices.  Handle
a few minor differences in ncm_setup.

Signed-off-by: Greg Suarez <gsuarez@smithmicro.com>
Signed-off-by: Bjørn Mork <bjorn@mork.no>
---
 drivers/net/usb/cdc_ncm.c |   51 ++++++++++++++++++++++++++++++++-------------
 1 file changed, 36 insertions(+), 15 deletions(-)

diff --git a/drivers/net/usb/cdc_ncm.c b/drivers/net/usb/cdc_ncm.c
index 6a65662..bddb0e4 100644
--- a/drivers/net/usb/cdc_ncm.c
+++ b/drivers/net/usb/cdc_ncm.c
@@ -64,6 +64,9 @@
 /* Minimum value for MaxDatagramSize, ch. 6.2.9 */
 #define	CDC_NCM_MIN_DATAGRAM_SIZE		1514	/* bytes */
 
+/* Minimum value for MaxDatagramSize, ch. 8.1.3 */
+#define CDC_MBIM_MIN_DATAGRAM_SIZE              2048    /* bytes */
+
 #define	CDC_NCM_MIN_TX_PKT			512	/* bytes */
 
 /* Default value for MaxDatagramSize */
@@ -98,6 +101,7 @@ struct cdc_ncm_ctx {
 	struct tasklet_struct bh;
 
 	const struct usb_cdc_ncm_desc *func_desc;
+	const struct usb_cdc_mbim_desc *mbim_desc;
 	const struct usb_cdc_header_desc *header_desc;
 	const struct usb_cdc_union_desc *union_desc;
 	const struct usb_cdc_ether_desc *ether_desc;
@@ -158,7 +162,10 @@ static u8 cdc_ncm_setup(struct cdc_ncm_ctx *ctx)
 	u8 flags;
 	u8 iface_no;
 	int err;
+	int eth_hlen;
 	u16 ntb_fmt_supported;
+	u32 min_dgram_size;
+	u32 min_hdr_size;
 
 	iface_no = ctx->control->cur_altsetting->desc.bInterfaceNumber;
 
@@ -184,10 +191,19 @@ static u8 cdc_ncm_setup(struct cdc_ncm_ctx *ctx)
 	ctx->tx_max_datagrams = le16_to_cpu(ctx->ncm_parm.wNtbOutMaxDatagrams);
 	ntb_fmt_supported = le16_to_cpu(ctx->ncm_parm.bmNtbFormatsSupported);
 
-	if (ctx->func_desc != NULL)
+	eth_hlen = ETH_HLEN;
+	min_dgram_size = CDC_NCM_MIN_DATAGRAM_SIZE;
+	min_hdr_size = CDC_NCM_MIN_HDR_SIZE;
+	if (ctx->mbim_desc != NULL) {
+		flags = ctx->mbim_desc->bmNetworkCapabilities;
+		eth_hlen = 0;
+		min_dgram_size = CDC_MBIM_MIN_DATAGRAM_SIZE;
+		min_hdr_size = 0;
+	} else if (ctx->func_desc != NULL) {
 		flags = ctx->func_desc->bmNetworkCapabilities;
-	else
+	} else {
 		flags = 0;
+	}
 
 	pr_debug("dwNtbInMaxSize=%u dwNtbOutMaxSize=%u "
 		 "wNdpOutPayloadRemainder=%u wNdpOutDivisor=%u "
@@ -224,6 +240,7 @@ static u8 cdc_ncm_setup(struct cdc_ncm_ctx *ctx)
 				err = -ENOMEM;
 				goto size_err;
 			}
+			ndp_in_sz->dwNtbInMaxSize = cpu_to_le32(ctx->rx_max);
 
 			err = usb_control_msg(ctx->udev,
 					usb_sndctrlpipe(ctx->udev, 0),
@@ -260,7 +277,7 @@ size_err:
 
 	/* verify maximum size of transmitted NTB in bytes */
 	if ((ctx->tx_max <
-	    (CDC_NCM_MIN_HDR_SIZE + CDC_NCM_MIN_DATAGRAM_SIZE)) ||
+	    (min_hdr_size + min_dgram_size)) ||
 	    (ctx->tx_max > CDC_NCM_NTB_MAX_SIZE_TX)) {
 		pr_debug("Using default maximum transmit length=%d\n",
 						CDC_NCM_NTB_MAX_SIZE_TX);
@@ -302,8 +319,8 @@ size_err:
 	}
 
 	/* adjust TX-remainder according to NCM specification. */
-	ctx->tx_remainder = ((ctx->tx_remainder - ETH_HLEN) &
-						(ctx->tx_modulus - 1));
+	ctx->tx_remainder = ((ctx->tx_remainder - eth_hlen) &
+			     (ctx->tx_modulus - 1));
 
 	/* additional configuration */
 
@@ -330,12 +347,18 @@ size_err:
 			pr_debug("Setting NTB format to 16-bit failed\n");
 	}
 
-	ctx->max_datagram_size = CDC_NCM_MIN_DATAGRAM_SIZE;
+	ctx->max_datagram_size = min_dgram_size;
 
 	/* set Max Datagram Size (MTU) */
 	if (flags & USB_CDC_NCM_NCAP_MAX_DATAGRAM_SIZE) {
 		__le16 *max_datagram_size;
-		u16 eth_max_sz = le16_to_cpu(ctx->ether_desc->wMaxSegmentSize);
+		u16 eth_max_sz;
+		if (ctx->ether_desc != NULL)
+			eth_max_sz = le16_to_cpu(ctx->ether_desc->wMaxSegmentSize);
+		else if (ctx->mbim_desc != NULL)
+			eth_max_sz = le16_to_cpu(ctx->mbim_desc->wMaxSegmentSize);
+		else
+			goto max_dgram_err;
 
 		max_datagram_size = kzalloc(sizeof(*max_datagram_size),
 				GFP_KERNEL);
@@ -352,7 +375,7 @@ size_err:
 				2, 1000);
 		if (err < 0) {
 			pr_debug("GET_MAX_DATAGRAM_SIZE failed, use size=%u\n",
-						CDC_NCM_MIN_DATAGRAM_SIZE);
+				 min_dgram_size);
 		} else {
 			ctx->max_datagram_size =
 				le16_to_cpu(*max_datagram_size);
@@ -361,12 +384,10 @@ size_err:
 					ctx->max_datagram_size = eth_max_sz;
 
 			if (ctx->max_datagram_size > CDC_NCM_MAX_DATAGRAM_SIZE)
-				ctx->max_datagram_size =
-						CDC_NCM_MAX_DATAGRAM_SIZE;
+				ctx->max_datagram_size = CDC_NCM_MAX_DATAGRAM_SIZE;
 
-			if (ctx->max_datagram_size < CDC_NCM_MIN_DATAGRAM_SIZE)
-				ctx->max_datagram_size =
-					CDC_NCM_MIN_DATAGRAM_SIZE;
+			if (ctx->max_datagram_size < min_dgram_size)
+				ctx->max_datagram_size = min_dgram_size;
 
 			/* if value changed, update device */
 			if (ctx->max_datagram_size !=
@@ -387,8 +408,8 @@ size_err:
 	}
 
 max_dgram_err:
-	if (ctx->netdev->mtu != (ctx->max_datagram_size - ETH_HLEN))
-		ctx->netdev->mtu = ctx->max_datagram_size - ETH_HLEN;
+	if (ctx->netdev->mtu != (ctx->max_datagram_size - eth_hlen))
+		ctx->netdev->mtu = ctx->max_datagram_size - eth_hlen;
 
 	return 0;
 }
-- 
1.7.10.4

  parent reply	other threads:[~2012-10-18 20:42 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-10-18 20:40 [PATCH net-next 00/14] Adding a USB CDC MBIM driver Bjørn Mork
2012-10-18 20:40 ` [PATCH net-next 01/14] net: usbnet: make sure the queue lenght is at least 1 Bjørn Mork
2012-10-18 20:40 ` [PATCH net-next 02/14] net: cdc_ncm: use device rx_max value if update failed Bjørn Mork
     [not found]   ` <1350592867-25651-3-git-send-email-bjorn-yOkvZcmFvRU@public.gmane.org>
2012-10-18 21:45     ` Oliver Neukum
2012-10-18 22:09       ` Bjørn Mork
2012-10-18 23:30         ` Alexey Orishko
2012-10-19  6:41           ` Bjørn Mork
2012-10-19  9:30             ` Bjørn Mork
     [not found]               ` <871uguvmfy.fsf-lbf33ChDnrE/G1V5fR+Y7Q@public.gmane.org>
2012-10-19 10:01                 ` Alexey Orishko
     [not found]                   ` <CAL_Kpj3QX_bpLh5yX5VXKaqq+TSO9+aVxt+1TrU9e1BamKdFkA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2012-10-19 10:30                     ` Bjørn Mork
     [not found]                       ` <87vce6u52w.fsf-lbf33ChDnrE/G1V5fR+Y7Q@public.gmane.org>
2012-10-19 11:36                         ` [RFC] net: cdc_ncm: workaround NTB input size firmware bug Bjørn Mork
2012-10-19 12:18                     ` [PATCH net-next 02/14] net: cdc_ncm: use device rx_max value if update failed Bjørn Mork
     [not found]                       ` <878vb2u03g.fsf-lbf33ChDnrE/G1V5fR+Y7Q@public.gmane.org>
2012-10-19 13:53                         ` Alexey Orishko
     [not found]                           ` <CAL_Kpj3tT6qfcD-Tpeqgof-k-PX-EPv_cMFo_NeEdLHfyN8Qfw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2012-10-19 14:09                             ` Bjørn Mork
2012-10-18 20:40 ` Bjørn Mork [this message]
2012-10-18 20:40 ` [PATCH net-next 06/14] net: cdc_ncm: process chained NDPs Bjørn Mork
2012-10-18 20:41 ` [PATCH net-next 08/14] net: cdc_ncm: refactoring for tx multiplexing Bjørn Mork
2012-10-18 20:41 ` [PATCH net-next 11/14] net: cdc_mbim: build the MBIM driver Bjørn Mork
2012-10-18 20:41 ` [PATCH net-next 12/14] net: cdc_ncm: do not bind to NCM compatible MBIM devices Bjørn Mork
     [not found] ` <1350592867-25651-1-git-send-email-bjorn-yOkvZcmFvRU@public.gmane.org>
2012-10-18 20:40   ` [PATCH net-next 03/14] USB: cdc: add MBIM constants and structures Bjørn Mork
     [not found]     ` <1350592867-25651-4-git-send-email-bjorn-yOkvZcmFvRU@public.gmane.org>
2012-10-18 21:14       ` Greg Kroah-Hartman
2012-10-18 20:40   ` [PATCH net-next 05/14] net: cdc_ncm: refactor bind preparing for MBIM support Bjørn Mork
2012-10-18 20:41   ` [PATCH net-next 07/14] net: cdc_ncm: splitting rx_fixup for code reuse Bjørn Mork
2012-10-18 20:41   ` [PATCH net-next 09/14] net: cdc_ncm: export shared symbols and definitions Bjørn Mork
2012-10-18 20:41   ` [PATCH net-next 10/14] net: cdc_mbim: adding MBIM driver Bjørn Mork
2012-10-18 20:41   ` [PATCH net-next 13/14] net: cdc_ncm: map MBIM IPS SessionID to VLAN ID Bjørn Mork
2012-10-18 21:04   ` [PATCH net-next 00/14] Adding a USB CDC MBIM driver David Miller
2012-10-18 21:08     ` Bjørn Mork
2012-10-18 20:41 ` [PATCH net-next 14/14] net: cdc_mbim: Device Service Stream support Bjørn Mork
2012-10-18 21:16 ` [PATCH net-next 00/14] Adding a USB CDC MBIM driver Greg Kroah-Hartman

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1350592867-25651-5-git-send-email-bjorn@mork.no \
    --to=bjorn@mork.no \
    --cc=aleksander@lanedo.com \
    --cc=alexey.orishko@gmail.com \
    --cc=dcbw@redhat.com \
    --cc=fangxiaozhi@huawei.com \
    --cc=gpsuarez2512@gmail.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=gsuarez@smithmicro.com \
    --cc=linux-usb@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=oliver@neukum.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).