Home | History | Annotate | Download | only in wifi_hal
      1 /* Copyright (c) 2015, The Linux Foundation. All rights reserved.
      2  *
      3  * Redistribution and use in source and binary forms, with or without
      4  * modification, are permitted provided that the following conditions are
      5  * met:
      6  *     * Redistributions of source code must retain the above copyright
      7  *       notice, this list of conditions and the following disclaimer.
      8  *     * Redistributions in binary form must reproduce the above
      9  *       copyright notice, this list of conditions and the following
     10  *       disclaimer in the documentation and/or other materials provided
     11  *       with the distribution.
     12  *     * Neither the name of The Linux Foundation nor the names of its
     13  *       contributors may be used to endorse or promote products derived
     14  *       from this software without specific prior written permission.
     15  *
     16  * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
     17  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
     18  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
     19  * ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
     20  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     21  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     22  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
     23  * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
     24  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
     25  * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
     26  * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     27  */
     28 
     29 #ifndef __RING_BUFFER_H
     30 #define __RING_BUFFER_H
     31 
     32 /* Ring buffer status codes */
     33 enum rb_status {
     34     RB_SUCCESS = 0,
     35     RB_FAILURE = 1,
     36 };
     37 
     38 struct rb_stats {
     39     u32 total_bytes_written;
     40     u32 total_bytes_read;
     41     u32 cur_valid_bytes;
     42     unsigned int max_num_bufs;
     43     size_t each_buf_size;
     44 };
     45 
     46 typedef void (*threshold_call_back) (void *cb_ctx);
     47 
     48 /* intiitalizes the ring buffer and returns the context to it */
     49 void * ring_buffer_init(size_t size_of_buf, int num_bufs);
     50 
     51 /* Frees up the mem allocated for this ring buffer operation */
     52 void ring_buffer_deinit(void *ctx);
     53 
     54 /* Writes writes length of bytes from buf to ring buffer */
     55 enum rb_status rb_write(void *ctx, u8 *buf, size_t length, int overwrite);
     56 
     57 /* Tries to read max_length of bytes from ring buffer to buf
     58  * and returns actual length of bytes read from ring buffer
     59  */
     60 size_t rb_read(void *ctx, u8 *buf, size_t max_length);
     61 
     62 /* A buffer with possible maximum of bytes that can be read
     63  * from a single buffer of ring buffer
     64  * Ring buffer module looses the ownership of the buffer returned by this api,
     65  * which means the caller has to make sure to free the buffer returned.
     66  */
     67 u8 *rb_get_read_buf(void *ctx, size_t *length);
     68 
     69 /* calls callback whenever ring_buffer reaches percent percentage of it'ss
     70  * full size
     71  */
     72 void rb_config_threshold(void *ctx,
     73                          unsigned int num_min_bytes,
     74                          threshold_call_back callback,
     75                          void *cb_ctx);
     76 
     77 /* Get the current status of ring buffer */
     78 void rb_get_stats(void *ctx, struct rb_stats *rbs);
     79 
     80 #endif /* __RING_BUFFER_H */
     81