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

Commit b6c5a911 authored by Katish Paran's avatar Katish Paran Committed by Matt Wagantall
Browse files

diag: Enable hdlc encoding in case the logging mode changes



Currently hdlc encoding is not turned on by default in case if
the logging mode is changed from usb mode to memory device mode
or vice-versa. By design, the hdlc encoding must be turned on
after any logging switch. Also, stop any further reads over
peripherals until the time the mux layer is established.

Change-Id: I21f89771412e2da8ee0243f5f6bb24f917038300
Signed-off-by: default avatarKatish Paran <kparan@codeaurora.org>
parent 192b864c
Loading
Loading
Loading
Loading
+12 −2
Original line number Diff line number Diff line
@@ -108,8 +108,18 @@ static void usb_connect(struct diag_usb_info *ch)
		return;
	}

	if (ch->ops && ch->ops->open)
	if (ch->ops && ch->ops->open) {
		if (atomic_read(&ch->diag_state)) {
			ch->ops->open(ch->ctxt, DIAG_USB_MODE);
		} else {
			/*
			 * This case indicates that the USB is connected
			 * but the logging is still happening in MEMORY
			 * DEVICE MODE. Continue the logging without
			 * resetting the buffers.
			 */
		}
	}
	/* As soon as we open the channel, queue a read */
	queue_work(ch->usb_wq, &(ch->read_work));
}
+5 −3
Original line number Diff line number Diff line
@@ -229,7 +229,9 @@ void diag_drain_work_fn(struct work_struct *work)
	timer_in_progress = 0;

	mutex_lock(&apps_data_mutex);
	if (!driver->hdlc_disabled)
		diag_drain_apps_data(&hdlc_data);
	else
		diag_drain_apps_data(&non_hdlc_data);
	mutex_unlock(&apps_data_mutex);
}
@@ -1106,7 +1108,6 @@ static int diag_switch_logging(int requested_mode)
		driver->md_proc[DIAG_LOCAL_PROC].socket_process = NULL;
	}

	driver->logging_mode = new_mode;
	diag_ws_reset(DIAG_WS_MUX);
	err = diag_mux_switch_logging(mux_mode);
	if (err) {
@@ -1115,6 +1116,7 @@ static int diag_switch_logging(int requested_mode)
		driver->logging_mode = current_mode;
		goto fail;
	}
	driver->logging_mode = new_mode;
	pr_info("diag: Logging switched from %d to %d mode\n",
		current_mode, new_mode);

+27 −25
Original line number Diff line number Diff line
@@ -1004,17 +1004,6 @@ static int diagfwd_mux_open(int id, int mode)
	uint8_t i;
	unsigned long flags;

	if (driver->rsp_buf_busy) {
		/*
		 * When a client switches from callback mode to USB mode
		 * explicitly, there can be a situation when the last response
		 * is not drained to the user space application. Reset the
		 * in_busy flag in this case.
		 */
		spin_lock_irqsave(&driver->rsp_buf_busy_lock, flags);
		driver->rsp_buf_busy = 0;
		spin_unlock_irqrestore(&driver->rsp_buf_busy_lock, flags);
	}
	switch (mode) {
	case DIAG_USB_MODE:
		driver->usb_connected = 1;
@@ -1025,21 +1014,21 @@ static int diagfwd_mux_open(int id, int mode)
		return -EINVAL;
	}

	if ((mode == DIAG_USB_MODE &&
	     driver->logging_mode == MEMORY_DEVICE_MODE) ||
	    (mode == DIAG_MEMORY_DEVICE_MODE &&
	     driver->logging_mode == USB_MODE)) {
	if (driver->rsp_buf_busy) {
		/*
		 * In this case Diag shouldn't not reset the smd in_busy data.
		 * If the reset of smd in_busy values happens then this will
		 * lead to loss of data read over peripherals.
		 * When a client switches from callback mode to USB mode
		 * explicitly, there can be a situation when the last response
		 * is not drained to the user space application. Reset the
		 * in_busy flag in this case.
		 */
	} else {
		spin_lock_irqsave(&driver->rsp_buf_busy_lock, flags);
		driver->rsp_buf_busy = 0;
		spin_unlock_irqrestore(&driver->rsp_buf_busy_lock, flags);
	}
	for (i = 0; i < NUM_PERIPHERALS; i++) {
		diagfwd_open(i, TYPE_DATA);
		diagfwd_open(i, TYPE_CMD);
	}
	}
	queue_work(driver->diag_real_time_wq, &driver->diag_real_time_work);
	return 0;
}
@@ -1058,7 +1047,16 @@ static int diagfwd_mux_close(int id, int mode)
		return -EINVAL;
	}

	if (driver->logging_mode == USB_MODE) {
	if ((mode == DIAG_USB_MODE &&
	     driver->logging_mode == MEMORY_DEVICE_MODE) ||
	    (mode == DIAG_MEMORY_DEVICE_MODE &&
	     driver->logging_mode == USB_MODE)) {
		/*
		 * In this case the channel must not be closed. This case
		 * indicates that the USB is removed but there is a client
		 * running in background with Memory Device mode
		 */
	} else {
		for (i = 0; i < NUM_PERIPHERALS; i++) {
			diagfwd_close(i, TYPE_DATA);
			diagfwd_close(i, TYPE_CMD);
@@ -1066,7 +1064,11 @@ static int diagfwd_mux_close(int id, int mode)
		/* Re enable HDLC encoding */
		pr_debug("diag: In %s, re-enabling HDLC encoding\n",
		       __func__);
		mutex_lock(&driver->hdlc_disable_mutex);
		driver->hdlc_disabled = 0;
		mutex_unlock(&driver->hdlc_disable_mutex);
		queue_work(driver->diag_wq,
			&(driver->update_user_clients));
	}
	queue_work(driver->diag_real_time_wq,
		   &driver->diag_real_time_work);