Skip to content

Commit 6177bbe

Browse files
committed
drivers: mspi: RX no copy - drivers
Added no copy functionality to RX. Signed-off-by: Michal Frankiewicz <[email protected]>
1 parent 2f0d4ce commit 6177bbe

File tree

1 file changed

+38
-15
lines changed

1 file changed

+38
-15
lines changed

drivers/mspi/mspi_nrfe.c

Lines changed: 38 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -526,7 +526,7 @@ static int xfer_packet(struct mspi_xfer_packet *packet, uint32_t timeout)
526526
nrfe_mspi_opcode_t opcode = (packet->dir == MSPI_RX) ? NRFE_MSPI_TXRX : NRFE_MSPI_TX;
527527

528528
#ifdef CONFIG_MSPI_NRFE_IPC_NO_COPY
529-
/* Check for alignment problems. */
529+
/* In case of buffer alignment problems: create correctly aligned temporary buffer. */
530530
uint32_t len = ((uint32_t)packet->data_buf) % sizeof(uint32_t) != 0
531531
? sizeof(nrfe_mspi_xfer_packet_msg_t) + packet->num_bytes
532532
: sizeof(nrfe_mspi_xfer_packet_msg_t);
@@ -542,10 +542,14 @@ static int xfer_packet(struct mspi_xfer_packet *packet, uint32_t timeout)
542542
xfer_packet->num_bytes = packet->num_bytes;
543543

544544
#ifdef CONFIG_MSPI_NRFE_IPC_NO_COPY
545-
/* Check for alignlemt problems. */
545+
/* In case of buffer alignment problems: fill temporary buffer with TX data and
546+
* set it as packet data.
547+
*/
546548
if (((uint32_t)packet->data_buf) % sizeof(uint32_t) != 0) {
547-
memcpy((void *)(buffer + sizeof(nrfe_mspi_xfer_packet_msg_t)),
548-
(void *)packet->data_buf, packet->num_bytes);
549+
if (packet->dir == MSPI_TX) {
550+
memcpy((void *)(buffer + sizeof(nrfe_mspi_xfer_packet_msg_t)),
551+
(void *)packet->data_buf, packet->num_bytes);
552+
}
549553
xfer_packet->data = buffer + sizeof(nrfe_mspi_xfer_packet_msg_t);
550554
} else {
551555
xfer_packet->data = packet->data_buf;
@@ -557,20 +561,39 @@ static int xfer_packet(struct mspi_xfer_packet *packet, uint32_t timeout)
557561
rc = send_data(xfer_packet->opcode, xfer_packet, len);
558562

559563
/* Wait for the transfer to complete and receive data. */
560-
if ((packet->dir == MSPI_RX) && (ipc_receive_buffer != NULL) && (ipc_received > 0)) {
561-
/*
562-
* It is not possible to check whether received data is valid, so packet->num_bytes
563-
* should always be equal to ipc_received. If it is not, then something went wrong.
564+
if (packet->dir == MSPI_RX) {
565+
566+
/* In case of CONFIG_MSPI_NRFE_IPC_NO_COPY ipc_received if equal to 0 because
567+
* packet buffer address was passed to vpr and data was written directly there.
568+
* So there is no way of checking how much data was written.
569+
*/
570+
#ifdef CONFIG_MSPI_NRFE_IPC_NO_COPY
571+
/* In case of buffer alignment problems: copy received data from temporary buffer
572+
* back to users buffer.
564573
*/
565-
if (packet->num_bytes != ipc_received) {
566-
rc = -EIO;
567-
} else {
568-
memcpy((void *)packet->data_buf, (void *)ipc_receive_buffer, ipc_received);
574+
if (((uint32_t)packet->data_buf) % sizeof(uint32_t) != 0) {
575+
memcpy((void *)packet->data_buf, (void *)xfer_packet->data,
576+
packet->num_bytes);
569577
}
578+
#else
579+
if ((ipc_receive_buffer != NULL) && (ipc_received > 0)) {
580+
/*
581+
* It is not possible to check whether received data is valid, so
582+
* packet->num_bytes should always be equal to ipc_received. If it is not,
583+
* then something went wrong.
584+
*/
585+
if (packet->num_bytes != ipc_received) {
586+
rc = -EIO;
587+
} else {
588+
memcpy((void *)packet->data_buf, (void *)ipc_receive_buffer,
589+
ipc_received);
590+
}
570591

571-
/* Clear the receive buffer pointer and size */
572-
ipc_receive_buffer = NULL;
573-
ipc_received = 0;
592+
/* Clear the receive buffer pointer and size */
593+
ipc_receive_buffer = NULL;
594+
ipc_received = 0;
595+
}
596+
#endif
574597
}
575598

576599
return rc;

0 commit comments

Comments
 (0)