1 /*
2 * Copyright (c) 2021, The Linux Foundation. All rights reserved.
3 * Copyright (c) 2022-2023 Qualcomm Innovation Center, Inc. All rights reserved.
4 *
5 * Permission to use, copy, modify, and/or distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
8 *
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 */
17
18 /**
19 * DOC: mlo_global_h_shmem_arena_api.c
20 * This file contains definition of functions that MLO global
21 * shared memory arena exposes.
22 */
23 #include <mlo_global_h_shmem_arena.h>
24
25 #ifdef WLAN_MGMT_RX_REO_SUPPORT
26 /**
27 * mgmt_rx_reo_snapshot_is_valid() - Check if an MGMT Rx REO snapshot is valid
28 * @snapshot_low: lower 32-bits of the snapshot
29 * @snapshot_version: snapshot version
30 *
31 * Return: true if snapshot is valid, else false
32 */
mgmt_rx_reo_snapshot_is_valid(uint32_t snapshot_low,uint8_t snapshot_version)33 static bool mgmt_rx_reo_snapshot_is_valid(uint32_t snapshot_low,
34 uint8_t snapshot_version)
35 {
36 return MLO_SHMEM_MGMT_RX_REO_SNAPSHOT_VALID_GET(snapshot_low,
37 snapshot_version);
38 }
39
40 /**
41 * mgmt_rx_reo_snapshot_get_mgmt_pkt_ctr() - Get the management packet counter
42 * from an MGMT Rx REO snapshot
43 * @snapshot_low: lower 32-bits of the snapshot
44 * @snapshot_version: snapshot version
45 *
46 * Return: Management packet counter of the snapshot
47 */
mgmt_rx_reo_snapshot_get_mgmt_pkt_ctr(uint32_t snapshot_low,uint8_t snapshot_version)48 static uint16_t mgmt_rx_reo_snapshot_get_mgmt_pkt_ctr(uint32_t snapshot_low,
49 uint8_t snapshot_version)
50 {
51 return MLO_SHMEM_MGMT_RX_REO_SNAPSHOT_MGMT_PKT_CTR_GET
52 (snapshot_low, snapshot_version);
53 }
54
55 /**
56 * mgmt_rx_reo_snapshot_get_redundant_mgmt_pkt_ctr() - Get the
57 * redundant management packet counter from MGMT Rx REO snapshot
58 * @snapshot_high: higher 32-bits of the snapshot
59 *
60 * Return: Redundant management packet counter of the snapshot
61 */
mgmt_rx_reo_snapshot_get_redundant_mgmt_pkt_ctr(uint32_t snapshot_high)62 static uint16_t mgmt_rx_reo_snapshot_get_redundant_mgmt_pkt_ctr
63 (uint32_t snapshot_high)
64 {
65 return MLO_SHMEM_MGMT_RX_REO_SNAPSHOT_MGMT_PKT_CTR_REDUNDANT_GET
66 (snapshot_high);
67 }
68
69 /**
70 * mgmt_rx_reo_snapshot_is_consistent() - Check if an MGMT Rx REO snapshot is
71 * consistent
72 * @snapshot_low: lower 32-bits of the snapshot
73 * @snapshot_high: higher 32-bits of the snapshot
74 * @snapshot_version: snapshot version
75 *
76 * Return: true if the snapshot is consistent, else false
77 */
mgmt_rx_reo_snapshot_is_consistent(uint32_t snapshot_low,uint32_t snapshot_high,uint8_t snapshot_version)78 static bool mgmt_rx_reo_snapshot_is_consistent(uint32_t snapshot_low,
79 uint32_t snapshot_high,
80 uint8_t snapshot_version)
81 {
82 return MLO_SHMEM_MGMT_RX_REO_SNAPSHOT_CHECK_CONSISTENCY(snapshot_low,
83 snapshot_high, snapshot_version);
84 }
85
86 /**
87 * mgmt_rx_reo_snapshot_get_global_timestamp() - Get the global timestamp from
88 * MGMT Rx REO snapshot
89 * @snapshot_low: lower 32-bits of the snapshot
90 * @snapshot_high: higher 32-bits of the snapshot
91 * @snapshot_version: snapshot version id
92 *
93 * Return: Global timestamp of the snapshot
94 */
mgmt_rx_reo_snapshot_get_global_timestamp(uint32_t snapshot_low,uint32_t snapshot_high,uint8_t snapshot_version)95 static uint32_t mgmt_rx_reo_snapshot_get_global_timestamp(
96 uint32_t snapshot_low, uint32_t snapshot_high, uint8_t snapshot_version)
97 {
98 return MLO_SHMEM_MGMT_RX_REO_SNAPSHOT_GLOBAL_TIMESTAMP_GET
99 (snapshot_low, snapshot_high, snapshot_version);
100 }
101
mgmt_rx_reo_register_wifi3_0_ops(struct wlan_lmac_if_mgmt_rx_reo_low_level_ops * reo_low_level_ops)102 QDF_STATUS mgmt_rx_reo_register_wifi3_0_ops(
103 struct wlan_lmac_if_mgmt_rx_reo_low_level_ops *reo_low_level_ops)
104 {
105 if (!reo_low_level_ops) {
106 target_if_err("Low level ops of MGMT Rx REO is null");
107 return QDF_STATUS_E_NULL_VALUE;
108 }
109
110 reo_low_level_ops->get_valid_link_bitmap =
111 mgmt_rx_reo_get_valid_link_bitmap;
112 reo_low_level_ops->get_num_links = mgmt_rx_reo_get_num_links;
113 reo_low_level_ops->get_snapshot_address =
114 mgmt_rx_reo_get_snapshot_address;
115 reo_low_level_ops->get_snapshot_version =
116 mgmt_rx_reo_get_snapshot_version;
117 reo_low_level_ops->snapshot_is_valid =
118 mgmt_rx_reo_snapshot_is_valid;
119 reo_low_level_ops->snapshot_get_mgmt_pkt_ctr =
120 mgmt_rx_reo_snapshot_get_mgmt_pkt_ctr;
121 reo_low_level_ops->snapshot_get_redundant_mgmt_pkt_ctr =
122 mgmt_rx_reo_snapshot_get_redundant_mgmt_pkt_ctr;
123 reo_low_level_ops->snapshot_is_consistent =
124 mgmt_rx_reo_snapshot_is_consistent;
125 reo_low_level_ops->snapshot_get_global_timestamp =
126 mgmt_rx_reo_snapshot_get_global_timestamp;
127
128 reo_low_level_ops->implemented = true;
129
130 return QDF_STATUS_SUCCESS;
131 }
132 #endif
133
134 #ifdef WLAN_MLO_GLOBAL_SHMEM_SUPPORT
135 static inline
global_shmem_register_target_recovery_ops(struct wlan_lmac_if_global_shmem_local_ops * shmem_local_ops)136 void global_shmem_register_target_recovery_ops(
137 struct wlan_lmac_if_global_shmem_local_ops *shmem_local_ops)
138 {
139 if (!shmem_local_ops) {
140 target_if_err("Low level ops of global shmem is NULL");
141 return;
142 }
143
144 shmem_local_ops->get_crash_reason_address =
145 mlo_glb_h_shmem_arena_get_crash_reason_address;
146 shmem_local_ops->get_recovery_mode_address =
147 mlo_glb_h_shmem_arena_get_recovery_mode_address;
148 shmem_local_ops->get_no_of_chips_from_crash_info =
149 mlo_glb_h_shmem_arena_get_no_of_chips_from_crash_info;
150 }
151 #else
152 static inline
global_shmem_register_target_recovery_ops(struct wlan_lmac_if_global_shmem_local_ops * shmem_local_ops)153 void global_shmem_register_target_recovery_ops(
154 struct wlan_lmac_if_global_shmem_local_ops *shmem_local_ops)
155 {
156 if (!shmem_local_ops) {
157 target_if_err("Low level ops of global shmem is NULL");
158 return;
159 }
160
161 shmem_local_ops->get_crash_reason_address = NULL;
162 shmem_local_ops->get_no_of_chips_from_crash_info = NULL;
163 }
164 #endif
165
global_shmem_register_wifi3_0_ops(struct wlan_lmac_if_global_shmem_local_ops * shmem_local_ops)166 QDF_STATUS global_shmem_register_wifi3_0_ops(
167 struct wlan_lmac_if_global_shmem_local_ops *shmem_local_ops)
168 {
169 if (!shmem_local_ops) {
170 target_if_err("Low level ops of global shmem is NULL");
171 return QDF_STATUS_E_NULL_VALUE;
172 }
173
174 shmem_local_ops->init_shmem_arena_ctx =
175 mlo_glb_h_shmem_arena_ctx_init;
176 shmem_local_ops->deinit_shmem_arena_ctx =
177 mlo_glb_h_shmem_arena_ctx_deinit;
178
179 global_shmem_register_target_recovery_ops(shmem_local_ops);
180
181 shmem_local_ops->implemented = true;
182
183 return QDF_STATUS_SUCCESS;
184 }
185