Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright (c) 2014-2015 The Linux Foundation. All rights reserved. |
| 3 | * |
| 4 | * Previously licensed under the ISC license by Qualcomm Atheros, Inc. |
| 5 | * |
| 6 | * |
| 7 | * Permission to use, copy, modify, and/or distribute this software for |
| 8 | * any purpose with or without fee is hereby granted, provided that the |
| 9 | * above copyright notice and this permission notice appear in all |
| 10 | * copies. |
| 11 | * |
| 12 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL |
| 13 | * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED |
| 14 | * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE |
| 15 | * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL |
| 16 | * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR |
| 17 | * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER |
| 18 | * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR |
| 19 | * PERFORMANCE OF THIS SOFTWARE. |
| 20 | */ |
| 21 | |
| 22 | /* |
| 23 | * This file was originally distributed by Qualcomm Atheros, Inc. |
| 24 | * under proprietary terms before Copyright ownership was assigned |
| 25 | * to the Linux Foundation. |
| 26 | */ |
| 27 | |
| 28 | #if !defined( __CDS_SCHED_H ) |
| 29 | #define __CDS_SCHED_H |
| 30 | |
| 31 | /**========================================================================= |
| 32 | |
| 33 | \file cds_sched.h |
| 34 | |
| 35 | \brief Connectivity driver services scheduler |
| 36 | |
| 37 | ========================================================================*/ |
| 38 | |
| 39 | /*-------------------------------------------------------------------------- |
| 40 | Include Files |
| 41 | ------------------------------------------------------------------------*/ |
| 42 | #include <cdf_event.h> |
| 43 | #include "i_cdf_types.h" |
| 44 | #include <linux/wait.h> |
| 45 | #if defined(WLAN_OPEN_SOURCE) && defined(CONFIG_HAS_WAKELOCK) |
| 46 | #include <linux/wakelock.h> |
| 47 | #endif |
| 48 | #include <cds_mq.h> |
| 49 | #include <cdf_types.h> |
| 50 | #include "cdf_lock.h" |
| 51 | |
| 52 | #define TX_POST_EVENT_MASK 0x001 |
| 53 | #define TX_SUSPEND_EVENT_MASK 0x002 |
| 54 | #define MC_POST_EVENT_MASK 0x001 |
| 55 | #define MC_SUSPEND_EVENT_MASK 0x002 |
| 56 | #define RX_POST_EVENT_MASK 0x001 |
| 57 | #define RX_SUSPEND_EVENT_MASK 0x002 |
| 58 | #define TX_SHUTDOWN_EVENT_MASK 0x010 |
| 59 | #define MC_SHUTDOWN_EVENT_MASK 0x010 |
| 60 | #define RX_SHUTDOWN_EVENT_MASK 0x010 |
| 61 | #define WD_POST_EVENT_MASK 0x001 |
| 62 | #define WD_SHUTDOWN_EVENT_MASK 0x002 |
| 63 | #define WD_CHIP_RESET_EVENT_MASK 0x004 |
| 64 | #define WD_WLAN_SHUTDOWN_EVENT_MASK 0x008 |
| 65 | #define WD_WLAN_REINIT_EVENT_MASK 0x010 |
| 66 | |
| 67 | /* |
| 68 | * Maximum number of messages in the system |
| 69 | * These are buffers to account for all current messages |
| 70 | * with some accounting of what we think is a |
| 71 | * worst-case scenario. Must be able to handle all |
| 72 | * incoming frames, as well as overhead for internal |
| 73 | * messaging |
| 74 | * |
| 75 | * Increased to 8000 to handle more RX frames |
| 76 | */ |
| 77 | #define CDS_CORE_MAX_MESSAGES 8000 |
| 78 | |
| 79 | #ifdef QCA_CONFIG_SMP |
| 80 | /* |
| 81 | ** Maximum number of cds messages to be allocated for |
| 82 | ** OL Rx thread. |
| 83 | */ |
| 84 | #define CDS_MAX_OL_RX_PKT 4000 |
| 85 | |
| 86 | typedef void (*cds_ol_rx_thread_cb)(void *context, void *rxpkt, uint16_t staid); |
| 87 | #endif |
| 88 | |
| 89 | /* |
| 90 | ** CDF Message queue definition. |
| 91 | */ |
| 92 | typedef struct _cds_mq_type { |
| 93 | /* Lock use to synchronize access to this message queue */ |
| 94 | spinlock_t mqLock; |
| 95 | |
| 96 | /* List of vOS Messages waiting on this queue */ |
| 97 | struct list_head mqList; |
| 98 | |
| 99 | } cds_mq_type, *p_cds_mq_type; |
| 100 | |
| 101 | #ifdef QCA_CONFIG_SMP |
| 102 | /* |
| 103 | ** CDS message wrapper for data rx from TXRX |
| 104 | */ |
| 105 | struct cds_ol_rx_pkt { |
| 106 | struct list_head list; |
| 107 | void *context; |
| 108 | |
| 109 | /* Rx skb */ |
| 110 | void *Rxpkt; |
| 111 | |
| 112 | /* Station id to which this packet is destined */ |
| 113 | uint16_t staId; |
| 114 | |
| 115 | /* Call back to further send this packet to txrx layer */ |
| 116 | cds_ol_rx_thread_cb callback; |
| 117 | |
| 118 | }; |
| 119 | #endif |
| 120 | |
| 121 | /* |
| 122 | ** CDS Scheduler context |
| 123 | ** The scheduler context contains the following: |
| 124 | ** ** the messages queues |
| 125 | ** ** the handle to the tread |
| 126 | ** ** pointer to the events that gracefully shutdown the MC and Tx threads |
| 127 | ** |
| 128 | */ |
| 129 | typedef struct _cds_sched_context { |
| 130 | /* Place holder to the CDS Context */ |
| 131 | void *pVContext; |
| 132 | /* WMA Message queue on the Main thread */ |
| 133 | cds_mq_type wmaMcMq; |
| 134 | |
| 135 | /* PE Message queue on the Main thread */ |
| 136 | cds_mq_type peMcMq; |
| 137 | |
| 138 | /* SME Message queue on the Main thread */ |
| 139 | cds_mq_type smeMcMq; |
| 140 | |
| 141 | /* SYS Message queue on the Main thread */ |
| 142 | cds_mq_type sysMcMq; |
| 143 | |
| 144 | /* Handle of Event for MC thread to signal startup */ |
| 145 | struct completion McStartEvent; |
| 146 | |
| 147 | struct task_struct *McThread; |
| 148 | |
| 149 | /* completion object for MC thread shutdown */ |
| 150 | struct completion McShutdown; |
| 151 | |
| 152 | /* Wait queue for MC thread */ |
| 153 | wait_queue_head_t mcWaitQueue; |
| 154 | |
| 155 | unsigned long mcEventFlag; |
| 156 | |
| 157 | /* Completion object to resume Mc thread */ |
| 158 | struct completion ResumeMcEvent; |
| 159 | |
| 160 | /* lock to make sure that McThread suspend/resume mechanism is in sync */ |
| 161 | spinlock_t McThreadLock; |
| 162 | #ifdef QCA_CONFIG_SMP |
| 163 | spinlock_t ol_rx_thread_lock; |
| 164 | |
| 165 | /* OL Rx thread handle */ |
| 166 | struct task_struct *ol_rx_thread; |
| 167 | |
| 168 | /* Handle of Event for Rx thread to signal startup */ |
| 169 | struct completion ol_rx_start_event; |
| 170 | |
| 171 | /* Completion object to suspend OL rx thread */ |
| 172 | struct completion ol_suspend_rx_event; |
| 173 | |
| 174 | /* Completion objext to resume OL rx thread */ |
| 175 | struct completion ol_resume_rx_event; |
| 176 | |
| 177 | /* Completion object for OL Rxthread shutdown */ |
| 178 | struct completion ol_rx_shutdown; |
| 179 | |
| 180 | /* Waitq for OL Rx thread */ |
| 181 | wait_queue_head_t ol_rx_wait_queue; |
| 182 | |
| 183 | unsigned long ol_rx_event_flag; |
| 184 | |
| 185 | /* Rx buffer queue */ |
| 186 | struct list_head ol_rx_thread_queue; |
| 187 | |
| 188 | /* Spinlock to synchronize between tasklet and thread */ |
| 189 | spinlock_t ol_rx_queue_lock; |
| 190 | |
| 191 | /* Rx queue length */ |
| 192 | unsigned int ol_rx_queue_len; |
| 193 | |
| 194 | /* Lock to synchronize free buffer queue access */ |
| 195 | spinlock_t cds_ol_rx_pkt_freeq_lock; |
| 196 | |
| 197 | /* Free message queue for OL Rx processing */ |
| 198 | struct list_head cds_ol_rx_pkt_freeq; |
| 199 | |
| 200 | /* cpu hotplug notifier */ |
| 201 | struct notifier_block *cpu_hot_plug_notifier; |
| 202 | #endif |
| 203 | } cds_sched_context, *p_cds_sched_context; |
| 204 | |
| 205 | /** |
| 206 | * struct cds_log_complete - Log completion internal structure |
| 207 | * @is_fatal: Type is fatal or not |
| 208 | * @indicator: Source of bug report |
| 209 | * @reason_code: Reason code for bug report |
| 210 | * @is_report_in_progress: If bug report is in progress |
| 211 | * |
| 212 | * This structure internally stores the log related params |
| 213 | */ |
| 214 | struct cds_log_complete { |
| 215 | uint32_t is_fatal; |
| 216 | uint32_t indicator; |
| 217 | uint32_t reason_code; |
| 218 | bool is_report_in_progress; |
| 219 | }; |
| 220 | |
| 221 | /* |
| 222 | ** CDS Sched Msg Wrapper |
| 223 | ** Wrapper messages so that they can be chained to their respective queue |
| 224 | ** in the scheduler. |
| 225 | */ |
| 226 | typedef struct _cds_msg_wrapper { |
| 227 | /* Message node */ |
| 228 | struct list_head msgNode; |
| 229 | |
| 230 | /* the Vos message it is associated to */ |
| 231 | cds_msg_t *pVosMsg; |
| 232 | |
| 233 | } cds_msg_wrapper, *p_cds_msg_wrapper; |
| 234 | |
| 235 | typedef struct _cds_context_type { |
| 236 | /* Messages buffers */ |
| 237 | cds_msg_t aMsgBuffers[CDS_CORE_MAX_MESSAGES]; |
| 238 | |
| 239 | cds_msg_wrapper aMsgWrappers[CDS_CORE_MAX_MESSAGES]; |
| 240 | |
| 241 | /* Free Message queue */ |
| 242 | cds_mq_type freeVosMq; |
| 243 | |
| 244 | /* Scheduler Context */ |
| 245 | cds_sched_context cdf_sched; |
| 246 | |
| 247 | /* HDD Module Context */ |
| 248 | void *pHDDContext; |
| 249 | |
| 250 | /* MAC Module Context */ |
| 251 | void *pMACContext; |
| 252 | |
| 253 | #ifndef WLAN_FEATURE_MBSSID |
| 254 | /* SAP Context */ |
| 255 | void *pSAPContext; |
| 256 | #endif |
| 257 | |
| 258 | cdf_event_t ProbeEvent; |
| 259 | |
| 260 | volatile uint8_t isLogpInProgress; |
| 261 | |
| 262 | cdf_event_t wmaCompleteEvent; |
| 263 | |
| 264 | /* WMA Context */ |
| 265 | void *pWMAContext; |
| 266 | |
| 267 | void *pHIFContext; |
| 268 | |
| 269 | void *htc_ctx; |
| 270 | |
| 271 | void *epping_ctx; |
| 272 | /* |
| 273 | * cdf_ctx will be used by cdf |
| 274 | * while allocating dma memory |
| 275 | * to access dev information. |
| 276 | */ |
| 277 | cdf_device_t cdf_ctx; |
| 278 | |
| 279 | void *pdev_txrx_ctx; |
| 280 | |
| 281 | /* Configuration handle used to get system configuration */ |
| 282 | void *cfg_ctx; |
| 283 | |
| 284 | volatile uint8_t isLoadUnloadInProgress; |
| 285 | |
| 286 | bool is_wakelock_log_enabled; |
| 287 | uint32_t wakelock_log_level; |
| 288 | uint32_t connectivity_log_level; |
| 289 | uint32_t packet_stats_log_level; |
| 290 | uint32_t driver_debug_log_level; |
| 291 | uint32_t fw_debug_log_level; |
| 292 | struct cds_log_complete log_complete; |
| 293 | cdf_spinlock_t bug_report_lock; |
| 294 | cdf_event_t connection_update_done_evt; |
| 295 | |
| 296 | } cds_context_type, *p_cds_contextType; |
| 297 | |
| 298 | /*--------------------------------------------------------------------------- |
| 299 | Function declarations and documenation |
| 300 | ---------------------------------------------------------------------------*/ |
| 301 | |
| 302 | #ifdef QCA_CONFIG_SMP |
| 303 | /*--------------------------------------------------------------------------- |
| 304 | \brief cds_drop_rxpkt_by_staid() - API to drop pending Rx packets for a sta |
| 305 | The \a cds_drop_rxpkt_by_staid() drops queued packets for a station, to drop |
| 306 | all the pending packets the caller has to send WLAN_MAX_STA_COUNT as staId. |
| 307 | \param pSchedContext - pointer to the global CDS Sched Context |
| 308 | \param staId - Station Id |
| 309 | |
| 310 | \return Nothing |
| 311 | \sa cds_drop_rxpkt_by_staid() |
| 312 | -------------------------------------------------------------------------*/ |
| 313 | void cds_drop_rxpkt_by_staid(p_cds_sched_context pSchedContext, uint16_t staId); |
| 314 | |
| 315 | /*--------------------------------------------------------------------------- |
| 316 | \brief cds_indicate_rxpkt() - API to Indicate rx data packet |
| 317 | The \a cds_indicate_rxpkt() enqueues the rx packet onto ol_rx_thread_queue |
| 318 | and notifies cds_ol_rx_thread(). |
| 319 | \param Arg - pointer to the global CDS Sched Context |
| 320 | \param pkt - Vos data message buffer |
| 321 | |
| 322 | \return Nothing |
| 323 | \sa cds_indicate_rxpkt() |
| 324 | -------------------------------------------------------------------------*/ |
| 325 | void cds_indicate_rxpkt(p_cds_sched_context pSchedContext, |
| 326 | struct cds_ol_rx_pkt *pkt); |
| 327 | |
| 328 | /*--------------------------------------------------------------------------- |
| 329 | \brief cds_alloc_ol_rx_pkt() - API to return next available cds message |
| 330 | The \a cds_alloc_ol_rx_pkt() returns next available cds message buffer |
| 331 | used for Rx Data processing. |
| 332 | \param pSchedContext - pointer to the global CDS Sched Context |
| 333 | |
| 334 | \return pointer to cds message buffer |
| 335 | \sa cds_alloc_ol_rx_pkt() |
| 336 | -------------------------------------------------------------------------*/ |
| 337 | struct cds_ol_rx_pkt *cds_alloc_ol_rx_pkt(p_cds_sched_context pSchedContext); |
| 338 | |
| 339 | /*--------------------------------------------------------------------------- |
| 340 | \brief cds_free_ol_rx_pkt() - API to release cds message to the freeq |
| 341 | The \a cds_free_ol_rx_pkt() returns the cds message used for Rx data |
| 342 | to the free queue. |
| 343 | \param pSchedContext - pointer to the global CDS Sched Context |
| 344 | \param pkt - Vos message buffer to be returned to free queue. |
| 345 | |
| 346 | \return Nothing |
| 347 | \sa cds_free_ol_rx_pkt() |
| 348 | -------------------------------------------------------------------------*/ |
| 349 | void cds_free_ol_rx_pkt(p_cds_sched_context pSchedContext, |
| 350 | struct cds_ol_rx_pkt *pkt); |
| 351 | /*--------------------------------------------------------------------------- |
| 352 | \brief cds_free_ol_rx_pkt_freeq() - Free cdss buffer free queue |
| 353 | The \a cds_free_ol_rx_pkt_freeq() does mem free of the buffers |
| 354 | available in free cds buffer queue which is used for Data rx processing |
| 355 | from Tlshim. |
| 356 | \param pSchedContext - pointer to the global CDS Sched Context |
| 357 | |
| 358 | \return Nothing |
| 359 | \sa cds_free_ol_rx_pkt_freeq() |
| 360 | -------------------------------------------------------------------------*/ |
| 361 | void cds_free_ol_rx_pkt_freeq(p_cds_sched_context pSchedContext); |
| 362 | #endif |
| 363 | |
| 364 | /*--------------------------------------------------------------------------- |
| 365 | |
| 366 | \brief cds_sched_open() - initialize the CDS Scheduler |
| 367 | |
| 368 | The \a cds_sched_open() function initializes the CDS Scheduler |
| 369 | Upon successful initialization: |
| 370 | |
| 371 | - All the message queues are initialized |
| 372 | |
| 373 | - The Main Controller thread is created and ready to receive and |
| 374 | dispatch messages. |
| 375 | |
| 376 | - The Tx thread is created and ready to receive and dispatch messages |
| 377 | |
| 378 | \param p_cds_context - pointer to the global CDF Context |
| 379 | |
| 380 | \param p_cds_sched_context - pointer to a previously allocated buffer big |
| 381 | enough to hold a scheduler context. |
| 382 | \ |
| 383 | |
| 384 | \return CDF_STATUS_SUCCESS - Scheduler was successfully initialized and |
| 385 | is ready to be used. |
| 386 | |
| 387 | CDF_STATUS_E_RESOURCES - System resources (other than memory) |
| 388 | are unavailable to initilize the scheduler |
| 389 | |
| 390 | CDF_STATUS_E_NOMEM - insufficient memory exists to initialize |
| 391 | the scheduler |
| 392 | |
| 393 | CDF_STATUS_E_INVAL - Invalid parameter passed to the scheduler Open |
| 394 | function |
| 395 | |
| 396 | CDF_STATUS_E_FAILURE - Failure to initialize the scheduler/ |
| 397 | |
| 398 | \sa cds_sched_open() |
| 399 | |
| 400 | -------------------------------------------------------------------------*/ |
| 401 | CDF_STATUS cds_sched_open(void *p_cds_context, |
| 402 | p_cds_sched_context pSchedCxt, uint32_t SchedCtxSize); |
| 403 | |
| 404 | /*--------------------------------------------------------------------------- |
| 405 | |
| 406 | \brief cds_sched_close() - Close the CDS Scheduler |
| 407 | |
| 408 | The \a cds_sched_closes() function closes the CDS Scheduler |
| 409 | Upon successful closing: |
| 410 | |
| 411 | - All the message queues are flushed |
| 412 | |
| 413 | - The Main Controller thread is closed |
| 414 | |
| 415 | - The Tx thread is closed |
| 416 | |
| 417 | \param p_cds_context - pointer to the global CDF Context |
| 418 | |
| 419 | \return CDF_STATUS_SUCCESS - Scheduler was successfully initialized and |
| 420 | is ready to be used. |
| 421 | |
| 422 | CDF_STATUS_E_INVAL - Invalid parameter passed to the scheduler Open |
| 423 | function |
| 424 | |
| 425 | CDF_STATUS_E_FAILURE - Failure to initialize the scheduler/ |
| 426 | |
| 427 | \sa cds_sched_close() |
| 428 | |
| 429 | ---------------------------------------------------------------------------*/ |
| 430 | CDF_STATUS cds_sched_close(void *p_cds_context); |
| 431 | |
| 432 | /* Helper routines provided to other CDS API's */ |
| 433 | CDF_STATUS cds_mq_init(p_cds_mq_type pMq); |
| 434 | void cds_mq_deinit(p_cds_mq_type pMq); |
| 435 | void cds_mq_put(p_cds_mq_type pMq, p_cds_msg_wrapper pMsgWrapper); |
| 436 | p_cds_msg_wrapper cds_mq_get(p_cds_mq_type pMq); |
| 437 | bool cds_is_mq_empty(p_cds_mq_type pMq); |
| 438 | p_cds_sched_context get_cds_sched_ctxt(void); |
| 439 | CDF_STATUS cds_sched_init_mqs(p_cds_sched_context pSchedContext); |
| 440 | void cds_sched_deinit_mqs(p_cds_sched_context pSchedContext); |
| 441 | void cds_sched_flush_mc_mqs(p_cds_sched_context pSchedContext); |
| 442 | |
| 443 | void cdf_timer_module_init(void); |
| 444 | void cds_ssr_protect_init(void); |
| 445 | void cds_ssr_protect(const char *caller_func); |
| 446 | void cds_ssr_unprotect(const char *caller_func); |
| 447 | bool cds_is_ssr_ready(const char *caller_func); |
| 448 | |
| 449 | #define cds_wait_for_work_thread_completion(func) cds_is_ssr_ready(func) |
| 450 | |
| 451 | #endif /* #if !defined __CDS_SCHED_H */ |