1 /* 2 * Copyright (c) 2021 Chipsea Technologies (Shenzhen) Corp., Ltd. All rights reserved. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 #ifndef _WIFI_NX_CMDS_H 16 #define _WIFI_NX_CMDS_H 17 18 #if 0 19 #include <linux/spinlock.h> 20 #include <linux/completion.h> 21 #endif 22 #include <stddef.h> 23 24 #include "wifi_msg.h" 25 #include "cs_list.h" 26 #include "rtos_ohos_al.h" 27 #include "wb_co_int.h" 28 #include "wb_co_bool.h" 29 #include "dbg_assert.h" 30 #include "compiler.h" 31 32 #include "wb_co_list.h" 33 34 35 36 #ifdef CONFIG_RWNX_SDM 37 #define RWNX_80211_CMD_TIMEOUT_MS (20 * 300) 38 #elif defined(CONFIG_RWNX_FHOST) 39 #define RWNX_80211_CMD_TIMEOUT_MS (10000) 40 #else 41 #define RWNX_80211_CMD_TIMEOUT_MS 300 42 #endif 43 44 #define RWNX_CMD_FLAG_NONBLOCK BIT(0) 45 #define RWNX_CMD_FLAG_REQ_CFM BIT(1) 46 #define RWNX_CMD_FLAG_WAIT_PUSH BIT(2) 47 #define RWNX_CMD_FLAG_WAIT_ACK BIT(3) 48 #define RWNX_CMD_FLAG_WAIT_CFM BIT(4) 49 #define RWNX_CMD_FLAG_DONE BIT(5) 50 /* ATM IPC design makes it possible to get the CFM before the ACK, 51 * otherwise this could have simply been a state enum */ 52 #define RWNX_CMD_WAIT_COMPLETE(flags) \ 53 (!(flags & (RWNX_CMD_FLAG_WAIT_ACK | RWNX_CMD_FLAG_WAIT_CFM))) 54 55 #define RWNX_CMD_MAX_QUEUED 8 56 57 58 #include "wifi_ipc_shared.h" 59 #define rwnx_cmd_e2amsg ipc_e2a_msg 60 #define rwnx_cmd_a2emsg lmac_msg 61 #define RWNX_CMD_A2EMSG_LEN(m) (sizeof(struct lmac_msg) + m->param_len) 62 #define RWNX_CMD_E2AMSG_LEN_MAX (IPC_E2A_MSG_PARAM_SIZE * 4) 63 64 65 struct rwnx_hw; 66 struct rwnx_cmd; 67 typedef int (*msg_cb_fct)(struct rwnx_hw *rwnx_hw, struct rwnx_cmd *cmd, 68 struct rwnx_cmd_e2amsg *msg); 69 70 enum rwnx_cmd_mgr_state { 71 RWNX_CMD_MGR_STATE_DEINIT, 72 RWNX_CMD_MGR_STATE_INITED, 73 RWNX_CMD_MGR_STATE_CRASHED, 74 }; 75 76 typedef struct rwnx_cmd { 77 struct list_head list; 78 lmac_msg_id_t id; 79 lmac_msg_id_t reqid; 80 struct rwnx_cmd_a2emsg *a2e_msg; 81 char *e2a_msg; 82 uint32_t tkn; 83 uint16_t flags; 84 rtos_semaphore sema; 85 86 //struct completion complete; 87 uint32_t result; 88 #ifdef CONFIG_RWNX_FHOST 89 struct rwnx_term_stream *stream; 90 #endif 91 } rwnx_cmd; 92 93 struct rwnx_cmd_mgr { 94 enum rwnx_cmd_mgr_state state; 95 //spinlock_t lock; 96 rtos_mutex mutex; 97 uint32_t next_tkn; 98 uint32_t queue_sz; 99 uint32_t max_queue_sz; 100 101 struct list_head cmds; 102 103 int (*queue)(struct rwnx_cmd_mgr *, struct rwnx_cmd *); 104 int (*llind)(struct rwnx_cmd_mgr *, struct rwnx_cmd *); 105 int (*msgind)(struct rwnx_cmd_mgr *, struct rwnx_cmd_e2amsg *, msg_cb_fct); 106 void (*print)(struct rwnx_cmd_mgr *); 107 void (*drain)(struct rwnx_cmd_mgr *); 108 }; 109 110 void rwnx_cmd_mgr_init(struct rwnx_cmd_mgr *cmd_mgr); 111 void rwnx_cmd_mgr_deinit(struct rwnx_cmd_mgr *cmd_mgr); 112 113 #endif // _WIFI_NX_CMDS_H 114