diff options
Diffstat (limited to 'drivers/net/usb/cdc_ncm.c')
-rw-r--r-- | drivers/net/usb/cdc_ncm.c | 48 |
1 files changed, 23 insertions, 25 deletions
diff --git a/drivers/net/usb/cdc_ncm.c b/drivers/net/usb/cdc_ncm.c index dbff290ed0e4..d350d2795e10 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; | |||
68 | static int cdc_ncm_setup(struct usbnet *dev) | 68 | static 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; |
@@ -82,22 +81,22 @@ static int cdc_ncm_setup(struct usbnet *dev) | |||
82 | err = usbnet_read_cmd(dev, USB_CDC_GET_NTB_PARAMETERS, | 81 | err = usbnet_read_cmd(dev, USB_CDC_GET_NTB_PARAMETERS, |
83 | USB_TYPE_CLASS | USB_DIR_IN | 82 | USB_TYPE_CLASS | USB_DIR_IN |
84 | |USB_RECIP_INTERFACE, | 83 | |USB_RECIP_INTERFACE, |
85 | 0, iface_no, &ncm_parm, | 84 | 0, iface_no, &ctx->ncm_parm, |
86 | sizeof(ncm_parm)); | 85 | sizeof(ctx->ncm_parm)); |
87 | if (err < 0) { | 86 | if (err < 0) { |
88 | dev_err(&dev->intf->dev, "failed GET_NTB_PARAMETERS\n"); | 87 | dev_err(&dev->intf->dev, "failed GET_NTB_PARAMETERS\n"); |
89 | return err; /* GET_NTB_PARAMETERS is required */ | 88 | return err; /* GET_NTB_PARAMETERS is required */ |
90 | } | 89 | } |
91 | 90 | ||
92 | /* read correct set of parameters according to device mode */ | 91 | /* read correct set of parameters according to device mode */ |
93 | ctx->rx_max = le32_to_cpu(ncm_parm.dwNtbInMaxSize); | 92 | ctx->rx_max = le32_to_cpu(ctx->ncm_parm.dwNtbInMaxSize); |
94 | ctx->tx_max = le32_to_cpu(ncm_parm.dwNtbOutMaxSize); | 93 | ctx->tx_max = le32_to_cpu(ctx->ncm_parm.dwNtbOutMaxSize); |
95 | ctx->tx_remainder = le16_to_cpu(ncm_parm.wNdpOutPayloadRemainder); | 94 | ctx->tx_remainder = le16_to_cpu(ctx->ncm_parm.wNdpOutPayloadRemainder); |
96 | ctx->tx_modulus = le16_to_cpu(ncm_parm.wNdpOutDivisor); | 95 | ctx->tx_modulus = le16_to_cpu(ctx->ncm_parm.wNdpOutDivisor); |
97 | ctx->tx_ndp_modulus = le16_to_cpu(ncm_parm.wNdpOutAlignment); | 96 | ctx->tx_ndp_modulus = le16_to_cpu(ctx->ncm_parm.wNdpOutAlignment); |
98 | /* devices prior to NCM Errata shall set this field to zero */ | 97 | /* devices prior to NCM Errata shall set this field to zero */ |
99 | ctx->tx_max_datagrams = le16_to_cpu(ncm_parm.wNtbOutMaxDatagrams); | 98 | ctx->tx_max_datagrams = le16_to_cpu(ctx->ncm_parm.wNtbOutMaxDatagrams); |
100 | ntb_fmt_supported = le16_to_cpu(ncm_parm.bmNtbFormatsSupported); | 99 | ntb_fmt_supported = le16_to_cpu(ctx->ncm_parm.bmNtbFormatsSupported); |
101 | 100 | ||
102 | /* there are some minor differences in NCM and MBIM defaults */ | 101 | /* there are some minor differences in NCM and MBIM defaults */ |
103 | if (cdc_ncm_comm_intf_is_mbim(ctx->control->cur_altsetting)) { | 102 | if (cdc_ncm_comm_intf_is_mbim(ctx->control->cur_altsetting)) { |
@@ -146,7 +145,7 @@ static int cdc_ncm_setup(struct usbnet *dev) | |||
146 | } | 145 | } |
147 | 146 | ||
148 | /* inform device about NTB input size changes */ | 147 | /* inform device about NTB input size changes */ |
149 | if (ctx->rx_max != le32_to_cpu(ncm_parm.dwNtbInMaxSize)) { | 148 | if (ctx->rx_max != le32_to_cpu(ctx->ncm_parm.dwNtbInMaxSize)) { |
150 | __le32 dwNtbInMaxSize = cpu_to_le32(ctx->rx_max); | 149 | __le32 dwNtbInMaxSize = cpu_to_le32(ctx->rx_max); |
151 | 150 | ||
152 | err = usbnet_write_cmd(dev, USB_CDC_SET_NTB_INPUT_SIZE, | 151 | err = usbnet_write_cmd(dev, USB_CDC_SET_NTB_INPUT_SIZE, |
@@ -162,14 +161,6 @@ static int cdc_ncm_setup(struct usbnet *dev) | |||
162 | dev_dbg(&dev->intf->dev, "Using default maximum transmit length=%d\n", | 161 | dev_dbg(&dev->intf->dev, "Using default maximum transmit length=%d\n", |
163 | CDC_NCM_NTB_MAX_SIZE_TX); | 162 | CDC_NCM_NTB_MAX_SIZE_TX); |
164 | ctx->tx_max = CDC_NCM_NTB_MAX_SIZE_TX; | 163 | ctx->tx_max = CDC_NCM_NTB_MAX_SIZE_TX; |
165 | |||
166 | /* Adding a pad byte here simplifies the handling in | ||
167 | * cdc_ncm_fill_tx_frame, by making tx_max always | ||
168 | * represent the real skb max size. | ||
169 | */ | ||
170 | if (ctx->tx_max % usb_maxpacket(dev->udev, dev->out, 1) == 0) | ||
171 | ctx->tx_max++; | ||
172 | |||
173 | } | 164 | } |
174 | 165 | ||
175 | /* | 166 | /* |
@@ -439,6 +430,10 @@ advance: | |||
439 | goto error2; | 430 | goto error2; |
440 | } | 431 | } |
441 | 432 | ||
433 | /* initialize data interface */ | ||
434 | if (cdc_ncm_setup(dev)) | ||
435 | goto error2; | ||
436 | |||
442 | /* configure data interface */ | 437 | /* configure data interface */ |
443 | temp = usb_set_interface(dev->udev, iface_no, data_altsetting); | 438 | temp = usb_set_interface(dev->udev, iface_no, data_altsetting); |
444 | if (temp) { | 439 | if (temp) { |
@@ -453,12 +448,6 @@ advance: | |||
453 | goto error2; | 448 | goto error2; |
454 | } | 449 | } |
455 | 450 | ||
456 | /* initialize data interface */ | ||
457 | if (cdc_ncm_setup(dev)) { | ||
458 | dev_dbg(&intf->dev, "cdc_ncm_setup() failed\n"); | ||
459 | goto error2; | ||
460 | } | ||
461 | |||
462 | usb_set_intfdata(ctx->data, dev); | 451 | usb_set_intfdata(ctx->data, dev); |
463 | usb_set_intfdata(ctx->control, dev); | 452 | usb_set_intfdata(ctx->control, dev); |
464 | 453 | ||
@@ -475,6 +464,15 @@ advance: | |||
475 | dev->hard_mtu = ctx->tx_max; | 464 | dev->hard_mtu = ctx->tx_max; |
476 | dev->rx_urb_size = ctx->rx_max; | 465 | dev->rx_urb_size = ctx->rx_max; |
477 | 466 | ||
467 | /* cdc_ncm_setup will override dwNtbOutMaxSize if it is | ||
468 | * outside the sane range. Adding a pad byte here if necessary | ||
469 | * simplifies the handling in cdc_ncm_fill_tx_frame, making | ||
470 | * tx_max always represent the real skb max size. | ||
471 | */ | ||
472 | if (ctx->tx_max != le32_to_cpu(ctx->ncm_parm.dwNtbOutMaxSize) && | ||
473 | ctx->tx_max % usb_maxpacket(dev->udev, dev->out, 1) == 0) | ||
474 | ctx->tx_max++; | ||
475 | |||
478 | return 0; | 476 | return 0; |
479 | 477 | ||
480 | error2: | 478 | error2: |