Skip to content

Commit

Permalink
Prevent request_id overflow to 0
Browse files Browse the repository at this point in the history
GenCP states that only the first command sent can have 0 as its request_id. Because we were overflowing back to 0 we would receive a GENCP_INVALID_PARAMETER status as part of the returned ack status.
  • Loading branch information
mmorin-ni committed Feb 11, 2022
1 parent c2bd583 commit a09d215
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
9 changes: 9 additions & 0 deletions u3v_control.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,9 @@ int u3v_create_control(struct u3v_device *u3v)
/* id is preincremented so we want it to start at 0 */
ctrl->request_id = -1;

/* Set the maximum id value so that we can skip 0 once we overflow */
ctrl->max_request_id = -1;

ctrl->ack_buffer =
kzalloc(ctrl->max_ack_transfer_size, GFP_KERNEL);
ctrl->cmd_buffer =
Expand Down Expand Up @@ -279,6 +282,9 @@ int u3v_read_memory(struct u3v_control *ctrl, u32 transfer_size,
command->header.cmd = cpu_to_le16(READMEM_CMD);
command->header.length =
cpu_to_le16(sizeof(struct read_mem_cmd_payload));
if (ctrl->request_id + 1 == ctrl->max_request_id) {
ctrl->request_id = 0;
}
command->header.request_id = cpu_to_le16(++(ctrl->request_id));
payload->address = address + total_bytes_read;
payload->reserved = 0;
Expand Down Expand Up @@ -511,6 +517,9 @@ int u3v_write_memory(struct u3v_control *ctrl, u32 transfer_size,
command->header.length =
cpu_to_le16(sizeof(struct write_mem_cmd_payload) +
bytes_this_iteration);
if (ctrl->request_id + 1 == ctrl->max_request_id) {
ctrl->request_id = 0;
}
command->header.request_id = cpu_to_le16(++(ctrl->request_id));
payload->address = cpu_to_le64(address + total_bytes_written);
memcpy(payload->data, (u8 *)(buffer + total_bytes_written),
Expand Down
1 change: 1 addition & 0 deletions u3v_control.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ struct u3v_control {
u8 *cmd_buffer;
u32 max_cmd_transfer_size;
u16 request_id;
u16 max_request_id; /* Maximum id value we can have before we loop back around */
u32 u3v_timeout; /* Maximum device response time in ms */
};

Expand Down

0 comments on commit a09d215

Please sign in to comment.