-
Notifications
You must be signed in to change notification settings - Fork 143
soundwire: cadence_master: use full data slots in BRA frames #5482
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -2109,7 +2109,6 @@ int sdw_cdns_bpt_find_buffer_sizes(int command, /* 0: write, 1: read */ | |||||
| unsigned int actual_bpt_bytes; | ||||||
| unsigned int pdi0_tx_size; | ||||||
| unsigned int pdi1_rx_size; | ||||||
| unsigned int remainder; | ||||||
|
|
||||||
| if (!data_bytes) | ||||||
| return -EINVAL; | ||||||
|
|
@@ -2118,9 +2117,6 @@ int sdw_cdns_bpt_find_buffer_sizes(int command, /* 0: write, 1: read */ | |||||
| if (!actual_bpt_bytes) | ||||||
| return -EINVAL; | ||||||
|
|
||||||
| if (data_bytes < actual_bpt_bytes) | ||||||
| actual_bpt_bytes = data_bytes; | ||||||
|
|
||||||
| /* | ||||||
| * the caller may want to set the number of bytes per frame, | ||||||
| * allow when possible | ||||||
|
|
@@ -2130,43 +2126,25 @@ int sdw_cdns_bpt_find_buffer_sizes(int command, /* 0: write, 1: read */ | |||||
|
|
||||||
| *data_per_frame = actual_bpt_bytes; | ||||||
|
|
||||||
| /* | ||||||
| * For writes we need to send all the data_bytes per frame, even for the last frame | ||||||
| * which may only transport fewer bytes. | ||||||
| * For reads for some reason the transport may not complete if the last frame is not | ||||||
| * fully used. We will set the data length of all frames are fully used to the BPT | ||||||
| * header and ignore the unrequested date. | ||||||
| */ | ||||||
| *num_frames = DIV_ROUND_UP(data_bytes, actual_bpt_bytes); | ||||||
| if (command == 0) { | ||||||
| /* | ||||||
| * for writes we need to send all the data_bytes per frame, | ||||||
| * even for the last frame which may only transport fewer bytes | ||||||
| */ | ||||||
|
|
||||||
| *num_frames = DIV_ROUND_UP(data_bytes, actual_bpt_bytes); | ||||||
|
|
||||||
| pdi0_tx_size = sdw_cdns_write_pdi0_buffer_size(actual_bpt_bytes); | ||||||
| pdi1_rx_size = SDW_CDNS_WRITE_PDI1_BUFFER_SIZE; | ||||||
|
|
||||||
| *pdi0_buffer_size = pdi0_tx_size * *num_frames; | ||||||
| *pdi1_buffer_size = pdi1_rx_size * *num_frames; | ||||||
| } else { | ||||||
| /* | ||||||
| * for reads we need to retrieve only what is requested in the BPT | ||||||
| * header, so the last frame needs to be special-cased | ||||||
| */ | ||||||
| *num_frames = data_bytes / actual_bpt_bytes; | ||||||
|
|
||||||
| pdi0_tx_size = SDW_CDNS_READ_PDI0_BUFFER_SIZE; | ||||||
| pdi1_rx_size = sdw_cdns_read_pdi1_buffer_size(actual_bpt_bytes); | ||||||
|
|
||||||
| *pdi0_buffer_size = pdi0_tx_size * *num_frames; | ||||||
| *pdi1_buffer_size = pdi1_rx_size * *num_frames; | ||||||
|
|
||||||
| remainder = data_bytes % actual_bpt_bytes; | ||||||
| if (remainder) { | ||||||
| pdi0_tx_size = SDW_CDNS_READ_PDI0_BUFFER_SIZE; | ||||||
| pdi1_rx_size = sdw_cdns_read_pdi1_buffer_size(remainder); | ||||||
|
|
||||||
| *num_frames = *num_frames + 1; | ||||||
| *pdi0_buffer_size += pdi0_tx_size; | ||||||
| *pdi1_buffer_size += pdi1_rx_size; | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| *pdi0_buffer_size = pdi0_tx_size * *num_frames; | ||||||
| *pdi1_buffer_size = pdi1_rx_size * *num_frames; | ||||||
|
|
||||||
| return 0; | ||||||
| } | ||||||
| EXPORT_SYMBOL(sdw_cdns_bpt_find_buffer_sizes); | ||||||
|
|
@@ -2382,7 +2360,11 @@ int sdw_cdns_prepare_read_dma_buffer(u8 dev_num, u32 start_register, int data_si | |||||
| header[0] |= GENMASK(7, 6); /* header is active */ | ||||||
| header[0] |= (dev_num << 2); | ||||||
|
|
||||||
| while (data_size >= data_per_frame) { | ||||||
| /* | ||||||
| * Set message length = data_per_frame even if the required data is less then | ||||||
| * data_per_frame in the last frame. | ||||||
| */ | ||||||
| while (data_size >= 0) { | ||||||
|
||||||
| while (data_size >= 0) { | |
| while (data_size > 0) { |
Copilot
AI
Jul 4, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed boundary check means extract_read_data may write beyond the target buffer when the last frame is smaller than data_per_frame. Reintroduce logic to cap the extracted length to the remaining buffer size (buffer_size - total_num_bytes).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typo in comment: 'date' should be 'data'.