1 /* Copyright (c) 2014 Broadcom Corporation 2 * 3 * Permission to use, copy, modify, and/or distribute this software for any 4 * purpose with or without fee is hereby granted, provided that the above 5 * copyright notice and this permission notice appear in all copies. 6 * 7 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 8 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 9 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY 10 * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 11 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION 12 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN 13 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 14 */ 15 #ifndef BRCMFMAC_COMMONRING_H 16 #define BRCMFMAC_COMMONRING_H 17 18 19 struct brcmf_commonring { 20 u16 r_ptr; 21 u16 w_ptr; 22 u16 f_ptr; 23 u16 depth; 24 u16 item_len; 25 26 void *buf_addr; 27 28 int (*cr_ring_bell)(void *ctx); 29 int (*cr_update_rptr)(void *ctx); 30 int (*cr_update_wptr)(void *ctx); 31 int (*cr_write_rptr)(void *ctx); 32 int (*cr_write_wptr)(void *ctx); 33 34 void *cr_ctx; 35 36 spinlock_t lock; 37 unsigned long flags; 38 bool inited; 39 bool was_full; 40 41 atomic_t outstanding_tx; 42 }; 43 44 45 void brcmf_commonring_register_cb(struct brcmf_commonring *commonring, 46 int (*cr_ring_bell)(void *ctx), 47 int (*cr_update_rptr)(void *ctx), 48 int (*cr_update_wptr)(void *ctx), 49 int (*cr_write_rptr)(void *ctx), 50 int (*cr_write_wptr)(void *ctx), void *ctx); 51 void brcmf_commonring_config(struct brcmf_commonring *commonring, u16 depth, 52 u16 item_len, void *buf_addr); 53 void brcmf_commonring_lock(struct brcmf_commonring *commonring); 54 void brcmf_commonring_unlock(struct brcmf_commonring *commonring); 55 bool brcmf_commonring_write_available(struct brcmf_commonring *commonring); 56 void *brcmf_commonring_reserve_for_write(struct brcmf_commonring *commonring); 57 void * 58 brcmf_commonring_reserve_for_write_multiple(struct brcmf_commonring *commonring, 59 u16 n_items, u16 *alloced); 60 int brcmf_commonring_write_complete(struct brcmf_commonring *commonring); 61 void brcmf_commonring_write_cancel(struct brcmf_commonring *commonring, 62 u16 n_items); 63 void *brcmf_commonring_get_read_ptr(struct brcmf_commonring *commonring, 64 u16 *n_items); 65 int brcmf_commonring_read_complete(struct brcmf_commonring *commonring, 66 u16 n_items); 67 68 #define brcmf_commonring_n_items(commonring) (commonring->depth) 69 #define brcmf_commonring_len_item(commonring) (commonring->item_len) 70 71 72 #endif /* BRCMFMAC_COMMONRING_H */ 73