aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/usb
diff options
context:
space:
mode:
authorAlexey Orishko <alexey.orishko@gmail.com>2012-03-14 07:26:11 -0400
committerDavid S. Miller <davem@davemloft.net>2012-03-16 05:08:36 -0400
commit3f658cde9401bd45429ee720cf2c69f0bc5547b9 (patch)
tree369600921781f515c587853aa7c7b7cacd1d6884 /drivers/net/usb
parentc84ff1d6dff38058a5bd20cb633d13a0f685788a (diff)
cdc_ncm: fix MTU and max_datagram_size handling
Changes/fixes: - inform device if max_datagram_size was changed by host - max_datagram_size can't be bigger MTU in ETH func descr - fix constants definitions to enable running CAIF service over NCM Tested on Intel/ARM. Reviewed-by: Sjur Brændeland <sjur.brandeland@stericsson.com> Tested-by: Dmitry Tarnyagin <Dmitry.Tarnyagin@stericsson.com> Signed-off-by: Alexey Orishko <alexey.orishko@stericsson.com> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'drivers/net/usb')
-rw-r--r--drivers/net/usb/cdc_ncm.c34
1 files changed, 16 insertions, 18 deletions
diff --git a/drivers/net/usb/cdc_ncm.c b/drivers/net/usb/cdc_ncm.c
index a8e2a62c2958..f8f194658412 100644
--- a/drivers/net/usb/cdc_ncm.c
+++ b/drivers/net/usb/cdc_ncm.c
@@ -58,8 +58,8 @@
58#define USB_CDC_NCM_NDP16_LENGTH_MIN 0x10 58#define USB_CDC_NCM_NDP16_LENGTH_MIN 0x10
59 59
60/* Maximum NTB length */ 60/* Maximum NTB length */
61#define CDC_NCM_NTB_MAX_SIZE_TX 16384 /* bytes */ 61#define CDC_NCM_NTB_MAX_SIZE_TX 32768 /* bytes */
62#define CDC_NCM_NTB_MAX_SIZE_RX 16384 /* bytes */ 62#define CDC_NCM_NTB_MAX_SIZE_RX 32768 /* bytes */
63 63
64/* Minimum value for MaxDatagramSize, ch. 6.2.9 */ 64/* Minimum value for MaxDatagramSize, ch. 6.2.9 */
65#define CDC_NCM_MIN_DATAGRAM_SIZE 1514 /* bytes */ 65#define CDC_NCM_MIN_DATAGRAM_SIZE 1514 /* bytes */
@@ -67,13 +67,13 @@
67#define CDC_NCM_MIN_TX_PKT 512 /* bytes */ 67#define CDC_NCM_MIN_TX_PKT 512 /* bytes */
68 68
69/* Default value for MaxDatagramSize */ 69/* Default value for MaxDatagramSize */
70#define CDC_NCM_MAX_DATAGRAM_SIZE 2048 /* bytes */ 70#define CDC_NCM_MAX_DATAGRAM_SIZE 8192 /* bytes */
71 71
72/* 72/*
73 * Maximum amount of datagrams in NCM Datagram Pointer Table, not counting 73 * Maximum amount of datagrams in NCM Datagram Pointer Table, not counting
74 * the last NULL entry. Any additional datagrams in NTB would be discarded. 74 * the last NULL entry. Any additional datagrams in NTB would be discarded.
75 */ 75 */
76#define CDC_NCM_DPT_DATAGRAMS_MAX 32 76#define CDC_NCM_DPT_DATAGRAMS_MAX 40
77 77
78/* Maximum amount of IN datagrams in NTB */ 78/* Maximum amount of IN datagrams in NTB */
79#define CDC_NCM_DPT_DATAGRAMS_IN_MAX 0 /* unlimited */ 79#define CDC_NCM_DPT_DATAGRAMS_IN_MAX 0 /* unlimited */
@@ -366,27 +366,25 @@ size_err:
366 if (err < 0) { 366 if (err < 0) {
367 pr_debug("GET_MAX_DATAGRAM_SIZE failed, use size=%u\n", 367 pr_debug("GET_MAX_DATAGRAM_SIZE failed, use size=%u\n",
368 CDC_NCM_MIN_DATAGRAM_SIZE); 368 CDC_NCM_MIN_DATAGRAM_SIZE);
369 kfree(max_datagram_size);
370 } else { 369 } else {
371 ctx->max_datagram_size = 370 ctx->max_datagram_size =
372 le16_to_cpu(*max_datagram_size); 371 le16_to_cpu(*max_datagram_size);
373 /* Check Eth descriptor value */ 372 /* Check Eth descriptor value */
374 if (eth_max_sz < CDC_NCM_MAX_DATAGRAM_SIZE) { 373 if (ctx->max_datagram_size > eth_max_sz)
375 if (ctx->max_datagram_size > eth_max_sz)
376 ctx->max_datagram_size = eth_max_sz; 374 ctx->max_datagram_size = eth_max_sz;
377 } else { 375
378 if (ctx->max_datagram_size > 376 if (ctx->max_datagram_size > CDC_NCM_MAX_DATAGRAM_SIZE)
379 CDC_NCM_MAX_DATAGRAM_SIZE) 377 ctx->max_datagram_size =
380 ctx->max_datagram_size =
381 CDC_NCM_MAX_DATAGRAM_SIZE; 378 CDC_NCM_MAX_DATAGRAM_SIZE;
382 }
383 379
384 if (ctx->max_datagram_size < CDC_NCM_MIN_DATAGRAM_SIZE) 380 if (ctx->max_datagram_size < CDC_NCM_MIN_DATAGRAM_SIZE)
385 ctx->max_datagram_size = 381 ctx->max_datagram_size =
386 CDC_NCM_MIN_DATAGRAM_SIZE; 382 CDC_NCM_MIN_DATAGRAM_SIZE;
387 383
388 /* if value changed, update device */ 384 /* if value changed, update device */
389 err = usb_control_msg(ctx->udev, 385 if (ctx->max_datagram_size !=
386 le16_to_cpu(*max_datagram_size)) {
387 err = usb_control_msg(ctx->udev,
390 usb_sndctrlpipe(ctx->udev, 0), 388 usb_sndctrlpipe(ctx->udev, 0),
391 USB_CDC_SET_MAX_DATAGRAM_SIZE, 389 USB_CDC_SET_MAX_DATAGRAM_SIZE,
392 USB_TYPE_CLASS | USB_DIR_OUT 390 USB_TYPE_CLASS | USB_DIR_OUT
@@ -394,14 +392,14 @@ size_err:
394 0, 392 0,
395 iface_no, max_datagram_size, 393 iface_no, max_datagram_size,
396 2, 1000); 394 2, 1000);
397 kfree(max_datagram_size); 395 if (err < 0)
398max_dgram_err: 396 pr_debug("SET_MAX_DGRAM_SIZE failed\n");
399 if (err < 0) 397 }
400 pr_debug("SET_MAX_DATAGRAM_SIZE failed\n");
401 } 398 }
402 399 kfree(max_datagram_size);
403 } 400 }
404 401
402max_dgram_err:
405 if (ctx->netdev->mtu != (ctx->max_datagram_size - ETH_HLEN)) 403 if (ctx->netdev->mtu != (ctx->max_datagram_size - ETH_HLEN))
406 ctx->netdev->mtu = ctx->max_datagram_size - ETH_HLEN; 404 ctx->netdev->mtu = ctx->max_datagram_size - ETH_HLEN;
407 405