Skip to contentSkip to conversation

drivers: optee: i2c: add bus retry configuration

PATCH In review Jorge Ramirez-Ortiz 2 participants 6 messages Sep 16, 2020 – Sep 23, 2020

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 drivers: optee: i2c: add bus retry configuration

Allow OP-TEE to specify the number of retries in the adaptor.

---
 drivers/tee/optee/rpc.c | 7 +++++++
 1 file changed, 7 insertions(+)
drivers/tee/optee/rpc.c +7 -0
index 1e3614e4798f..2d46a9ecb1de 100644
@@ -58,6 +58,7 @@ static void handle_rpc_func_cmd_i2c_transfer(struct tee_context *ctx,
 	struct tee_param *params;
 	size_t i;
 	int ret = -EOPNOTSUPP;
+	int retries = 0;
 	u8 attr[] = {
 		TEE_IOCTL_PARAM_ATTR_TYPE_VALUE_INPUT,
 		TEE_IOCTL_PARAM_ATTR_TYPE_VALUE_INPUT,
@@ -102,12 +103,17 @@ static void handle_rpc_func_cmd_i2c_transfer(struct tee_context *ctx,
 	client.addr = params[0].u.value.c;
 	snprintf(client.name, I2C_NAME_SIZE, "i2c%d", client.adapter->nr);
 
+	/* cache the current value */
+	retries = client.adapter->retries;
+
 	switch (params[0].u.value.a) {
 	case OPTEE_MSG_RPC_CMD_I2C_TRANSFER_RD:
+		client.adapter->retries = params[1].u.value.b;
 		ret = i2c_master_recv(&client, params[2].u.memref.shm->kaddr,
 				      params[2].u.memref.size);
 		break;
 	case OPTEE_MSG_RPC_CMD_I2C_TRANSFER_WR:
+		client.adapter->retries = params[1].u.value.b;
 		ret = i2c_master_send(&client, params[2].u.memref.shm->kaddr,
 				      params[2].u.memref.size);
 		break;
@@ -126,6 +132,7 @@ static void handle_rpc_func_cmd_i2c_transfer(struct tee_context *ctx,
 			arg->ret = TEEC_SUCCESS;
 	}
 
+	client.adapter->retries = retries;
 	i2c_put_adapter(client.adapter);
 	kfree(params);
 	return;
Signature · 1 line
2.17.1
#1 lore raw
Quoted 20 lines · Jorge Ramirez-Ortiz

Allow OP-TEE to specify the number of retries in the adaptor.

---
 drivers/tee/optee/rpc.c | 7 +++++++
 1 file changed, 7 insertions(+)
drivers/tee/optee/rpc.c +1 -0
index 1e3614e4798f..2d46a9ecb1de 100644
@@ -58,6 +58,7 @@ static void handle_rpc_func_cmd_i2c_transfer(struct tee_context *ctx,
 	struct tee_param *params;
 	size_t i;
 	int ret = -EOPNOTSUPP;
+	int retries = 0;
 	u8 attr[] = {
 		TEE_IOCTL_PARAM_ATTR_TYPE_VALUE_INPUT,
 		TEE_IOCTL_PARAM_ATTR_TYPE_VALUE_INPUT,

drivers/tee/optee/rpc.c static void handle_rpc_func_cmd_i2c_transfer(struct tee_context *ctx, · line 111

Quoted 9 lines
drivers/tee/optee/rpc.c +4 -0
@@ -102,12 +103,17 @@ static void handle_rpc_func_cmd_i2c_transfer(struct tee_context *ctx,
 	client.addr = params[0].u.value.c;
 	snprintf(client.name, I2C_NAME_SIZE, "i2c%d", client.adapter->nr);
 
+	/* cache the current value */
+	retries = client.adapter->retries;
+
 	switch (params[0].u.value.a) {
 	case OPTEE_MSG_RPC_CMD_I2C_TRANSFER_RD:
+		client.adapter->retries = params[1].u.value.b;

Do we need to take any locks befor this?

Cheers,
Jens

Quoted 19 lines
drivers/tee/optee/rpc.c +2 -0
 		ret = i2c_master_recv(&client, params[2].u.memref.shm->kaddr,
 				      params[2].u.memref.size);
 		break;
 	case OPTEE_MSG_RPC_CMD_I2C_TRANSFER_WR:
+		client.adapter->retries = params[1].u.value.b;
 		ret = i2c_master_send(&client, params[2].u.memref.shm->kaddr,
 				      params[2].u.memref.size);
 		break;
@@ -126,6 +132,7 @@ static void handle_rpc_func_cmd_i2c_transfer(struct tee_context *ctx,
 			arg->ret = TEEC_SUCCESS;
 	}
 
+	client.adapter->retries = retries;
 	i2c_put_adapter(client.adapter);
 	kfree(params);
 	return;
Signature · 1 line
2.17.1
#2 lore raw
Quoted 24 lines · Jens Wiklander
Quoted 23 lines · Jorge Ramirez-Ortiz

Allow OP-TEE to specify the number of retries in the adaptor.

---
 drivers/tee/optee/rpc.c | 7 +++++++
 1 file changed, 7 insertions(+)
drivers/tee/optee/rpc.c +1 -0
index 1e3614e4798f..2d46a9ecb1de 100644
@@ -58,6 +58,7 @@ static void handle_rpc_func_cmd_i2c_transfer(struct tee_context *ctx,
 	struct tee_param *params;
 	size_t i;
 	int ret = -EOPNOTSUPP;
+	int retries = 0;
 	u8 attr[] = {
 		TEE_IOCTL_PARAM_ATTR_TYPE_VALUE_INPUT,
 		TEE_IOCTL_PARAM_ATTR_TYPE_VALUE_INPUT,
@@ -102,12 +103,17 @@ static void handle_rpc_func_cmd_i2c_transfer(struct tee_context *ctx,
 	client.addr = params[0].u.value.c;
 	snprintf(client.name, I2C_NAME_SIZE, "i2c%d", client.adapter->nr);
 
Quoted 7 lines

drivers/tee/optee/rpc.c static void handle_rpc_func_cmd_i2c_transfer(struct tee_context *ctx, · line 111

Quoted 6 lines
drivers/tee/optee/rpc.c +4 -0
+	/* cache the current value */
+	retries = client.adapter->retries;
+
 	switch (params[0].u.value.a) {
 	case OPTEE_MSG_RPC_CMD_I2C_TRANSFER_RD:
+		client.adapter->retries = params[1].u.value.b;

Do we need to take any locks befor this?

no I dont think so: there is no need for bus locks when requesting a transfer via i2c_master_recv/send; the lock for the bus segment gets taken later on, when the actual transfer hppens ( __i2c_transfer())

the functionality implemented in this function pretty much mimicks what is done in the normal world via /dev/i2c-X (drivers/i2c/i2c_dev.c)

- i2cdev_read --> i2c_master_send
- i2cdev->write -->i2c_master_recv

and now the retry count setup on the adaptor with this commit.

- i2cdev_ioctl I2C_RETRIES

Quoted 23 lines

Cheers,
Jens

Quoted 19 lines
drivers/tee/optee/rpc.c +2 -0
 		ret = i2c_master_recv(&client, params[2].u.memref.shm->kaddr,
 				      params[2].u.memref.size);
 		break;
 	case OPTEE_MSG_RPC_CMD_I2C_TRANSFER_WR:
+		client.adapter->retries = params[1].u.value.b;
 		ret = i2c_master_send(&client, params[2].u.memref.shm->kaddr,
 				      params[2].u.memref.size);
 		break;
@@ -126,6 +132,7 @@ static void handle_rpc_func_cmd_i2c_transfer(struct tee_context *ctx,
 			arg->ret = TEEC_SUCCESS;
 	}
 
+	client.adapter->retries = retries;
 	i2c_put_adapter(client.adapter);
 	kfree(params);
 	return;
Signature · 1 line
2.17.1
#3 lore raw
Quoted 33 lines · Foundries
Quoted 24 lines · Jens Wiklander
Quoted 23 lines · Jorge Ramirez-Ortiz

Allow OP-TEE to specify the number of retries in the adaptor.

---
 drivers/tee/optee/rpc.c | 7 +++++++
 1 file changed, 7 insertions(+)
drivers/tee/optee/rpc.c +1 -0
index 1e3614e4798f..2d46a9ecb1de 100644
@@ -58,6 +58,7 @@ static void handle_rpc_func_cmd_i2c_transfer(struct tee_context *ctx,
 	struct tee_param *params;
 	size_t i;
 	int ret = -EOPNOTSUPP;
+	int retries = 0;
 	u8 attr[] = {
 		TEE_IOCTL_PARAM_ATTR_TYPE_VALUE_INPUT,
 		TEE_IOCTL_PARAM_ATTR_TYPE_VALUE_INPUT,
@@ -102,12 +103,17 @@ static void handle_rpc_func_cmd_i2c_transfer(struct tee_context *ctx,
 	client.addr = params[0].u.value.c;
 	snprintf(client.name, I2C_NAME_SIZE, "i2c%d", client.adapter->nr);
 
Quoted 7 lines

drivers/tee/optee/rpc.c static void handle_rpc_func_cmd_i2c_transfer(struct tee_context *ctx, · line 111

Quoted 6 lines
drivers/tee/optee/rpc.c +4 -0
+	/* cache the current value */
+	retries = client.adapter->retries;
+
 	switch (params[0].u.value.a) {
 	case OPTEE_MSG_RPC_CMD_I2C_TRANSFER_RD:
+		client.adapter->retries = params[1].u.value.b;

Do we need to take any locks befor this?

Quoted 8 lines

no I dont think so: there is no need for bus locks when requesting a transfer via i2c_master_recv/send; the lock for the bus segment gets taken later on, when the actual transfer hppens ( __i2c_transfer())

the functionality implemented in this function pretty much mimicks what is done in the normal world via /dev/i2c-X (drivers/i2c/i2c_dev.c)

correction (of course)
- i2cdev_read --> i2c_master_recv
- i2cdev->write -->i2c_master_send

Quoted 28 lines

and now the retry count setup on the adaptor with this commit.

- i2cdev_ioctl I2C_RETRIES

Quoted 23 lines

Cheers,
Jens

Quoted 19 lines
drivers/tee/optee/rpc.c +2 -0
 		ret = i2c_master_recv(&client, params[2].u.memref.shm->kaddr,
 				      params[2].u.memref.size);
 		break;
 	case OPTEE_MSG_RPC_CMD_I2C_TRANSFER_WR:
+		client.adapter->retries = params[1].u.value.b;
 		ret = i2c_master_send(&client, params[2].u.memref.shm->kaddr,
 				      params[2].u.memref.size);
 		break;
@@ -126,6 +132,7 @@ static void handle_rpc_func_cmd_i2c_transfer(struct tee_context *ctx,
 			arg->ret = TEEC_SUCCESS;
 	}
 
+	client.adapter->retries = retries;
 	i2c_put_adapter(client.adapter);
 	kfree(params);
 	return;
Signature · 1 line
2.17.1
#4 lore raw
Quoted 38 lines · Foundries
Quoted 37 lines · Foundries
Quoted 24 lines · Jens Wiklander
Quoted 23 lines · Jorge Ramirez-Ortiz

Allow OP-TEE to specify the number of retries in the adaptor.

---
 drivers/tee/optee/rpc.c | 7 +++++++
 1 file changed, 7 insertions(+)
drivers/tee/optee/rpc.c +1 -0
index 1e3614e4798f..2d46a9ecb1de 100644
@@ -58,6 +58,7 @@ static void handle_rpc_func_cmd_i2c_transfer(struct tee_context *ctx,
 	struct tee_param *params;
 	size_t i;
 	int ret = -EOPNOTSUPP;
+	int retries = 0;
 	u8 attr[] = {
 		TEE_IOCTL_PARAM_ATTR_TYPE_VALUE_INPUT,
 		TEE_IOCTL_PARAM_ATTR_TYPE_VALUE_INPUT,
@@ -102,12 +103,17 @@ static void handle_rpc_func_cmd_i2c_transfer(struct tee_context *ctx,
 	client.addr = params[0].u.value.c;
 	snprintf(client.name, I2C_NAME_SIZE, "i2c%d", client.adapter->nr);
 
Quoted 7 lines

drivers/tee/optee/rpc.c static void handle_rpc_func_cmd_i2c_transfer(struct tee_context *ctx, · line 111

Quoted 6 lines
drivers/tee/optee/rpc.c +4 -0
+	/* cache the current value */
+	retries = client.adapter->retries;
+
 	switch (params[0].u.value.a) {
 	case OPTEE_MSG_RPC_CMD_I2C_TRANSFER_RD:
+		client.adapter->retries = params[1].u.value.b;

Do we need to take any locks befor this?

no I dont think so: there is no need for bus locks when requesting a transfer via i2c_master_recv/send; the lock for the bus segment gets taken later on, when the actual transfer hppens ( __i2c_transfer())

Quoted 12 lines
Quoted 4 lines

the functionality implemented in this function pretty much mimicks what is done in the normal world via /dev/i2c-X (drivers/i2c/i2c_dev.c)

correction (of course)
- i2cdev_read --> i2c_master_recv
- i2cdev->write -->i2c_master_send

Quoted 4 lines

and now the retry count setup on the adaptor with this commit.

- i2cdev_ioctl I2C_RETRIES

I don't understand. Do you mean that client.adapter->retries doesn't need to be protected from concurrent updates? Or is it already protected by some other mechanism?

Cheers,
Jens

#5 lore raw
Quoted 48 lines · Jens Wiklander
Quoted 47 lines · Foundries
Quoted 33 lines · Foundries
Quoted 24 lines · Jens Wiklander
Quoted 23 lines · Jorge Ramirez-Ortiz

Allow OP-TEE to specify the number of retries in the adaptor.

---
 drivers/tee/optee/rpc.c | 7 +++++++
 1 file changed, 7 insertions(+)
drivers/tee/optee/rpc.c +1 -0
index 1e3614e4798f..2d46a9ecb1de 100644
@@ -58,6 +58,7 @@ static void handle_rpc_func_cmd_i2c_transfer(struct tee_context *ctx,
 	struct tee_param *params;
 	size_t i;
 	int ret = -EOPNOTSUPP;
+	int retries = 0;
 	u8 attr[] = {
 		TEE_IOCTL_PARAM_ATTR_TYPE_VALUE_INPUT,
 		TEE_IOCTL_PARAM_ATTR_TYPE_VALUE_INPUT,
@@ -102,12 +103,17 @@ static void handle_rpc_func_cmd_i2c_transfer(struct tee_context *ctx,
 	client.addr = params[0].u.value.c;
 	snprintf(client.name, I2C_NAME_SIZE, "i2c%d", client.adapter->nr);
 
Quoted 7 lines

drivers/tee/optee/rpc.c static void handle_rpc_func_cmd_i2c_transfer(struct tee_context *ctx, · line 111

Quoted 6 lines
drivers/tee/optee/rpc.c +4 -0
+	/* cache the current value */
+	retries = client.adapter->retries;
+
 	switch (params[0].u.value.a) {
 	case OPTEE_MSG_RPC_CMD_I2C_TRANSFER_RD:
+		client.adapter->retries = params[1].u.value.b;

Do we need to take any locks befor this?

Quoted 8 lines

no I dont think so: there is no need for bus locks when requesting a transfer via i2c_master_recv/send; the lock for the bus segment gets taken later on, when the actual transfer hppens ( __i2c_transfer())

the functionality implemented in this function pretty much mimicks what is done in the normal world via /dev/i2c-X (drivers/i2c/i2c_dev.c)

correction (of course)
- i2cdev_read --> i2c_master_recv
- i2cdev->write -->i2c_master_send

Quoted 1 line
Quoted 7 lines
Quoted 3 lines
Quoted 3 lines

and now the retry count setup on the adaptor with this commit.

- i2cdev_ioctl I2C_RETRIES

I don't understand. Do you mean that client.adapter->retries doesn't need to be protected from concurrent updates? Or is it already protected by some other mechanism?

yeah I probably misunderstood your comment. my bad.

um I thought that upon getting the adaptor there would be some protection mechanism in place until it is put back; but that is not the case. looking a bit into it I see no simple way of protecting changes to the adaptor (at any given time any thread could get a pointer to it) so it seems that setting the retry field is not a guarantee that it will be applied.

Quoted 3 lines

Cheers,
Jens