|
| 1 | +/* |
| 2 | + * Copyright (c) 2024 Nordic Semiconductor ASA |
| 3 | + * |
| 4 | + * SPDX-License-Identifier: Apache-2.0 |
| 5 | + */ |
| 6 | + |
| 7 | +/** |
| 8 | + * @brief File containing API definitions for the |
| 9 | + * IPC bus layer of the nRF71 Wi-Fi driver. |
| 10 | + */ |
| 11 | +#include <zephyr/kernel.h> |
| 12 | +#include <zephyr/logging/log.h> |
| 13 | + |
| 14 | +LOG_MODULE_DECLARE(wifi_nrf_bus, CONFIG_WIFI_NRF70_BUSLIB_LOG_LEVEL); |
| 15 | + |
| 16 | +#include "ipc_if.h" |
| 17 | +#include "bal_structs.h" |
| 18 | +#include "qspi.h" |
| 19 | +#include "common/hal_structs_common.h" |
| 20 | + |
| 21 | +/* Define addresses to use for the free queues */ |
| 22 | +#define EVENT_FREEQ_ADDR 0x200C2000 |
| 23 | +#define CMD_FREEQ_ADDR 0x200C3000 |
| 24 | + |
| 25 | +#define NUM_INSTANCES 3 |
| 26 | +#define NUM_ENDPOINTS 1 |
| 27 | + |
| 28 | +struct device *ipc_instances[NUM_INSTANCES]; |
| 29 | +struct ipc_ept ept[NUM_ENDPOINTS]; |
| 30 | +struct ipc_ept_cfg ept_cfg[NUM_ENDPOINTS]; |
| 31 | + |
| 32 | +static wifi_ipc_t wifi_event; |
| 33 | +static wifi_ipc_t wifi_cmd; |
| 34 | +static wifi_ipc_t wifi_tx; |
| 35 | + |
| 36 | +static int (*callback_func)(void *data); |
| 37 | + |
| 38 | +static void event_recv(void *data, void *priv) |
| 39 | +{ |
| 40 | + struct nrf_wifi_bus_qspi_dev_ctx *dev_ctx = NULL; |
| 41 | + struct nrf_wifi_bal_dev_ctx *bal_dev_ctx = NULL; |
| 42 | + struct nrf_wifi_hal_dev_ctx *hal_dev_ctx = NULL; |
| 43 | + |
| 44 | + dev_ctx = (struct nrf_wifi_bus_qspi_dev_ctx *)priv; |
| 45 | + bal_dev_ctx = (struct nrf_wifi_bal_dev_ctx *)dev_ctx->bal_dev_ctx; |
| 46 | + hal_dev_ctx = (struct nrf_wifi_hal_dev_ctx *)bal_dev_ctx->hal_dev_ctx; |
| 47 | + LOG_DBG("Event IPC received"); |
| 48 | + |
| 49 | + hal_dev_ctx->ipc_msg = data; |
| 50 | + callback_func(priv); |
| 51 | + LOG_DBG("Event IPC callback completed"); |
| 52 | +} |
| 53 | + |
| 54 | +int ipc_init(void) |
| 55 | +{ |
| 56 | + wifi_ipc_host_event_init(&wifi_event, EVENT_FREEQ_ADDR); |
| 57 | + LOG_DBG("Event IPC initialized"); |
| 58 | + wifi_ipc_host_cmd_init(&wifi_cmd, CMD_FREEQ_ADDR); |
| 59 | + LOG_DBG("Command IPC initialized"); |
| 60 | + return 0; |
| 61 | +} |
| 62 | + |
| 63 | +int ipc_deinit(void) |
| 64 | +{ |
| 65 | + return 0; |
| 66 | +} |
| 67 | + |
| 68 | +int ipc_recv(ipc_ctx_t ctx, void *data, int len) |
| 69 | +{ |
| 70 | + return 0; |
| 71 | +} |
| 72 | + |
| 73 | +int ipc_send(ipc_ctx_t ctx, const void *data, int len) |
| 74 | +{ |
| 75 | + |
| 76 | + int ret = 0; |
| 77 | + |
| 78 | + switch (ctx.inst) { |
| 79 | + case IPC_INSTANCE_CMD_CTRL: |
| 80 | + /* IPC service on RPU may not have been established. Keep trying. */ |
| 81 | + do { |
| 82 | + ret = wifi_ipc_host_cmd_send_memcpy(&wifi_cmd, data, len); |
| 83 | + } while (ret == WIFI_IPC_STATUS_BUSYQ_NOTREADY); |
| 84 | + |
| 85 | + /* Critical error during IPC service transfer. Should never happen. */ |
| 86 | + if (ret == WIFI_IPC_STATUS_BUSYQ_CRITICAL_ERR) { |
| 87 | + LOG_ERR("Critical error during IPC CMD busyq transfer"); |
| 88 | + return -1; |
| 89 | + } |
| 90 | + break; |
| 91 | + case IPC_INSTANCE_CMD_TX: |
| 92 | + /* IPC service on RPU may not have been established. Keep trying. */ |
| 93 | + do { |
| 94 | + ret = wifi_ipc_host_tx_send(&wifi_tx, data); |
| 95 | + } while (ret == WIFI_IPC_STATUS_BUSYQ_NOTREADY); |
| 96 | + |
| 97 | + /* Critical error during IPC service transfer. Should never happen. */ |
| 98 | + if (ret == WIFI_IPC_STATUS_BUSYQ_CRITICAL_ERR) { |
| 99 | + LOG_ERR("Critical error during IPC TX busyq transfer"); |
| 100 | + return -1; |
| 101 | + } |
| 102 | + break; |
| 103 | + case IPC_INSTANCE_RX: |
| 104 | + break; |
| 105 | + default: |
| 106 | + break; |
| 107 | + } |
| 108 | + |
| 109 | + LOG_DBG("IPC send completed: %d", ret); |
| 110 | + |
| 111 | + return ret; |
| 112 | +} |
| 113 | + |
| 114 | +int ipc_register_rx_cb(int (*rx_handler)(void *priv), void *data) |
| 115 | +{ |
| 116 | + int ret; |
| 117 | + |
| 118 | + callback_func = rx_handler; |
| 119 | + |
| 120 | + ret = wifi_ipc_bind_ipc_service_tx_rx(&wifi_cmd, &wifi_event, |
| 121 | + DEVICE_DT_GET(DT_NODELABEL(ipc0)), event_recv, data); |
| 122 | + if (ret != WIFI_IPC_STATUS_OK) { |
| 123 | + LOG_ERR("Failed to bind IPC service: %d", ret); |
| 124 | + return -1; |
| 125 | + } |
| 126 | + |
| 127 | + ret = wifi_ipc_bind_ipc_service(&wifi_tx, DEVICE_DT_GET(DT_NODELABEL(ipc1)), event_recv, |
| 128 | + data); |
| 129 | + if (ret != WIFI_IPC_STATUS_OK) { |
| 130 | + LOG_ERR("Failed to bind IPC service: %d", ret); |
| 131 | + return -1; |
| 132 | + } |
| 133 | + |
| 134 | + return 0; |
| 135 | +} |
0 commit comments