Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit ed045baf authored by Mayank Rana's avatar Mayank Rana
Browse files

usb: gadget: Add support to use usb request buffer size from mbim driver



Some of USB function is having protocol which communicates max usb
transfer size with host. It is required to have same size buffer available
to receive the data. Hence this change adds support with MBIM function
driver which marks usb buffer size for RX transfer based on its
communicated Max Out transfer size to host. This change also adds mod_param
as mbim_ntb_out_size_sys2bam to configure the same if it is required. Same
functionality can be extended to other tethered function driver if it is
required.

Change-Id: I282d77cc1167dd4e29966cdd66e764c7272312fb
Signed-off-by: default avatarMayank Rana <mrana@codeaurora.org>
parent 5bc094e1
Loading
Loading
Loading
Loading
+17 −1
Original line number Diff line number Diff line
@@ -177,6 +177,9 @@ static inline unsigned mbim_bitrate(struct usb_gadget *g)
#define MBIM_NTB_OUT_SIZE_IPA		(0x2000)

#define MBIM_FORMATS_SUPPORTED	USB_CDC_NCM_NTB16_SUPPORTED
static int mbim_ntb_out_size_sys2bam;
module_param(mbim_ntb_out_size_sys2bam, int, S_IRUGO | S_IWUSR);
MODULE_PARM_DESC(mbim_ntb_out_size_sys2bam, "MBIM OUT SIZE for SYS2BAM Mode");

static struct usb_cdc_ncm_ntb_parameters mbim_ntb_parameters = {
	.wLength = sizeof mbim_ntb_parameters,
@@ -1727,6 +1730,7 @@ int mbim_bind_config(struct usb_configuration *c, unsigned portno,
{
	struct f_mbim	*mbim = NULL;
	int status = 0;
	int mbim_out_max_size;

	pr_info("port number %u", portno);

@@ -1793,9 +1797,21 @@ int mbim_bind_config(struct usb_configuration *c, unsigned portno,
		/* For IPA this is proven to give maximum throughput */
		mbim_ntb_parameters.dwNtbInMaxSize =
		cpu_to_le32(NTB_DEFAULT_IN_SIZE_IPA);
		/*
		 * If mbim_ntb_out_size_sys2bam is set, use that value
		 * otherwise use default value.
		 */
		if (mbim_ntb_out_size_sys2bam)
			mbim_out_max_size = mbim_ntb_out_size_sys2bam;
		else
			mbim_out_max_size = MBIM_NTB_OUT_SIZE_IPA;

		mbim_ntb_parameters.dwNtbOutMaxSize =
				cpu_to_le32(MBIM_NTB_OUT_SIZE_IPA);
				cpu_to_le32(mbim_out_max_size);
		/* update rx buffer size to be used by usb rx request buffer */
		mbim->bam_port.rx_buffer_size = mbim_out_max_size;
		mbim_ntb_parameters.wNdpInDivisor = 1;
		pr_debug("MBIM: dwNtbOutMaxSize:%d\n", mbim_out_max_size);
	}

	INIT_LIST_HEAD(&mbim->cpkt_req_q);
+8 −4
Original line number Diff line number Diff line
@@ -93,6 +93,7 @@ struct bam_data_ch_info {
	enum usb_bam_pipe_type	src_pipe_type;
	enum usb_bam_pipe_type	dst_pipe_type;
	unsigned int		pending_with_bam;
	int			rx_buffer_size;

	unsigned int		rx_flow_control_disable;
	unsigned int		rx_flow_control_enable;
@@ -230,14 +231,14 @@ static void bam_data_start_rx(struct bam_data_port *port)
			break;

		req = list_first_entry(&d->rx_idle, struct usb_request, list);
		skb = alloc_skb(bam_mux_rx_req_size + BAM_MUX_HDR, GFP_ATOMIC);
		skb = alloc_skb(d->rx_buffer_size + BAM_MUX_HDR, GFP_ATOMIC);
		if (!skb)
			break;
		skb_reserve(skb, BAM_MUX_HDR);

		list_del(&req->list);
		req->buf = skb->data;
		req->length = bam_mux_rx_req_size;
		req->length = d->rx_buffer_size;
		req->context = skb;
		spin_unlock_irqrestore(&port->port_lock_ul, flags);
		ret = usb_ep_queue(ep, req, GFP_ATOMIC);
@@ -311,7 +312,7 @@ static void bam_data_epout_complete(struct usb_ep *ep, struct usb_request *req)
	}
	spin_unlock(&port->port_lock_ul);

	skb = alloc_skb(bam_mux_rx_req_size + BAM_MUX_HDR, GFP_ATOMIC);
	skb = alloc_skb(d->rx_buffer_size + BAM_MUX_HDR, GFP_ATOMIC);
	if (!skb) {
		list_add_tail(&req->list, &d->rx_idle);
		return;
@@ -319,7 +320,7 @@ static void bam_data_epout_complete(struct usb_ep *ep, struct usb_request *req)
	skb_reserve(skb, BAM_MUX_HDR);

	req->buf = skb->data;
	req->length = bam_mux_rx_req_size;
	req->length = d->rx_buffer_size;
	req->context = skb;

	status = usb_ep_queue(ep, req, GFP_ATOMIC);
@@ -1041,7 +1042,10 @@ int bam_data_connect(struct data_port *gr, u8 port_num,

	d->trans = trans;
	d->func_type = func;
	d->rx_buffer_size = (gr->rx_buffer_size ? gr->rx_buffer_size :
					bam_mux_rx_req_size);

	pr_debug("%s(): rx_buffer_size:%d\n", __func__, d->rx_buffer_size);
	if (trans == USB_GADGET_XPORT_BAM2BAM_IPA) {
		d->ipa_params.src_pipe = &(d->src_pipe_idx);
		d->ipa_params.dst_pipe = &(d->dst_pipe_idx);
+1 −0
Original line number Diff line number Diff line
@@ -25,6 +25,7 @@ struct data_port {
	struct usb_composite_dev	*cdev;
	struct usb_function		*func;
	struct usb_ep			*in;
	int				rx_buffer_size;
	struct usb_ep			*out;
	int                             ipa_consumer_ep;
	int                             ipa_producer_ep;