aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/usb/cdc_ncm.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/net/usb/cdc_ncm.c')
-rw-r--r--drivers/net/usb/cdc_ncm.c48
1 files changed, 23 insertions, 25 deletions
diff --git a/drivers/net/usb/cdc_ncm.c b/drivers/net/usb/cdc_ncm.c
index e8711a8cfa01..549dbac710ed 100644
--- a/drivers/net/usb/cdc_ncm.c
+++ b/drivers/net/usb/cdc_ncm.c
@@ -68,7 +68,6 @@ static struct usb_driver cdc_ncm_driver;
68static int cdc_ncm_setup(struct usbnet *dev) 68static int cdc_ncm_setup(struct usbnet *dev)
69{ 69{
70 struct cdc_ncm_ctx *ctx = (struct cdc_ncm_ctx *)dev->data[0]; 70 struct cdc_ncm_ctx *ctx = (struct cdc_ncm_ctx *)dev->data[0];
71 struct usb_cdc_ncm_ntb_parameters ncm_parm;
72 u32 val; 71 u32 val;
73 u8 flags; 72 u8 flags;
74 u8 iface_no; 73 u8 iface_no;
@@ -83,22 +82,22 @@ static int cdc_ncm_setup(struct usbnet *dev)
83 err = usbnet_read_cmd(dev, USB_CDC_GET_NTB_PARAMETERS, 82 err = usbnet_read_cmd(dev, USB_CDC_GET_NTB_PARAMETERS,
84 USB_TYPE_CLASS | USB_DIR_IN 83 USB_TYPE_CLASS | USB_DIR_IN
85 |USB_RECIP_INTERFACE, 84 |USB_RECIP_INTERFACE,
86 0, iface_no, &ncm_parm, 85 0, iface_no, &ctx->ncm_parm,
87 sizeof(ncm_parm)); 86 sizeof(ctx->ncm_parm));
88 if (err < 0) { 87 if (err < 0) {
89 dev_err(&dev->intf->dev, "failed GET_NTB_PARAMETERS\n"); 88 dev_err(&dev->intf->dev, "failed GET_NTB_PARAMETERS\n");
90 return err; /* GET_NTB_PARAMETERS is required */ 89 return err; /* GET_NTB_PARAMETERS is required */
91 } 90 }
92 91
93 /* read correct set of parameters according to device mode */ 92 /* read correct set of parameters according to device mode */
94 ctx->rx_max = le32_to_cpu(ncm_parm.dwNtbInMaxSize); 93 ctx->rx_max = le32_to_cpu(ctx->ncm_parm.dwNtbInMaxSize);
95 ctx->tx_max = le32_to_cpu(ncm_parm.dwNtbOutMaxSize); 94 ctx->tx_max = le32_to_cpu(ctx->ncm_parm.dwNtbOutMaxSize);
96 ctx->tx_remainder = le16_to_cpu(ncm_parm.wNdpOutPayloadRemainder); 95 ctx->tx_remainder = le16_to_cpu(ctx->ncm_parm.wNdpOutPayloadRemainder);
97 ctx->tx_modulus = le16_to_cpu(ncm_parm.wNdpOutDivisor); 96 ctx->tx_modulus = le16_to_cpu(ctx->ncm_parm.wNdpOutDivisor);
98 ctx->tx_ndp_modulus = le16_to_cpu(ncm_parm.wNdpOutAlignment); 97 ctx->tx_ndp_modulus = le16_to_cpu(ctx->ncm_parm.wNdpOutAlignment);
99 /* devices prior to NCM Errata shall set this field to zero */ 98 /* devices prior to NCM Errata shall set this field to zero */
100 ctx->tx_max_datagrams = le16_to_cpu(ncm_parm.wNtbOutMaxDatagrams); 99 ctx->tx_max_datagrams = le16_to_cpu(ctx->ncm_parm.wNtbOutMaxDatagrams);
101 ntb_fmt_supported = le16_to_cpu(ncm_parm.bmNtbFormatsSupported); 100 ntb_fmt_supported = le16_to_cpu(ctx->ncm_parm.bmNtbFormatsSupported);
102 101
103 /* there are some minor differences in NCM and MBIM defaults */ 102 /* there are some minor differences in NCM and MBIM defaults */
104 if (cdc_ncm_comm_intf_is_mbim(ctx->control->cur_altsetting)) { 103 if (cdc_ncm_comm_intf_is_mbim(ctx->control->cur_altsetting)) {
@@ -147,7 +146,7 @@ static int cdc_ncm_setup(struct usbnet *dev)
147 } 146 }
148 147
149 /* inform device about NTB input size changes */ 148 /* inform device about NTB input size changes */
150 if (ctx->rx_max != le32_to_cpu(ncm_parm.dwNtbInMaxSize)) { 149 if (ctx->rx_max != le32_to_cpu(ctx->ncm_parm.dwNtbInMaxSize)) {
151 __le32 dwNtbInMaxSize = cpu_to_le32(ctx->rx_max); 150 __le32 dwNtbInMaxSize = cpu_to_le32(ctx->rx_max);
152 151
153 err = usbnet_write_cmd(dev, USB_CDC_SET_NTB_INPUT_SIZE, 152 err = usbnet_write_cmd(dev, USB_CDC_SET_NTB_INPUT_SIZE,
@@ -163,14 +162,6 @@ static int cdc_ncm_setup(struct usbnet *dev)
163 dev_dbg(&dev->intf->dev, "Using default maximum transmit length=%d\n", 162 dev_dbg(&dev->intf->dev, "Using default maximum transmit length=%d\n",
164 CDC_NCM_NTB_MAX_SIZE_TX); 163 CDC_NCM_NTB_MAX_SIZE_TX);
165 ctx->tx_max = CDC_NCM_NTB_MAX_SIZE_TX; 164 ctx->tx_max = CDC_NCM_NTB_MAX_SIZE_TX;
166
167 /* Adding a pad byte here simplifies the handling in
168 * cdc_ncm_fill_tx_frame, by making tx_max always
169 * represent the real skb max size.
170 */
171 if (ctx->tx_max % usb_maxpacket(dev->udev, dev->out, 1) == 0)
172 ctx->tx_max++;
173
174 } 165 }
175 166
176 /* 167 /*
@@ -456,6 +447,10 @@ advance:
456 goto error2; 447 goto error2;
457 } 448 }
458 449
450 /* initialize data interface */
451 if (cdc_ncm_setup(dev))
452 goto error2;
453
459 /* configure data interface */ 454 /* configure data interface */
460 temp = usb_set_interface(dev->udev, iface_no, data_altsetting); 455 temp = usb_set_interface(dev->udev, iface_no, data_altsetting);
461 if (temp) { 456 if (temp) {
@@ -470,12 +465,6 @@ advance:
470 goto error2; 465 goto error2;
471 } 466 }
472 467
473 /* initialize data interface */
474 if (cdc_ncm_setup(dev)) {
475 dev_dbg(&intf->dev, "cdc_ncm_setup() failed\n");
476 goto error2;
477 }
478
479 usb_set_intfdata(ctx->data, dev); 468 usb_set_intfdata(ctx->data, dev);
480 usb_set_intfdata(ctx->control, dev); 469 usb_set_intfdata(ctx->control, dev);
481 470
@@ -492,6 +481,15 @@ advance:
492 dev->hard_mtu = ctx->tx_max; 481 dev->hard_mtu = ctx->tx_max;
493 dev->rx_urb_size = ctx->rx_max; 482 dev->rx_urb_size = ctx->rx_max;
494 483
484 /* cdc_ncm_setup will override dwNtbOutMaxSize if it is
485 * outside the sane range. Adding a pad byte here if necessary
486 * simplifies the handling in cdc_ncm_fill_tx_frame, making
487 * tx_max always represent the real skb max size.
488 */
489 if (ctx->tx_max != le32_to_cpu(ctx->ncm_parm.dwNtbOutMaxSize) &&
490 ctx->tx_max % usb_maxpacket(dev->udev, dev->out, 1) == 0)
491 ctx->tx_max++;
492
495 return 0; 493 return 0;
496 494
497error2: 495error2: