1276485Snp/*- 2276485Snp * Copyright (c) 2014 Chelsio Communications, Inc. 3276485Snp * All rights reserved. 4276485Snp * Written by: Navdeep Parhar <np@FreeBSD.org> 5276485Snp * 6276485Snp * Redistribution and use in source and binary forms, with or without 7276485Snp * modification, are permitted provided that the following conditions 8276485Snp * are met: 9276485Snp * 1. Redistributions of source code must retain the above copyright 10276485Snp * notice, this list of conditions and the following disclaimer. 11276485Snp * 2. Redistributions in binary form must reproduce the above copyright 12276485Snp * notice, this list of conditions and the following disclaimer in the 13276485Snp * documentation and/or other materials provided with the distribution. 14276485Snp * 15276485Snp * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 16276485Snp * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17276485Snp * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18276485Snp * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 19276485Snp * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20276485Snp * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 21276485Snp * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22276485Snp * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23276485Snp * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24276485Snp * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25276485Snp * SUCH DAMAGE. 26276485Snp * 27276485Snp * $FreeBSD$ 28276485Snp * 29276485Snp */ 30276485Snp 31276485Snp#ifndef __CXGBE_MP_RING_H 32276485Snp#define __CXGBE_MP_RING_H 33276485Snp 34276485Snp#ifndef _KERNEL 35276485Snp#error "no user-serviceable parts inside" 36276485Snp#endif 37276485Snp 38276485Snpstruct mp_ring; 39276485Snptypedef u_int (*ring_drain_t)(struct mp_ring *, u_int, u_int); 40276485Snptypedef u_int (*ring_can_drain_t)(struct mp_ring *); 41276485Snp 42276485Snpstruct mp_ring { 43276485Snp volatile uint64_t state __aligned(CACHE_LINE_SIZE); 44276485Snp 45276485Snp int size __aligned(CACHE_LINE_SIZE); 46276485Snp void * cookie; 47276485Snp struct malloc_type * mt; 48276485Snp ring_drain_t drain; 49276485Snp ring_can_drain_t can_drain; /* cheap, may be unreliable */ 50276485Snp counter_u64_t enqueues; 51276485Snp counter_u64_t drops; 52276485Snp counter_u64_t starts; 53276485Snp counter_u64_t stalls; 54276485Snp counter_u64_t restarts; /* recovered after stalling */ 55276485Snp counter_u64_t abdications; 56276485Snp 57276485Snp void * volatile items[] __aligned(CACHE_LINE_SIZE); 58276485Snp}; 59276485Snp 60276485Snpint mp_ring_alloc(struct mp_ring **, int, void *, ring_drain_t, 61276485Snp ring_can_drain_t, struct malloc_type *, int); 62276485Snpvoid mp_ring_free(struct mp_ring *); 63276485Snpint mp_ring_enqueue(struct mp_ring *, void **, int, int); 64276485Snpvoid mp_ring_check_drainage(struct mp_ring *, int); 65276485Snpvoid mp_ring_reset_stats(struct mp_ring *); 66276485Snpint mp_ring_is_idle(struct mp_ring *); 67276485Snp 68276485Snp#endif 69