From 009691403a343221438e44054b624bb0e482c3e1 Mon Sep 17 00:00:00 2001 From: Jakub Zymelka Date: Tue, 18 Mar 2025 12:50:19 +0100 Subject: [PATCH] drivers: mspi: sdp: merge send_data functions The mspi_ipc_data_send and send_data functions have been merged into one to prevent misuse due to the lack of NO_COPY distinction in the mspi_ipc_data_send function. Signed-off-by: Jakub Zymelka --- drivers/mspi/mspi_nrfe.c | 71 +++++++++++++++------------------------- 1 file changed, 27 insertions(+), 44 deletions(-) diff --git a/drivers/mspi/mspi_nrfe.c b/drivers/mspi/mspi_nrfe.c index 862b042712c7..c81c4641585f 100644 --- a/drivers/mspi/mspi_nrfe.c +++ b/drivers/mspi/mspi_nrfe.c @@ -196,45 +196,6 @@ static void ep_recv(const void *data, size_t len, void *priv) LOG_HEXDUMP_DBG((uint8_t *)data, len, "Received msg:"); } -/** - * @brief Send data to the flpr with the given opcode. - * - * @param opcode The opcode of the message to send. - * @param data The data to send. - * @param len The length of the data to send. - * - * @return 0 on success, -ENOMEM if there is no space in the buffer, - * -ETIMEDOUT if the transfer timed out. - */ -static int mspi_ipc_data_send(nrfe_mspi_opcode_t opcode, const void *data, size_t len) -{ - int rc; - - LOG_DBG("Sending msg with opcode: %d", (uint8_t)opcode); -#if defined(CONFIG_SYS_CLOCK_EXISTS) - uint32_t start = k_uptime_get_32(); -#else - uint32_t repeat = EP_SEND_TIMEOUT_MS; -#endif -#if !defined(CONFIG_MULTITHREADING) - atomic_clear_bit(&ipc_atomic_sem, opcode); -#endif - - do { - rc = ipc_service_send(&ep, data, len); -#if defined(CONFIG_SYS_CLOCK_EXISTS) - if ((k_uptime_get_32() - start) > EP_SEND_TIMEOUT_MS) { -#else - repeat--; - if ((rc < 0) && (repeat == 0)) { -#endif - break; - }; - } while (rc == -ENOMEM); /* No space in the buffer. Retry. */ - - return rc; -} - /** * @brief Waits for a response from the peer with the given opcode. * @@ -303,16 +264,38 @@ static int nrfe_mspi_wait_for_response(nrfe_mspi_opcode_t opcode, uint32_t timeo */ static int send_data(nrfe_mspi_opcode_t opcode, const void *data, size_t len) { - int rc; + LOG_DBG("Sending msg with opcode: %d", (uint8_t)opcode); + int rc; #ifdef CONFIG_MSPI_NRFE_IPC_NO_COPY (void)len; void *data_ptr = (void *)data; +#endif - rc = mspi_ipc_data_send(opcode, &data_ptr, sizeof(void *)); +#if defined(CONFIG_SYS_CLOCK_EXISTS) + uint32_t start = k_uptime_get_32(); #else - rc = mspi_ipc_data_send(opcode, data, len); + uint32_t repeat = EP_SEND_TIMEOUT_MS; #endif +#if !defined(CONFIG_MULTITHREADING) + atomic_clear_bit(&ipc_atomic_sem, opcode); +#endif + + do { +#ifdef CONFIG_MSPI_NRFE_IPC_NO_COPY + rc = ipc_service_send(&ep, &data_ptr, sizeof(void *)); +#else + rc = ipc_service_send(&ep, data, len); +#endif +#if defined(CONFIG_SYS_CLOCK_EXISTS) + if ((k_uptime_get_32() - start) > EP_SEND_TIMEOUT_MS) { +#else + repeat--; + if ((rc < 0) && (repeat == 0)) { +#endif + break; + }; + } while (rc == -ENOMEM); /* No space in the buffer. Retry. */ if (rc < 0) { LOG_ERR("Data transfer failed: %d", rc); @@ -520,7 +503,7 @@ static int api_get_channel_status(const struct device *dev, uint8_t ch) * @retval -ENOMEM if there is no space in the buffer * @retval -ETIMEDOUT if the transfer timed out */ -static int xfer_packet(struct mspi_xfer_packet *packet, uint32_t timeout) +static int send_packet(struct mspi_xfer_packet *packet, uint32_t timeout) { int rc; nrfe_mspi_opcode_t opcode = (packet->dir == MSPI_RX) ? NRFE_MSPI_TXRX : NRFE_MSPI_TX; @@ -598,7 +581,7 @@ static int start_next_packet(struct mspi_xfer *xfer, uint32_t packets_done) return -EINVAL; } - return xfer_packet(packet, xfer->timeout); + return send_packet(packet, xfer->timeout); } /**