From 24134b26ba1051df06c4f722d2f6b0301f83aff2 Mon Sep 17 00:00:00 2001 From: xerox_lin Date: Thu, 4 Sep 2014 16:01:59 +0800 Subject: [PATCH] USB: gadget: rndis: Add module parameter for DL max packets per xfer Currently DL aggregation is supported in RNDIS driver and is set to 3 by default. And there is no support to change downlink maximum packets per transfer at runtime through module parameter. Hence add module parameter for DL maximum packets per transfer to change it at runtime. echo 6 > /sys/module/g_android/parameters/rndis_dl_max_pkt_per_xfer To disable DL aggregation during runtime, echo 1 > /sys/module/g_android/parameters/rndis_dl_max_pkt_per_xfer Change-Id: I3a1d0bc97358e2b6f233df7ae8725fb507de50db Signed-off-by: Xerox Lin Signed-off-by: Vijayavardhan Vennapusa --- drivers/usb/gadget/function/f_rndis.c | 11 ++++++----- drivers/usb/gadget/function/u_ether.c | 6 ++++-- drivers/usb/gadget/function/u_ether.h | 3 +-- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/drivers/usb/gadget/function/f_rndis.c b/drivers/usb/gadget/function/f_rndis.c index 635bbbbd0639..2758522180f3 100644 --- a/drivers/usb/gadget/function/f_rndis.c +++ b/drivers/usb/gadget/function/f_rndis.c @@ -70,10 +70,10 @@ * - MS-Windows drivers sometimes emit undocumented requests. */ -static bool rndis_multipacket_dl_disable; -module_param(rndis_multipacket_dl_disable, bool, S_IRUGO|S_IWUSR); -MODULE_PARM_DESC(rndis_multipacket_dl_disable, - "Disable RNDIS Multi-packet support in DownLink"); +static unsigned int rndis_dl_max_pkt_per_xfer = 3; +module_param(rndis_dl_max_pkt_per_xfer, uint, S_IRUGO | S_IWUSR); +MODULE_PARM_DESC(rndis_dl_max_pkt_per_xfer, + "Maximum packets per transfer for DL aggregation"); static unsigned int rndis_ul_max_pkt_per_xfer = 3; module_param(rndis_ul_max_pkt_per_xfer, uint, S_IRUGO | S_IWUSR); @@ -480,7 +480,7 @@ static void rndis_command_complete(struct usb_ep *ep, struct usb_request *req) __func__, buf->MaxTransferSize, rndis->port.multi_pkt_xfer ? "enabled" : "disabled"); - if (rndis_multipacket_dl_disable) + if (rndis_dl_max_pkt_per_xfer <= 1) rndis->port.multi_pkt_xfer = 0; } // spin_unlock(&dev->lock); @@ -1006,6 +1006,7 @@ static struct usb_function *rndis_alloc(struct usb_function_instance *fi) rndis->port.wrap = rndis_add_header; rndis->port.unwrap = rndis_rm_hdr; rndis->port.ul_max_pkts_per_xfer = rndis_ul_max_pkt_per_xfer; + rndis->port.dl_max_pkts_per_xfer = rndis_dl_max_pkt_per_xfer; rndis->port.func.name = "rndis"; /* descriptors are per-instance copies */ diff --git a/drivers/usb/gadget/function/u_ether.c b/drivers/usb/gadget/function/u_ether.c index 69bf03e04603..e39880a654cc 100644 --- a/drivers/usb/gadget/function/u_ether.c +++ b/drivers/usb/gadget/function/u_ether.c @@ -79,6 +79,7 @@ struct eth_dev { unsigned header_len; unsigned ul_max_pkts_per_xfer; + unsigned dl_max_pkts_per_xfer; struct sk_buff *(*wrap)(struct gether *, struct sk_buff *skb); int (*unwrap)(struct gether *, struct sk_buff *skb, @@ -581,7 +582,7 @@ static void alloc_tx_buffer(struct eth_dev *dev) struct list_head *act; struct usb_request *req; - dev->tx_req_bufsize = (TX_SKB_HOLD_THRESHOLD * + dev->tx_req_bufsize = (dev->dl_max_pkts_per_xfer * (dev->net->mtu + sizeof(struct ethhdr) /* size of rndis_packet_msg_type */ @@ -699,7 +700,7 @@ static netdev_tx_t eth_start_xmit(struct sk_buff *skb, dev_kfree_skb_any(skb); spin_lock_irqsave(&dev->req_lock, flags); - if (dev->tx_skb_hold_count < TX_SKB_HOLD_THRESHOLD) { + if (dev->tx_skb_hold_count < dev->dl_max_pkts_per_xfer) { if (dev->no_tx_req_used > TX_REQ_THRESHOLD) { list_add(&req->list, &dev->tx_reqs); spin_unlock_irqrestore(&dev->req_lock, flags); @@ -1248,6 +1249,7 @@ struct net_device *gether_connect(struct gether *link) dev->unwrap = link->unwrap; dev->wrap = link->wrap; dev->ul_max_pkts_per_xfer = link->ul_max_pkts_per_xfer; + dev->dl_max_pkts_per_xfer = link->dl_max_pkts_per_xfer; spin_lock(&dev->lock); dev->tx_skb_hold_count = 0; diff --git a/drivers/usb/gadget/function/u_ether.h b/drivers/usb/gadget/function/u_ether.h index 7914b4b1ce6c..e9fd14b46102 100644 --- a/drivers/usb/gadget/function/u_ether.h +++ b/drivers/usb/gadget/function/u_ether.h @@ -74,8 +74,7 @@ struct gether { u32 fixed_out_len; u32 fixed_in_len; unsigned ul_max_pkts_per_xfer; -/* Max number of SKB packets to be used to create Multi Packet RNDIS */ -#define TX_SKB_HOLD_THRESHOLD 3 + unsigned dl_max_pkts_per_xfer; bool multi_pkt_xfer; bool supports_multi_frame; struct sk_buff *(*wrap)(struct gether *port, -- 2.34.1