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

Commit 57d86afe authored by Vamsi Krishna's avatar Vamsi Krishna Committed by Stephen Boyd
Browse files

usb: gadget: mbim: prefix common variables with mbim



mbim driver is cloned from ncm and shares same variable names. Prefix
common variables with mbim to avoid compilation error when ncm is
enabled

Change-Id: I8f1dadb01f67797e881fcd72ddc200a99e4c9ea6
Signed-off-by: default avatarVamsi Krishna <vskrishn@codeaurora.org>
parent c200525d
Loading
Loading
Loading
Loading
+47 −44
Original line number Diff line number Diff line
@@ -63,10 +63,10 @@ struct mbim_notify_port {
};

enum mbim_notify_state {
	NCM_NOTIFY_NONE,
	NCM_NOTIFY_CONNECT,
	NCM_NOTIFY_SPEED,
	NCM_NOTIFY_RESPONSE_AVAILABLE,
	MBIM_NOTIFY_NONE,
	MBIM_NOTIFY_CONNECT,
	MBIM_NOTIFY_SPEED,
	MBIM_NOTIFY_RESPONSE_AVAILABLE,
};

struct f_mbim {
@@ -95,7 +95,7 @@ struct f_mbim {
	u8				ctrl_id, data_id;
	u8				data_alt_int;

	struct ndp_parser_opts		*parser_opts;
	struct mbim_ndp_parser_opts	*parser_opts;

	spinlock_t			lock;

@@ -140,24 +140,24 @@ static inline unsigned mbim_bitrate(struct usb_gadget *g)

/*-------------------------------------------------------------------------*/

#define NTB_DEFAULT_IN_SIZE	(0x4000)
#define NTB_OUT_SIZE		(0x1000)
#define NDP_IN_DIVISOR		(0x4)
#define MBIM_NTB_DEFAULT_IN_SIZE	(0x4000)
#define MBIM_NTB_OUT_SIZE		(0x1000)
#define MBIM_NDP_IN_DIVISOR		(0x4)

#define NTB_DEFAULT_IN_SIZE_IPA	(0x2000)
#define NTB_OUT_SIZE_IPA		(0x2000)
#define MBIM_NTB_OUT_SIZE_IPA		(0x2000)

#define FORMATS_SUPPORTED	USB_CDC_NCM_NTB16_SUPPORTED
#define MBIM_FORMATS_SUPPORTED	USB_CDC_NCM_NTB16_SUPPORTED

static struct usb_cdc_ncm_ntb_parameters ntb_parameters = {
	.wLength = sizeof ntb_parameters,
	.bmNtbFormatsSupported = cpu_to_le16(FORMATS_SUPPORTED),
	.dwNtbInMaxSize = cpu_to_le32(NTB_DEFAULT_IN_SIZE),
	.wNdpInDivisor = cpu_to_le16(NDP_IN_DIVISOR),
static struct usb_cdc_ncm_ntb_parameters mbim_ntb_parameters = {
	.wLength = sizeof mbim_ntb_parameters,
	.bmNtbFormatsSupported = cpu_to_le16(MBIM_FORMATS_SUPPORTED),
	.dwNtbInMaxSize = cpu_to_le32(MBIM_NTB_DEFAULT_IN_SIZE),
	.wNdpInDivisor = cpu_to_le16(MBIM_NDP_IN_DIVISOR),
	.wNdpInPayloadRemainder = cpu_to_le16(0),
	.wNdpInAlignment = cpu_to_le16(4),

	.dwNtbOutMaxSize = cpu_to_le32(NTB_OUT_SIZE),
	.dwNtbOutMaxSize = cpu_to_le32(MBIM_NTB_OUT_SIZE),
	.wNdpOutDivisor = cpu_to_le16(4),
	.wNdpOutPayloadRemainder = cpu_to_le16(0),
	.wNdpOutAlignment = cpu_to_le16(4),
@@ -444,7 +444,7 @@ static struct {
 * and switch pointers to the structures when the format is changed.
 */

struct ndp_parser_opts {
struct mbim_ndp_parser_opts {
	u32		nth_sign;
	u32		ndp_sign;
	unsigned	nth_size;
@@ -487,8 +487,8 @@ struct ndp_parser_opts {
	.next_fp_index = 2,				\
}

static struct ndp_parser_opts ndp16_opts = INIT_NDP16_OPTS;
static struct ndp_parser_opts ndp32_opts = INIT_NDP32_OPTS;
static struct mbim_ndp_parser_opts mbim_ndp16_opts = INIT_NDP16_OPTS;
static struct mbim_ndp_parser_opts mbim_ndp32_opts = INIT_NDP32_OPTS;

static inline int mbim_lock(atomic_t *excl)
{
@@ -630,7 +630,7 @@ fmbim_send_cpkt_response(struct f_mbim *gr, struct ctrl_pkt *cpkt)
		return 0;
	}

	if (dev->not_port.notify_state != NCM_NOTIFY_RESPONSE_AVAILABLE) {
	if (dev->not_port.notify_state != MBIM_NOTIFY_RESPONSE_AVAILABLE) {
		pr_err("dev:%p state=%d, recover!!\n", dev,
			dev->not_port.notify_state);
		mbim_free_ctrl_pkt(cpkt);
@@ -670,12 +670,14 @@ int mbim_configure_params(void)
	int ret = 0;

	aggr_params.dl.aggr_prot = TETH_AGGR_PROTOCOL_MBIM;
	aggr_params.dl.max_datagrams = ntb_parameters.wNtbOutMaxDatagrams;
	aggr_params.dl.max_transfer_size_byte = ntb_parameters.dwNtbInMaxSize;
	aggr_params.dl.max_datagrams = mbim_ntb_parameters.wNtbOutMaxDatagrams;
	aggr_params.dl.max_transfer_size_byte =
			mbim_ntb_parameters.dwNtbInMaxSize;

	aggr_params.ul.aggr_prot = TETH_AGGR_PROTOCOL_MBIM;
	aggr_params.ul.max_datagrams = ntb_parameters.wNtbOutMaxDatagrams;
	aggr_params.ul.max_transfer_size_byte = ntb_parameters.dwNtbOutMaxSize;
	aggr_params.ul.max_datagrams = mbim_ntb_parameters.wNtbOutMaxDatagrams;
	aggr_params.ul.max_transfer_size_byte =
			mbim_ntb_parameters.dwNtbOutMaxSize;

	ret = teth_bridge_set_aggr_params(&aggr_params);
	if (ret)
@@ -731,9 +733,9 @@ static int mbim_bam_disconnect(struct f_mbim *dev)

static inline void mbim_reset_values(struct f_mbim *mbim)
{
	mbim->parser_opts = &ndp16_opts;
	mbim->parser_opts = &mbim_ndp16_opts;

	mbim->ntb_input_size = NTB_DEFAULT_IN_SIZE;
	mbim->ntb_input_size = MBIM_NTB_DEFAULT_IN_SIZE;

	atomic_set(&mbim->online, 0);
}
@@ -809,15 +811,15 @@ static void mbim_do_notify(struct f_mbim *mbim)

	switch (mbim->not_port.notify_state) {

	case NCM_NOTIFY_NONE:
	case MBIM_NOTIFY_NONE:
		if (atomic_read(&mbim->not_port.notify_count) > 0)
			pr_err("Pending notifications in NCM_NOTIFY_NONE\n");
			pr_err("Pending notifications in MBIM_NOTIFY_NONE\n");
		else
			pr_debug("No pending notifications\n");

		return;

	case NCM_NOTIFY_RESPONSE_AVAILABLE:
	case MBIM_NOTIFY_RESPONSE_AVAILABLE:
		pr_debug("Notification %02x sent\n", event->bNotificationType);

		if (atomic_read(&mbim->not_port.notify_count) <= 0) {
@@ -874,7 +876,7 @@ static void mbim_notify_complete(struct usb_ep *ep, struct usb_request *req)
	case -ECONNRESET:
	case -ESHUTDOWN:
		/* connection gone */
		mbim->not_port.notify_state = NCM_NOTIFY_NONE;
		mbim->not_port.notify_state = MBIM_NOTIFY_NONE;
		atomic_set(&mbim->not_port.notify_count, 0);
		pr_info("ESHUTDOWN/ECONNRESET, connection gone");
		spin_unlock(&mbim->lock);
@@ -913,7 +915,7 @@ static void mbim_ep0out_complete(struct usb_ep *ep, struct usb_request *req)
	if (req->length == 4) {
		in_size = get_unaligned_le32(req->buf);
		if (in_size < USB_CDC_NCM_NTB_MIN_IN_SIZE ||
		    in_size > le32_to_cpu(ntb_parameters.dwNtbInMaxSize)) {
		    in_size > le32_to_cpu(mbim_ntb_parameters.dwNtbInMaxSize)) {
			pr_err("Illegal INPUT SIZE (%d) from host\n", in_size);
			goto invalid;
		}
@@ -921,7 +923,7 @@ static void mbim_ep0out_complete(struct usb_ep *ep, struct usb_request *req)
		ntb = (struct mbim_ntb_input_size *)req->buf;
		in_size = get_unaligned_le32(&(ntb->ntb_input_size));
		if (in_size < USB_CDC_NCM_NTB_MIN_IN_SIZE ||
		    in_size > le32_to_cpu(ntb_parameters.dwNtbInMaxSize)) {
		    in_size > le32_to_cpu(mbim_ntb_parameters.dwNtbInMaxSize)) {
			pr_err("Illegal INPUT SIZE (%d) from host\n", in_size);
			goto invalid;
		}
@@ -1080,9 +1082,9 @@ mbim_setup(struct usb_function *f, const struct usb_ctrlrequest *ctrl)
		if (w_length == 0 || w_value != 0 || w_index != mbim->ctrl_id)
			break;

		value = w_length > sizeof ntb_parameters ?
			sizeof ntb_parameters : w_length;
		memcpy(req->buf, &ntb_parameters, value);
		value = w_length > sizeof mbim_ntb_parameters ?
			sizeof mbim_ntb_parameters : w_length;
		memcpy(req->buf, &mbim_ntb_parameters, value);
		break;

	case ((USB_DIR_IN | USB_TYPE_CLASS | USB_RECIP_INTERFACE) << 8)
@@ -1129,7 +1131,7 @@ mbim_setup(struct usb_function *f, const struct usb_ctrlrequest *ctrl)
		if (w_length < 2 || w_value != 0 || w_index != mbim->ctrl_id)
			break;

		format = (mbim->parser_opts == &ndp16_opts) ? 0x0000 : 0x0001;
		format = (mbim->parser_opts == &mbim_ndp16_opts) ? 0 : 1;
		put_unaligned_le16(format, req->buf);
		value = 2;
		pr_debug("NTB FORMAT: sending %d\n", format);
@@ -1145,11 +1147,11 @@ mbim_setup(struct usb_function *f, const struct usb_ctrlrequest *ctrl)
			break;
		switch (w_value) {
		case 0x0000:
			mbim->parser_opts = &ndp16_opts;
			mbim->parser_opts = &mbim_ndp16_opts;
			pr_debug("NCM16 selected\n");
			break;
		case 0x0001:
			mbim->parser_opts = &ndp32_opts;
			mbim->parser_opts = &mbim_ndp32_opts;
			pr_debug("NCM32 selected\n");
			break;
		default:
@@ -1343,7 +1345,7 @@ static int mbim_set_alt(struct usb_function *f, unsigned intf, unsigned alt)

		mbim->data_alt_int = alt;
		spin_lock(&mbim->lock);
		mbim->not_port.notify_state = NCM_NOTIFY_RESPONSE_AVAILABLE;
		mbim->not_port.notify_state = MBIM_NOTIFY_RESPONSE_AVAILABLE;
		spin_unlock(&mbim->lock);
	} else {
		goto fail;
@@ -1387,7 +1389,7 @@ static void mbim_disable(struct usb_function *f)
	pr_info("SET DEVICE OFFLINE");
	atomic_set(&mbim->online, 0);

	mbim->not_port.notify_state = NCM_NOTIFY_NONE;
	mbim->not_port.notify_state = MBIM_NOTIFY_NONE;

	mbim_clear_queues(mbim);
	mbim_reset_function_queue(mbim);
@@ -1655,12 +1657,13 @@ int mbim_bind_config(struct usb_configuration *c, unsigned portno,
		mbim->xport = USB_GADGET_XPORT_BAM2BAM;
	} else  {
		/* For IPA we use limit of 16 */
		ntb_parameters.wNtbOutMaxDatagrams = 16;
		mbim_ntb_parameters.wNtbOutMaxDatagrams = 16;
		/* For IPA this is proven to give maximum throughput */
		ntb_parameters.dwNtbInMaxSize =
		mbim_ntb_parameters.dwNtbInMaxSize =
		cpu_to_le32(NTB_DEFAULT_IN_SIZE_IPA);
		ntb_parameters.dwNtbOutMaxSize = cpu_to_le32(NTB_OUT_SIZE_IPA);
		ntb_parameters.wNdpInDivisor = 1;
		mbim_ntb_parameters.dwNtbOutMaxSize =
				cpu_to_le32(MBIM_NTB_OUT_SIZE_IPA);
		mbim_ntb_parameters.wNdpInDivisor = 1;
	}

	INIT_LIST_HEAD(&mbim->cpkt_req_q);