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

Commit e97e900d authored by qctecmdr's avatar qctecmdr Committed by Gerrit - the friendly Code Review server
Browse files

Merge "diag: Synchronize rpmsg info init variables"

parents ae2159a5 e3c43837
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -621,6 +621,7 @@ struct diagchar_dev {
	int dci_tag;
	int dci_client_id[MAX_DCI_CLIENTS];
	struct mutex dci_mutex;
	struct mutex rpmsginfo_mutex[NUM_PERIPHERALS];
	int num_dci_client;
	unsigned char *apps_dci_buf;
	int dci_state;
+1 −0
Original line number Diff line number Diff line
@@ -4150,6 +4150,7 @@ static int __init diagchar_init(void)
	mutex_init(&driver->hdlc_recovery_mutex);
	for (i = 0; i < NUM_PERIPHERALS; i++) {
		mutex_init(&driver->diagfwd_channel_mutex[i]);
		mutex_init(&driver->rpmsginfo_mutex[i]);
		driver->diag_id_sent[i] = 0;
	}
	init_waitqueue_head(&driver->wait_q);
+68 −10
Original line number Diff line number Diff line
@@ -394,9 +394,11 @@ static void diag_rpmsg_queue_read(void *ctxt)
		return;

	rpmsg_info = (struct diag_rpmsg_info *)ctxt;
	mutex_lock(&driver->rpmsginfo_mutex[rpmsg_info->peripheral]);
	if (rpmsg_info->hdl && rpmsg_info->wq &&
		atomic_read(&rpmsg_info->opened))
		queue_work(rpmsg_info->wq, &(rpmsg_info->read_work));
	mutex_unlock(&driver->rpmsginfo_mutex[rpmsg_info->peripheral]);
}

static void diag_state_close_rpmsg(void *ctxt)
@@ -435,13 +437,20 @@ static int diag_rpmsg_read(void *ctxt, unsigned char *buf, int buf_len)
		return -EIO;

	rpmsg_info = (struct diag_rpmsg_info *)ctxt;
	if (!rpmsg_info || !atomic_read(&rpmsg_info->opened) ||
		!rpmsg_info->hdl || !rpmsg_info->inited ||
		!rpmsg_info->fwd_ctxt) {
	if (!rpmsg_info || !rpmsg_info->fwd_ctxt) {
		DIAG_LOG(DIAG_DEBUG_PERIPHERALS, "diag:Invalid rpmsg context");
		return -EIO;
	}

	mutex_lock(&driver->rpmsginfo_mutex[rpmsg_info->peripheral]);
	if (!atomic_read(&rpmsg_info->opened) ||
		!rpmsg_info->hdl || !rpmsg_info->inited) {
		DIAG_LOG(DIAG_DEBUG_PERIPHERALS,
			"diag:RPMSG channel not opened");
		mutex_unlock(&driver->rpmsginfo_mutex[rpmsg_info->peripheral]);
		return -EIO;
	}
	mutex_unlock(&driver->rpmsginfo_mutex[rpmsg_info->peripheral]);

	fwd_info = rpmsg_info->fwd_ctxt;

@@ -466,13 +475,21 @@ static void diag_rpmsg_read_work_fn(struct work_struct *work)
							struct diag_rpmsg_info,
							read_work);

	if (!rpmsg_info || !atomic_read(&rpmsg_info->opened))
	if (!rpmsg_info)
		return;

	mutex_lock(&driver->rpmsginfo_mutex[rpmsg_info->peripheral]);

	if (!atomic_read(&rpmsg_info->opened)) {
		mutex_unlock(&driver->rpmsginfo_mutex[rpmsg_info->peripheral]);
		return;
	}
	if (!rpmsg_info->inited) {
		mutex_unlock(&driver->rpmsginfo_mutex[rpmsg_info->peripheral]);
		diag_ws_release();
		return;
	}
	mutex_unlock(&driver->rpmsginfo_mutex[rpmsg_info->peripheral]);

	diagfwd_channel_read(rpmsg_info->fwd_ctxt);
}
@@ -493,12 +510,16 @@ static int diag_rpmsg_write(void *ctxt, unsigned char *buf, int len)
		return -EINVAL;
	}

	mutex_lock(&driver->rpmsginfo_mutex[rpmsg_info->peripheral]);
	if (!rpmsg_info->inited || !rpmsg_info->hdl ||
		!atomic_read(&rpmsg_info->opened)) {
		pr_err_ratelimited("diag: In %s, rpmsg not inited, rpmsg_info: %pK, buf: %pK, len: %d\n",
				 __func__, rpmsg_info, buf, len);
		mutex_unlock(&driver->rpmsginfo_mutex[rpmsg_info->peripheral]);
		return -ENODEV;
	}
	mutex_unlock(&driver->rpmsginfo_mutex[rpmsg_info->peripheral]);

	rpdev = (struct rpmsg_device *)rpmsg_info->hdl;
	err = rpmsg_send(rpdev->ept, buf, len);
	if (!err) {
@@ -516,8 +537,16 @@ static void diag_rpmsg_late_init_work_fn(struct work_struct *work)
	struct diag_rpmsg_info *rpmsg_info = container_of(work,
							struct diag_rpmsg_info,
							late_init_work);
	if (!rpmsg_info || !rpmsg_info->hdl)
	if (!rpmsg_info)
		return;

	mutex_lock(&driver->rpmsginfo_mutex[rpmsg_info->peripheral]);
	if (!rpmsg_info->hdl) {
		mutex_unlock(&driver->rpmsginfo_mutex[rpmsg_info->peripheral]);
		return;
	}
	mutex_unlock(&driver->rpmsginfo_mutex[rpmsg_info->peripheral]);

	diagfwd_channel_open(rpmsg_info->fwd_ctxt);
	DIAG_LOG(DIAG_DEBUG_PERIPHERALS, "rpmsg late init p: %d t: %d\n",
			rpmsg_info->peripheral, rpmsg_info->type);
@@ -531,8 +560,14 @@ static void diag_rpmsg_open_work_fn(struct work_struct *work)
							open_work);
	if (!rpmsg_info)
		return;
	if (!rpmsg_info->inited)

	mutex_lock(&driver->rpmsginfo_mutex[rpmsg_info->peripheral]);
	if (!rpmsg_info->inited) {
		mutex_unlock(&driver->rpmsginfo_mutex[rpmsg_info->peripheral]);
		return;
	}
	mutex_unlock(&driver->rpmsginfo_mutex[rpmsg_info->peripheral]);

	if (rpmsg_info->type != TYPE_CNTL) {
		diagfwd_channel_open(rpmsg_info->fwd_ctxt);
		diagfwd_late_open(rpmsg_info->fwd_ctxt);
@@ -546,9 +581,16 @@ static void diag_rpmsg_close_work_fn(struct work_struct *work)
	struct diag_rpmsg_info *rpmsg_info = container_of(work,
							struct diag_rpmsg_info,
							close_work);
	if (!rpmsg_info || !rpmsg_info->inited || !rpmsg_info->hdl)
	if (!rpmsg_info)
		return;

	mutex_lock(&driver->rpmsginfo_mutex[rpmsg_info->peripheral]);
	if (!rpmsg_info->inited || !rpmsg_info->hdl) {
		mutex_unlock(&driver->rpmsginfo_mutex[rpmsg_info->peripheral]);
		return;
	}
	rpmsg_info->hdl = NULL;
	mutex_unlock(&driver->rpmsginfo_mutex[rpmsg_info->peripheral]);
	diagfwd_channel_close(rpmsg_info->fwd_ctxt);
}

@@ -667,10 +709,12 @@ int diag_rpmsg_init_peripheral(uint8_t peripheral)
		return -EINVAL;
	}

	mutex_lock(&driver->rpmsginfo_mutex[peripheral]);
	rpmsg_late_init(&rpmsg_data[peripheral]);
	rpmsg_late_init(&rpmsg_dci[peripheral]);
	rpmsg_late_init(&rpmsg_cmd[peripheral]);
	rpmsg_late_init(&rpmsg_dci_cmd[peripheral]);
	mutex_unlock(&driver->rpmsginfo_mutex[peripheral]);

	return 0;
}
@@ -727,17 +771,23 @@ int diag_rpmsg_init(void)
		if (peripheral != PERIPHERAL_WDSP)
			continue;
		rpmsg_info = &rpmsg_cntl[peripheral];
		mutex_lock(&driver->rpmsginfo_mutex[peripheral]);
		__diag_rpmsg_init(rpmsg_info);
		mutex_unlock(&driver->rpmsginfo_mutex[peripheral]);
		diagfwd_cntl_register(TRANSPORT_RPMSG, rpmsg_info->peripheral,
					(void *)rpmsg_info, &rpmsg_ops,
					&(rpmsg_info->fwd_ctxt));
		mutex_lock(&driver->rpmsginfo_mutex[peripheral]);
		rpmsg_info->inited = 1;
		mutex_unlock(&driver->rpmsginfo_mutex[peripheral]);
		diagfwd_channel_open(rpmsg_info->fwd_ctxt);
		diagfwd_late_open(rpmsg_info->fwd_ctxt);
		mutex_lock(&driver->rpmsginfo_mutex[peripheral]);
		__diag_rpmsg_init(&rpmsg_data[peripheral]);
		__diag_rpmsg_init(&rpmsg_cmd[peripheral]);
		__diag_rpmsg_init(&rpmsg_dci[peripheral]);
		__diag_rpmsg_init(&rpmsg_dci_cmd[peripheral]);
		mutex_unlock(&driver->rpmsginfo_mutex[peripheral]);
	}
	return 0;
}
@@ -768,8 +818,9 @@ void diag_rpmsg_early_exit(void)
	for (peripheral = 0; peripheral < NUM_PERIPHERALS; peripheral++) {
		if (peripheral != PERIPHERAL_WDSP)
			continue;
		mutex_lock(&driver->rpmsginfo_mutex[peripheral]);
		__diag_rpmsg_exit(&rpmsg_cntl[peripheral]);

		mutex_unlock(&driver->rpmsginfo_mutex[peripheral]);
	}
}

@@ -778,11 +829,12 @@ void diag_rpmsg_exit(void)
	int peripheral = 0;

	for (peripheral = 0; peripheral < NUM_PERIPHERALS; peripheral++) {
		mutex_lock(&driver->rpmsginfo_mutex[peripheral]);
		__diag_rpmsg_exit(&rpmsg_data[peripheral]);
		__diag_rpmsg_exit(&rpmsg_cmd[peripheral]);
		__diag_rpmsg_exit(&rpmsg_dci[peripheral]);
		__diag_rpmsg_exit(&rpmsg_dci_cmd[peripheral]);

		mutex_unlock(&driver->rpmsginfo_mutex[peripheral]);
	}
}

@@ -816,9 +868,13 @@ static int diag_rpmsg_probe(struct rpmsg_device *rpdev)

	rpmsg_info = diag_get_rpmsg_ptr(rpdev->id.name);
	if (rpmsg_info) {

		mutex_lock(&driver->rpmsginfo_mutex[rpmsg_info->peripheral]);
		rpmsg_info->hdl = rpdev;
		dev_set_drvdata(&rpdev->dev, rpmsg_info);
		atomic_set(&rpmsg_info->opened, 1);
		mutex_unlock(&driver->rpmsginfo_mutex[rpmsg_info->peripheral]);

		dev_set_drvdata(&rpdev->dev, rpmsg_info);
		diagfwd_channel_read(rpmsg_info->fwd_ctxt);
		queue_work(rpmsg_info->wq, &rpmsg_info->open_work);
	}
@@ -835,7 +891,9 @@ static void diag_rpmsg_remove(struct rpmsg_device *rpdev)

	rpmsg_info = diag_get_rpmsg_ptr(rpdev->id.name);
	if (rpmsg_info) {
		mutex_lock(&driver->rpmsginfo_mutex[rpmsg_info->peripheral]);
		atomic_set(&rpmsg_info->opened, 0);
		mutex_unlock(&driver->rpmsginfo_mutex[rpmsg_info->peripheral]);
		queue_work(rpmsg_info->wq, &rpmsg_info->close_work);
	}
}