From: "Bjørn Mork" <bjorn-yOkvZcmFvRU@public.gmane.org>
To: <netdev-u79uwXL29TY76Z2rM5mHXA@public.gmane.org>
Cc: linux-usb-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
"Alexey Orishko"
<alexey.orishko-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>,
"Oliver Neukum" <oliver-GvhC2dPhHPQdnm+yROfE0A@public.gmane.org>,
"Enrico Mioso"
<mrkiko.rs-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>,
"David Laight"
<David.Laight-ZS65k/vG3HxXrIkS9f7CXA@public.gmane.org>,
"Bjørn Mork" <bjorn-yOkvZcmFvRU@public.gmane.org>
Subject: [PATCH net-next 01/11] net: cdc_ncm: split out rx_max/tx_max update of setup
Date: Sat, 10 May 2014 17:41:39 +0200 [thread overview]
Message-ID: <1399736509-1159-2-git-send-email-bjorn@mork.no> (raw)
In-Reply-To: <1399736509-1159-1-git-send-email-bjorn-yOkvZcmFvRU@public.gmane.org>
Split out the part of setup dealing with updating the rx_max
and tx_max buffer sizes so that this code can be reused for
dynamically updating the limits.
Signed-off-by: Bjørn Mork <bjorn-yOkvZcmFvRU@public.gmane.org>
---
drivers/net/usb/cdc_ncm.c | 81 +++++++++++++++++++++++++++++------------------
1 file changed, 50 insertions(+), 31 deletions(-)
diff --git a/drivers/net/usb/cdc_ncm.c b/drivers/net/usb/cdc_ncm.c
index 549dbac710ed..87a32edf7ea5 100644
--- a/drivers/net/usb/cdc_ncm.c
+++ b/drivers/net/usb/cdc_ncm.c
@@ -65,6 +65,54 @@ static void cdc_ncm_tx_timeout_start(struct cdc_ncm_ctx *ctx);
static enum hrtimer_restart cdc_ncm_tx_timer_cb(struct hrtimer *hr_timer);
static struct usb_driver cdc_ncm_driver;
+/* handle rx_max and tx_max changes */
+static void cdc_ncm_update_rxtx_max(struct usbnet *dev, u32 new_rx, u32 new_tx)
+{
+ struct cdc_ncm_ctx *ctx = (struct cdc_ncm_ctx *)dev->data[0];
+ u8 iface_no = ctx->control->cur_altsetting->desc.bInterfaceNumber;
+ u32 val, max, min;
+
+ /* clamp new_rx to sane values */
+ min = min_t(u32, USB_CDC_NCM_NTB_MIN_IN_SIZE, le32_to_cpu(ctx->ncm_parm.dwNtbInMaxSize));
+ max = min_t(u32, CDC_NCM_NTB_MAX_SIZE_RX, le32_to_cpu(ctx->ncm_parm.dwNtbInMaxSize));
+
+ val = clamp_t(u32, new_rx, min, max);
+ if (val != new_rx) {
+ dev_dbg(&dev->intf->dev, "rx_max must be in the [%u, %u] range. Using %u\n",
+ min, max, val);
+ }
+
+ /* inform device about NTB input size changes */
+ if (val != ctx->rx_max) {
+ __le32 dwNtbInMaxSize = cpu_to_le32(val);
+
+ dev_info(&dev->intf->dev, "setting rx_max = %u\n", val);
+ if (usbnet_write_cmd(dev, USB_CDC_SET_NTB_INPUT_SIZE,
+ USB_TYPE_CLASS | USB_DIR_OUT
+ | USB_RECIP_INTERFACE,
+ 0, iface_no, &dwNtbInMaxSize, 4) < 0)
+ dev_dbg(&dev->intf->dev, "Setting NTB Input Size failed\n");
+ else
+ ctx->rx_max = val;
+ }
+
+ /* clamp new_tx to sane values */
+ min = CDC_NCM_MIN_HDR_SIZE + ctx->max_datagram_size;
+ max = min_t(u32, CDC_NCM_NTB_MAX_SIZE_TX, le32_to_cpu(ctx->ncm_parm.dwNtbOutMaxSize));
+
+ /* some devices set dwNtbOutMaxSize too low for the above default */
+ min = min(min, max);
+
+ val = clamp_t(u32, new_tx, min, max);
+ if (val != new_tx) {
+ dev_dbg(&dev->intf->dev, "tx_max must be in the [%u, %u] range. Using %u\n",
+ min, max, val);
+ }
+ if (val != ctx->tx_max)
+ dev_info(&dev->intf->dev, "setting tx_max = %u\n", val);
+ ctx->tx_max = val;
+}
+
static int cdc_ncm_setup(struct usbnet *dev)
{
struct cdc_ncm_ctx *ctx = (struct cdc_ncm_ctx *)dev->data[0];
@@ -132,37 +180,8 @@ static int cdc_ncm_setup(struct usbnet *dev)
(ctx->tx_max_datagrams > CDC_NCM_DPT_DATAGRAMS_MAX))
ctx->tx_max_datagrams = CDC_NCM_DPT_DATAGRAMS_MAX;
- /* verify maximum size of received NTB in bytes */
- if (ctx->rx_max < USB_CDC_NCM_NTB_MIN_IN_SIZE) {
- dev_dbg(&dev->intf->dev, "Using min receive length=%d\n",
- USB_CDC_NCM_NTB_MIN_IN_SIZE);
- ctx->rx_max = USB_CDC_NCM_NTB_MIN_IN_SIZE;
- }
-
- if (ctx->rx_max > CDC_NCM_NTB_MAX_SIZE_RX) {
- dev_dbg(&dev->intf->dev, "Using default maximum receive length=%d\n",
- CDC_NCM_NTB_MAX_SIZE_RX);
- ctx->rx_max = CDC_NCM_NTB_MAX_SIZE_RX;
- }
-
- /* inform device about NTB input size changes */
- if (ctx->rx_max != le32_to_cpu(ctx->ncm_parm.dwNtbInMaxSize)) {
- __le32 dwNtbInMaxSize = cpu_to_le32(ctx->rx_max);
-
- err = usbnet_write_cmd(dev, USB_CDC_SET_NTB_INPUT_SIZE,
- USB_TYPE_CLASS | USB_DIR_OUT
- | USB_RECIP_INTERFACE,
- 0, iface_no, &dwNtbInMaxSize, 4);
- if (err < 0)
- dev_dbg(&dev->intf->dev, "Setting NTB Input Size failed\n");
- }
next prev parent reply other threads:[~2014-05-10 15:41 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-05-10 15:41 [PATCH net-next 00/11] cdc_ncm: add buffer tuning and stats using ethtool Bjørn Mork
2014-05-10 15:41 ` [PATCH net-next 02/11] net: cdc_ncm: factor out one-time device initialization Bjørn Mork
2014-05-10 15:41 ` [PATCH net-next 03/11] net: cdc_ncm: split .bind " Bjørn Mork
2014-05-10 15:41 ` [PATCH net-next 05/11] net: cdc_ncm: use ethtool to tune coalescing settings Bjørn Mork
2014-05-10 15:41 ` [PATCH net-next 06/11] net: cdc_ncm: use true max dgram count for header estimates Bjørn Mork
2014-05-10 15:41 ` [PATCH net-next 07/11] net: cdc_ncm: set reasonable padding limits Bjørn Mork
2014-05-10 15:41 ` [PATCH net-next 08/11] net: cdc_ncm/cdc_mbim: adding NCM protocol statiscics Bjørn Mork
2014-05-10 15:41 ` [PATCH net-next 09/11] net: cdc_ncm: use sane defaults for rx/tx buffers Bjørn Mork
[not found] ` <1399736509-1159-1-git-send-email-bjorn-yOkvZcmFvRU@public.gmane.org>
2014-05-10 15:41 ` Bjørn Mork [this message]
2014-05-13 8:09 ` [PATCH net-next 01/11] net: cdc_ncm: split out rx_max/tx_max update of setup Oliver Neukum
2014-05-13 8:49 ` Bjørn Mork
2014-05-13 9:09 ` Oliver Neukum
[not found] ` <1399972165.8278.11.camel-B2T3B9s34ElbnMAlSieJcQ@public.gmane.org>
2014-05-13 9:25 ` Bjørn Mork
2014-05-13 11:07 ` Oliver Neukum
2014-05-10 15:41 ` [PATCH net-next 04/11] net: cdc_ncm: support rx_max/tx_max updates when running Bjørn Mork
2014-05-10 15:41 ` [PATCH net-next 10/11] net: cdc_ncm: fix argument alignment Bjørn Mork
2014-05-10 15:41 ` [PATCH net-next 11/11] net: cdc_ncm: remove redundant "disconnected" flag Bjørn Mork
2014-05-11 9:14 ` Enrico Mioso (@atlantide)
-- strict thread matches above, loose matches on Subject: below --
2014-05-13 9:40 [PATCH net-next 01/11] net: cdc_ncm: split out rx_max/tx_max update of setup Enrico Mioso
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=1399736509-1159-2-git-send-email-bjorn@mork.no \
--to=bjorn-yokvzcmfvru@public.gmane.org \
--cc=David.Laight-ZS65k/vG3HxXrIkS9f7CXA@public.gmane.org \
--cc=alexey.orishko-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org \
--cc=linux-usb-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=mrkiko.rs-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org \
--cc=netdev-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=oliver-GvhC2dPhHPQdnm+yROfE0A@public.gmane.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).