aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBjørn Mork <bjorn@mork.no>2013-11-01 06:16:45 -0400
committerDavid S. Miller <davem@davemloft.net>2013-11-02 02:02:02 -0400
commit6a9612e2cb22b3fd6a7304dcbf2b4ee1cf2104b2 (patch)
treedd1458d3788822fba831e06cf2e6a1cf3ac9a49a
parentf3028c524a7cd4d97b034fc1f35dcaecb5d6f9d6 (diff)
net: cdc_ncm: remove ncm_parm field
Moving the call to cdc_ncm_setup() after the endpoint setup removes the last remaining reference to ncm_parm outside cdc_ncm_setup. Collecting all the ncm_parm based calculations in cdc_ncm_setup improves readability. Cc: Alexey Orishko <alexey.orishko@gmail.com> Signed-off-by: Bjørn Mork <bjorn@mork.no> Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r--drivers/net/usb/cdc_ncm.c46
-rw-r--r--include/linux/usb/cdc_ncm.h1
2 files changed, 23 insertions, 24 deletions
diff --git a/drivers/net/usb/cdc_ncm.c b/drivers/net/usb/cdc_ncm.c
index fc36a99f8183..4de3a5423e87 100644
--- a/drivers/net/usb/cdc_ncm.c
+++ b/drivers/net/usb/cdc_ncm.c
@@ -83,6 +83,7 @@ cdc_ncm_get_drvinfo(struct net_device *net, struct ethtool_drvinfo *info)
83static u8 cdc_ncm_setup(struct usbnet *dev) 83static u8 cdc_ncm_setup(struct usbnet *dev)
84{ 84{
85 struct cdc_ncm_ctx *ctx = (struct cdc_ncm_ctx *)dev->data[0]; 85 struct cdc_ncm_ctx *ctx = (struct cdc_ncm_ctx *)dev->data[0];
86 struct usb_cdc_ncm_ntb_parameters ncm_parm;
86 u32 val; 87 u32 val;
87 u8 flags; 88 u8 flags;
88 u8 iface_no; 89 u8 iface_no;
@@ -97,22 +98,22 @@ static u8 cdc_ncm_setup(struct usbnet *dev)
97 err = usbnet_read_cmd(dev, USB_CDC_GET_NTB_PARAMETERS, 98 err = usbnet_read_cmd(dev, USB_CDC_GET_NTB_PARAMETERS,
98 USB_TYPE_CLASS | USB_DIR_IN 99 USB_TYPE_CLASS | USB_DIR_IN
99 |USB_RECIP_INTERFACE, 100 |USB_RECIP_INTERFACE,
100 0, iface_no, &ctx->ncm_parm, 101 0, iface_no, &ncm_parm,
101 sizeof(ctx->ncm_parm)); 102 sizeof(ncm_parm));
102 if (err < 0) { 103 if (err < 0) {
103 pr_debug("failed GET_NTB_PARAMETERS\n"); 104 pr_debug("failed GET_NTB_PARAMETERS\n");
104 return 1; 105 return 1;
105 } 106 }
106 107
107 /* read correct set of parameters according to device mode */ 108 /* read correct set of parameters according to device mode */
108 ctx->rx_max = le32_to_cpu(ctx->ncm_parm.dwNtbInMaxSize); 109 ctx->rx_max = le32_to_cpu(ncm_parm.dwNtbInMaxSize);
109 ctx->tx_max = le32_to_cpu(ctx->ncm_parm.dwNtbOutMaxSize); 110 ctx->tx_max = le32_to_cpu(ncm_parm.dwNtbOutMaxSize);
110 ctx->tx_remainder = le16_to_cpu(ctx->ncm_parm.wNdpOutPayloadRemainder); 111 ctx->tx_remainder = le16_to_cpu(ncm_parm.wNdpOutPayloadRemainder);
111 ctx->tx_modulus = le16_to_cpu(ctx->ncm_parm.wNdpOutDivisor); 112 ctx->tx_modulus = le16_to_cpu(ncm_parm.wNdpOutDivisor);
112 ctx->tx_ndp_modulus = le16_to_cpu(ctx->ncm_parm.wNdpOutAlignment); 113 ctx->tx_ndp_modulus = le16_to_cpu(ncm_parm.wNdpOutAlignment);
113 /* devices prior to NCM Errata shall set this field to zero */ 114 /* devices prior to NCM Errata shall set this field to zero */
114 ctx->tx_max_datagrams = le16_to_cpu(ctx->ncm_parm.wNtbOutMaxDatagrams); 115 ctx->tx_max_datagrams = le16_to_cpu(ncm_parm.wNtbOutMaxDatagrams);
115 ntb_fmt_supported = le16_to_cpu(ctx->ncm_parm.bmNtbFormatsSupported); 116 ntb_fmt_supported = le16_to_cpu(ncm_parm.bmNtbFormatsSupported);
116 117
117 eth_hlen = ETH_HLEN; 118 eth_hlen = ETH_HLEN;
118 min_dgram_size = CDC_NCM_MIN_DATAGRAM_SIZE; 119 min_dgram_size = CDC_NCM_MIN_DATAGRAM_SIZE;
@@ -153,7 +154,7 @@ static u8 cdc_ncm_setup(struct usbnet *dev)
153 } 154 }
154 155
155 /* inform device about NTB input size changes */ 156 /* inform device about NTB input size changes */
156 if (ctx->rx_max != le32_to_cpu(ctx->ncm_parm.dwNtbInMaxSize)) { 157 if (ctx->rx_max != le32_to_cpu(ncm_parm.dwNtbInMaxSize)) {
157 __le32 dwNtbInMaxSize = cpu_to_le32(ctx->rx_max); 158 __le32 dwNtbInMaxSize = cpu_to_le32(ctx->rx_max);
158 159
159 err = usbnet_write_cmd(dev, USB_CDC_SET_NTB_INPUT_SIZE, 160 err = usbnet_write_cmd(dev, USB_CDC_SET_NTB_INPUT_SIZE,
@@ -171,6 +172,14 @@ static u8 cdc_ncm_setup(struct usbnet *dev)
171 pr_debug("Using default maximum transmit length=%d\n", 172 pr_debug("Using default maximum transmit length=%d\n",
172 CDC_NCM_NTB_MAX_SIZE_TX); 173 CDC_NCM_NTB_MAX_SIZE_TX);
173 ctx->tx_max = CDC_NCM_NTB_MAX_SIZE_TX; 174 ctx->tx_max = CDC_NCM_NTB_MAX_SIZE_TX;
175
176 /* Adding a pad byte here simplifies the handling in
177 * cdc_ncm_fill_tx_frame, by making tx_max always
178 * represent the real skb max size.
179 */
180 if (ctx->tx_max % usb_maxpacket(dev->udev, dev->out, 1) == 0)
181 ctx->tx_max++;
182
174 } 183 }
175 184
176 /* 185 /*
@@ -473,10 +482,6 @@ advance:
473 if (temp) 482 if (temp)
474 goto error2; 483 goto error2;
475 484
476 /* initialize data interface */
477 if (cdc_ncm_setup(dev))
478 goto error2;
479
480 /* configure data interface */ 485 /* configure data interface */
481 temp = usb_set_interface(dev->udev, iface_no, data_altsetting); 486 temp = usb_set_interface(dev->udev, iface_no, data_altsetting);
482 if (temp) 487 if (temp)
@@ -487,6 +492,10 @@ advance:
487 if (!dev->in || !dev->out || !dev->status) 492 if (!dev->in || !dev->out || !dev->status)
488 goto error2; 493 goto error2;
489 494
495 /* initialize data interface */
496 if (cdc_ncm_setup(dev))
497 goto error2;
498
490 dev->net->ethtool_ops = &cdc_ncm_ethtool_ops; 499 dev->net->ethtool_ops = &cdc_ncm_ethtool_ops;
491 500
492 usb_set_intfdata(ctx->data, dev); 501 usb_set_intfdata(ctx->data, dev);
@@ -501,15 +510,6 @@ advance:
501 510
502 dev->rx_urb_size = ctx->rx_max; 511 dev->rx_urb_size = ctx->rx_max;
503 512
504 /* cdc_ncm_setup will override dwNtbOutMaxSize if it is
505 * outside the sane range. Adding a pad byte here if necessary
506 * simplifies the handling in cdc_ncm_fill_tx_frame, making
507 * tx_max always represent the real skb max size.
508 */
509 if (ctx->tx_max != le32_to_cpu(ctx->ncm_parm.dwNtbOutMaxSize) &&
510 ctx->tx_max % usb_maxpacket(dev->udev, dev->out, 1) == 0)
511 ctx->tx_max++;
512
513 return 0; 513 return 0;
514 514
515error2: 515error2:
diff --git a/include/linux/usb/cdc_ncm.h b/include/linux/usb/cdc_ncm.h
index f14af3dd0cce..89b52a0fe4b9 100644
--- a/include/linux/usb/cdc_ncm.h
+++ b/include/linux/usb/cdc_ncm.h
@@ -88,7 +88,6 @@
88#define cdc_ncm_data_intf_is_mbim(x) ((x)->desc.bInterfaceProtocol == USB_CDC_MBIM_PROTO_NTB) 88#define cdc_ncm_data_intf_is_mbim(x) ((x)->desc.bInterfaceProtocol == USB_CDC_MBIM_PROTO_NTB)
89 89
90struct cdc_ncm_ctx { 90struct cdc_ncm_ctx {
91 struct usb_cdc_ncm_ntb_parameters ncm_parm;
92 struct hrtimer tx_timer; 91 struct hrtimer tx_timer;
93 struct tasklet_struct bh; 92 struct tasklet_struct bh;
94 93