1 /* 2 * Copyright (c) 2017-2021, The Linux Foundation. All rights reserved. 3 * Copyright (c) 2021 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 #ifndef _DP_IPA_H_ 19 #define _DP_IPA_H_ 20 21 #define IPA_TCL_DATA_RING_IDX 2 22 #ifdef IPA_OFFLOAD 23 24 #define DP_IPA_MAX_IFACE 3 25 #define IPA_REO_DEST_RING_IDX 3 26 #define IPA_REO_DEST_RING_IDX_2 7 27 28 #define IPA_RX_REFILL_BUF_RING_IDX 2 29 30 /* Adding delay before disabling ipa pipes if any Tx Completions are pending */ 31 #define TX_COMP_DRAIN_WAIT_MS 50 32 #define TX_COMP_DRAIN_WAIT_TIMEOUT_MS 100 33 34 #ifdef IPA_WDI3_TX_TWO_PIPES 35 #define IPA_TX_ALT_RING_IDX 1 36 /* 37 * must be same as IPA_TX_ALT_RING_IDX as tcl and wbm ring 38 * are initialized with same index as a pair. 39 */ 40 #define IPA_TX_ALT_COMP_RING_IDX 1 41 #define IPA_SESSION_ID_SHIFT 1 42 #endif 43 44 /** 45 * struct dp_ipa_uc_tx_hdr - full tx header registered to IPA hardware 46 * @eth: ether II header 47 */ 48 struct dp_ipa_uc_tx_hdr { 49 struct ethhdr eth; 50 } __packed; 51 52 /** 53 * struct dp_ipa_uc_rx_hdr - full rx header registered to IPA hardware 54 * @eth: ether II header 55 */ 56 struct dp_ipa_uc_rx_hdr { 57 struct ethhdr eth; 58 } __packed; 59 60 #define DP_IPA_UC_WLAN_TX_HDR_LEN sizeof(struct dp_ipa_uc_tx_hdr) 61 #define DP_IPA_UC_WLAN_RX_HDR_LEN sizeof(struct dp_ipa_uc_rx_hdr) 62 #define DP_IPA_UC_WLAN_HDR_DES_MAC_OFFSET 0 63 64 /** 65 * dp_ipa_get_resource() - Client request resource information 66 * @soc_hdl - data path soc handle 67 * @pdev_id - device instance id 68 * 69 * IPA client will request IPA UC related resource information 70 * Resource information will be distributed to IPA module 71 * All of the required resources should be pre-allocated 72 * 73 * Return: QDF_STATUS 74 */ 75 QDF_STATUS dp_ipa_get_resource(struct cdp_soc_t *soc_hdl, uint8_t pdev_id); 76 77 /** 78 * dp_ipa_set_doorbell_paddr () - Set doorbell register physical address to SRNG 79 * @soc_hdl - data path soc handle 80 * @pdev_id - device instance id 81 * 82 * Set TX_COMP_DOORBELL register physical address to WBM Head_Ptr_MemAddr_LSB 83 * Set RX_READ_DOORBELL register physical address to REO Head_Ptr_MemAddr_LSB 84 * 85 * Return: none 86 */ 87 QDF_STATUS dp_ipa_set_doorbell_paddr(struct cdp_soc_t *soc_hdl, 88 uint8_t pdev_id); 89 QDF_STATUS dp_ipa_uc_set_active(struct cdp_soc_t *soc_hdl, uint8_t pdev_id, 90 bool uc_active, bool is_tx); 91 92 /** 93 * dp_ipa_op_response() - Handle OP command response from firmware 94 * @soc_hdl - data path soc handle 95 * @pdev_id - device instance id 96 * @op_msg: op response message from firmware 97 * 98 * Return: none 99 */ 100 QDF_STATUS dp_ipa_op_response(struct cdp_soc_t *soc_hdl, uint8_t pdev_id, 101 uint8_t *op_msg); 102 103 /** 104 * dp_ipa_register_op_cb() - Register OP handler function 105 * @soc_hdl - data path soc handle 106 * @pdev_id - device instance id 107 * @op_cb: handler function pointer 108 * 109 * Return: none 110 */ 111 QDF_STATUS dp_ipa_register_op_cb(struct cdp_soc_t *soc_hdl, uint8_t pdev_id, 112 ipa_uc_op_cb_type op_cb, void *usr_ctxt); 113 114 /** 115 * dp_ipa_register_op_cb() - Deregister OP handler function 116 * @soc_hdl - data path soc handle 117 * @pdev_id - device instance id 118 * 119 * Return: none 120 */ 121 void dp_ipa_deregister_op_cb(struct cdp_soc_t *soc_hdl, uint8_t pdev_id); 122 123 /** 124 * dp_ipa_get_stat() - Get firmware wdi status 125 * @soc_hdl - data path soc handle 126 * @pdev_id - device instance id 127 * 128 * Return: none 129 */ 130 QDF_STATUS dp_ipa_get_stat(struct cdp_soc_t *soc_hdl, uint8_t pdev_id); 131 132 /** 133 * dp_tx_send_ipa_data_frame() - send IPA data frame 134 * @soc_hdl: datapath soc handle 135 * @vdev_id: virtual device/interface id 136 * @skb: skb 137 * 138 * Return: skb/ NULL is for success 139 */ 140 qdf_nbuf_t dp_tx_send_ipa_data_frame(struct cdp_soc_t *soc_hdl, uint8_t vdev_id, 141 qdf_nbuf_t skb); 142 143 /** 144 * dp_ipa_enable_autonomy() – Enable autonomy RX path 145 * @soc_hdl - data path soc handle 146 * @pdev_id - device instance id 147 * 148 * Set all RX packet route to IPA REO ring 149 * Program Destination_Ring_Ctrl_IX_0 REO register to point IPA REO ring 150 * Return: none 151 */ 152 QDF_STATUS dp_ipa_enable_autonomy(struct cdp_soc_t *soc_hdl, uint8_t pdev_id); 153 154 /** 155 * dp_ipa_disable_autonomy() – Disable autonomy RX path 156 * @soc_hdl - data path soc handle 157 * @pdev_id - device instance id 158 * 159 * Disable RX packet routing to IPA REO 160 * Program Destination_Ring_Ctrl_IX_0 REO register to disable 161 * Return: none 162 */ 163 QDF_STATUS dp_ipa_disable_autonomy(struct cdp_soc_t *soc_hdl, uint8_t pdev_id); 164 165 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 10, 0)) || \ 166 defined(CONFIG_IPA_WDI_UNIFIED_API) 167 /** 168 * dp_ipa_setup() - Setup and connect IPA pipes 169 * @soc_hdl - data path soc handle 170 * @pdev_id - device instance id 171 * @ipa_i2w_cb: IPA to WLAN callback 172 * @ipa_w2i_cb: WLAN to IPA callback 173 * @ipa_wdi_meter_notifier_cb: IPA WDI metering callback 174 * @ipa_desc_size: IPA descriptor size 175 * @ipa_priv: handle to the HTT instance 176 * @is_rm_enabled: Is IPA RM enabled or not 177 * @tx_pipe_handle: pointer to Tx pipe handle 178 * @rx_pipe_handle: pointer to Rx pipe handle 179 * @is_smmu_enabled: Is SMMU enabled or not 180 * @sys_in: parameters to setup sys pipe in mcc mode 181 * 182 * Return: QDF_STATUS 183 */ 184 QDF_STATUS dp_ipa_setup(struct cdp_soc_t *soc_hdl, uint8_t pdev_id, 185 void *ipa_i2w_cb, void *ipa_w2i_cb, 186 void *ipa_wdi_meter_notifier_cb, 187 uint32_t ipa_desc_size, void *ipa_priv, 188 bool is_rm_enabled, uint32_t *tx_pipe_handle, 189 uint32_t *rx_pipe_handle, 190 bool is_smmu_enabled, 191 qdf_ipa_sys_connect_params_t *sys_in, bool over_gsi); 192 #else /* CONFIG_IPA_WDI_UNIFIED_API */ 193 /** 194 * dp_ipa_setup() - Setup and connect IPA pipes 195 * @soc_hdl - data path soc handle 196 * @pdev_id - device instance id 197 * @ipa_i2w_cb: IPA to WLAN callback 198 * @ipa_w2i_cb: WLAN to IPA callback 199 * @ipa_wdi_meter_notifier_cb: IPA WDI metering callback 200 * @ipa_desc_size: IPA descriptor size 201 * @ipa_priv: handle to the HTT instance 202 * @is_rm_enabled: Is IPA RM enabled or not 203 * @tx_pipe_handle: pointer to Tx pipe handle 204 * @rx_pipe_handle: pointer to Rx pipe handle 205 * 206 * Return: QDF_STATUS 207 */ 208 QDF_STATUS dp_ipa_setup(struct cdp_soc_t *soc_hdl, uint8_t pdev_id, 209 void *ipa_i2w_cb, void *ipa_w2i_cb, 210 void *ipa_wdi_meter_notifier_cb, 211 uint32_t ipa_desc_size, void *ipa_priv, 212 bool is_rm_enabled, uint32_t *tx_pipe_handle, 213 uint32_t *rx_pipe_handle); 214 #endif /* CONFIG_IPA_WDI_UNIFIED_API */ 215 QDF_STATUS dp_ipa_cleanup(struct cdp_soc_t *soc_hdl, uint8_t pdev_id, 216 uint32_t tx_pipe_handle, 217 uint32_t rx_pipe_handle); 218 QDF_STATUS dp_ipa_remove_header(char *name); 219 int dp_ipa_add_header_info(char *ifname, uint8_t *mac_addr, 220 uint8_t session_id, bool is_ipv6_enabled); 221 int dp_ipa_register_interface(char *ifname, bool is_ipv6_enabled); 222 QDF_STATUS dp_ipa_setup_iface(char *ifname, uint8_t *mac_addr, 223 qdf_ipa_client_type_t prod_client, 224 qdf_ipa_client_type_t cons_client, 225 uint8_t session_id, bool is_ipv6_enabled); 226 QDF_STATUS dp_ipa_cleanup_iface(char *ifname, bool is_ipv6_enabled); 227 228 /** 229 * dp_ipa_uc_enable_pipes() - Enable and resume traffic on Tx/Rx pipes 230 * @soc_hdl - handle to the soc 231 * @pdev_id - pdev id number, to get the handle 232 * 233 * Return: QDF_STATUS 234 */ 235 QDF_STATUS dp_ipa_enable_pipes(struct cdp_soc_t *soc_hdl, uint8_t pdev_id); 236 237 /** 238 * dp_ipa_disable_pipes() – Suspend traffic and disable Tx/Rx pipes 239 * @soc_hdl - handle to the soc 240 * @pdev_id - pdev id number, to get the handle 241 * 242 * Return: QDF_STATUS 243 */ 244 QDF_STATUS dp_ipa_disable_pipes(struct cdp_soc_t *soc_hdl, uint8_t pdev_id); 245 QDF_STATUS dp_ipa_set_perf_level(int client, 246 uint32_t max_supported_bw_mbps); 247 248 /** 249 * dp_ipa_rx_intrabss_fwd() - Perform intra-bss fwd for IPA RX path 250 * 251 * @soc_hdl: data path soc handle 252 * @vdev_id: virtual device/interface id 253 * @nbuf: pointer to skb of ethernet packet received from IPA RX path 254 * @fwd_success: pointer to indicate if skb succeeded in intra-bss TX 255 * 256 * This function performs intra-bss forwarding for WDI 3.0 IPA RX path. 257 * 258 * Return: true if packet is intra-bss fwd-ed and no need to pass to 259 * network stack. false if packet needs to be passed to network stack. 260 */ 261 bool dp_ipa_rx_intrabss_fwd(struct cdp_soc_t *soc_hdl, uint8_t vdev_id, 262 qdf_nbuf_t nbuf, bool *fwd_success); 263 int dp_ipa_uc_detach(struct dp_soc *soc, struct dp_pdev *pdev); 264 int dp_ipa_uc_attach(struct dp_soc *soc, struct dp_pdev *pdev); 265 int dp_ipa_ring_resource_setup(struct dp_soc *soc, 266 struct dp_pdev *pdev); 267 QDF_STATUS dp_ipa_handle_rx_buf_smmu_mapping(struct dp_soc *soc, 268 qdf_nbuf_t nbuf, 269 uint32_t size, 270 bool create); 271 272 bool dp_reo_remap_config(struct dp_soc *soc, uint32_t *remap0, 273 uint32_t *remap1, uint32_t *remap2); 274 bool dp_ipa_is_mdm_platform(void); 275 276 qdf_nbuf_t dp_ipa_handle_rx_reo_reinject(struct dp_soc *soc, qdf_nbuf_t nbuf); 277 278 /** 279 * dp_ipa_tx_buf_smmu_mapping() - Create SMMU mappings for IPA 280 * allocated TX buffers 281 * @soc_hdl: handle to the soc 282 * @pdev_id: pdev id number, to get the handle 283 * 284 * Return: QDF_STATUS 285 */ 286 QDF_STATUS dp_ipa_tx_buf_smmu_mapping( 287 struct cdp_soc_t *soc_hdl, uint8_t pdev_id); 288 289 /** 290 * dp_ipa_tx_buf_smmu_unmapping() - Release SMMU mappings for IPA 291 * allocated TX buffers 292 * @soc_hdl: handle to the soc 293 * @pdev_id: pdev id number, to get the handle 294 * 295 * Return: QDF_STATUS 296 */ 297 QDF_STATUS dp_ipa_tx_buf_smmu_unmapping( 298 struct cdp_soc_t *soc_hdl, uint8_t pdev_id); 299 300 #ifndef QCA_OL_DP_SRNG_LOCK_LESS_ACCESS 301 static inline void 302 dp_ipa_rx_buf_smmu_mapping_lock(struct dp_soc *soc) 303 { 304 if (soc->ipa_rx_buf_map_lock_initialized) 305 qdf_spin_lock_bh(&soc->ipa_rx_buf_map_lock); 306 } 307 308 static inline void 309 dp_ipa_rx_buf_smmu_mapping_unlock(struct dp_soc *soc) 310 { 311 if (soc->ipa_rx_buf_map_lock_initialized) 312 qdf_spin_unlock_bh(&soc->ipa_rx_buf_map_lock); 313 } 314 315 static inline void 316 dp_ipa_reo_ctx_buf_mapping_lock(struct dp_soc *soc, 317 uint32_t reo_ring_num) 318 { 319 if (!soc->ipa_reo_ctx_lock_required[reo_ring_num]) 320 return; 321 322 qdf_spin_lock_bh(&soc->ipa_rx_buf_map_lock); 323 } 324 325 static inline void 326 dp_ipa_reo_ctx_buf_mapping_unlock(struct dp_soc *soc, 327 uint32_t reo_ring_num) 328 { 329 if (!soc->ipa_reo_ctx_lock_required[reo_ring_num]) 330 return; 331 332 qdf_spin_unlock_bh(&soc->ipa_rx_buf_map_lock); 333 } 334 #else 335 336 static inline void 337 dp_ipa_rx_buf_smmu_mapping_lock(struct dp_soc *soc) 338 { 339 } 340 341 static inline void 342 dp_ipa_rx_buf_smmu_mapping_unlock(struct dp_soc *soc) 343 { 344 } 345 346 static inline void 347 dp_ipa_reo_ctx_buf_mapping_lock(struct dp_soc *soc, 348 uint32_t reo_ring_num) 349 { 350 } 351 352 static inline void 353 dp_ipa_reo_ctx_buf_mapping_unlock(struct dp_soc *soc, 354 uint32_t reo_ring_num) 355 { 356 } 357 #endif 358 359 #else 360 static inline int dp_ipa_uc_detach(struct dp_soc *soc, struct dp_pdev *pdev) 361 { 362 return QDF_STATUS_SUCCESS; 363 } 364 365 static inline int dp_ipa_uc_attach(struct dp_soc *soc, struct dp_pdev *pdev) 366 { 367 return QDF_STATUS_SUCCESS; 368 } 369 370 static inline int dp_ipa_ring_resource_setup(struct dp_soc *soc, 371 struct dp_pdev *pdev) 372 { 373 return 0; 374 } 375 376 static inline QDF_STATUS dp_ipa_handle_rx_buf_smmu_mapping(struct dp_soc *soc, 377 qdf_nbuf_t nbuf, 378 uint32_t size, 379 bool create) 380 { 381 return QDF_STATUS_SUCCESS; 382 } 383 384 static inline void 385 dp_ipa_rx_buf_smmu_mapping_lock(struct dp_soc *soc) 386 { 387 } 388 389 static inline void 390 dp_ipa_rx_buf_smmu_mapping_unlock(struct dp_soc *soc) 391 { 392 } 393 394 static inline void 395 dp_ipa_reo_ctx_buf_mapping_lock(struct dp_soc *soc, 396 uint32_t reo_ring_num) 397 { 398 } 399 400 static inline void 401 dp_ipa_reo_ctx_buf_mapping_unlock(struct dp_soc *soc, 402 uint32_t reo_ring_num) 403 { 404 } 405 406 static inline qdf_nbuf_t dp_ipa_handle_rx_reo_reinject(struct dp_soc *soc, 407 qdf_nbuf_t nbuf) 408 { 409 return nbuf; 410 } 411 412 static inline QDF_STATUS dp_ipa_tx_buf_smmu_mapping(struct cdp_soc_t *soc_hdl, 413 uint8_t pdev_id) 414 { 415 return QDF_STATUS_SUCCESS; 416 } 417 418 static inline QDF_STATUS dp_ipa_tx_buf_smmu_unmapping(struct cdp_soc_t *soc_hdl, 419 uint8_t pdev_id) 420 { 421 return QDF_STATUS_SUCCESS; 422 } 423 424 #endif 425 #endif /* _DP_IPA_H_ */ 426