1204497Srwatson/*- 2204497Srwatson * Copyright (c) 2007-2009 Robert N. M. Watson 3222249Srwatson * Copyright (c) 2010-2011 Juniper Networks, Inc. 4204497Srwatson * All rights reserved. 5204497Srwatson * 6204497Srwatson * This software was developed by Robert N. M. Watson under contract 7204497Srwatson * to Juniper Networks, Inc. 8204497Srwatson * 9204497Srwatson * Redistribution and use in source and binary forms, with or without 10204497Srwatson * modification, are permitted provided that the following conditions 11204497Srwatson * are met: 12204497Srwatson * 1. Redistributions of source code must retain the above copyright 13204497Srwatson * notice, this list of conditions and the following disclaimer. 14204497Srwatson * 2. Redistributions in binary form must reproduce the above copyright 15204497Srwatson * notice, this list of conditions and the following disclaimer in the 16204497Srwatson * documentation and/or other materials provided with the distribution. 17204497Srwatson * 18204497Srwatson * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 19204497Srwatson * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20204497Srwatson * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21204497Srwatson * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 22204497Srwatson * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23204497Srwatson * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24204497Srwatson * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25204497Srwatson * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26204497Srwatson * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27204497Srwatson * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28204497Srwatson * SUCH DAMAGE. 29204497Srwatson * 30204497Srwatson * $FreeBSD$ 31204497Srwatson */ 32204497Srwatson 33204497Srwatson#ifndef _NET_NETISR_INTERNAL_H_ 34204497Srwatson#define _NET_NETISR_INTERNAL_H_ 35204497Srwatson 36204497Srwatson#ifndef _WANT_NETISR_INTERNAL 37204497Srwatson#error "no user-serviceable parts inside" 38204497Srwatson#endif 39204497Srwatson 40204497Srwatson/* 41204497Srwatson * These definitions are private to the netisr implementation, but provided 42204497Srwatson * here for use by post-mortem crashdump analysis tools. They should not be 43204497Srwatson * used in any other context as they can and will change. Public definitions 44204497Srwatson * may be found in netisr.h. 45204497Srwatson */ 46204497Srwatson 47204497Srwatson#ifndef _KERNEL 48204497Srwatsontypedef void *netisr_handler_t; 49204497Srwatsontypedef void *netisr_m2flow_t; 50204497Srwatsontypedef void *netisr_m2cpuid_t; 51204497Srwatsontypedef void *netisr_drainedcpu_t; 52204497Srwatson#endif 53204497Srwatson 54204497Srwatson/* 55204497Srwatson * Each protocol is described by a struct netisr_proto, which holds all 56204497Srwatson * global per-protocol information. This data structure is set up by 57204497Srwatson * netisr_register(), and derived from the public struct netisr_handler. 58204497Srwatson */ 59204497Srwatsonstruct netisr_proto { 60204497Srwatson const char *np_name; /* Character string protocol name. */ 61204497Srwatson netisr_handler_t *np_handler; /* Protocol handler. */ 62204497Srwatson netisr_m2flow_t *np_m2flow; /* Query flow for untagged packet. */ 63204497Srwatson netisr_m2cpuid_t *np_m2cpuid; /* Query CPU to process packet on. */ 64204497Srwatson netisr_drainedcpu_t *np_drainedcpu; /* Callback when drained a queue. */ 65204497Srwatson u_int np_qlimit; /* Maximum per-CPU queue depth. */ 66204497Srwatson u_int np_policy; /* Work placement policy. */ 67222249Srwatson u_int np_dispatch; /* Work dispatch policy. */ 68204497Srwatson}; 69204497Srwatson 70204497Srwatson#define NETISR_MAXPROT 16 /* Compile-time limit. */ 71204497Srwatson 72204497Srwatson/* 73204497Srwatson * Protocol-specific work for each workstream is described by struct 74204497Srwatson * netisr_work. Each work descriptor consists of an mbuf queue and 75204497Srwatson * statistics. 76204497Srwatson */ 77204497Srwatsonstruct netisr_work { 78204497Srwatson /* 79204497Srwatson * Packet queue, linked by m_nextpkt. 80204497Srwatson */ 81204497Srwatson struct mbuf *nw_head; 82204497Srwatson struct mbuf *nw_tail; 83204497Srwatson u_int nw_len; 84204497Srwatson u_int nw_qlimit; 85204497Srwatson u_int nw_watermark; 86204497Srwatson 87204497Srwatson /* 88204497Srwatson * Statistics -- written unlocked, but mostly from curcpu. 89204497Srwatson */ 90204497Srwatson u_int64_t nw_dispatched; /* Number of direct dispatches. */ 91204497Srwatson u_int64_t nw_hybrid_dispatched; /* "" hybrid dispatches. */ 92204497Srwatson u_int64_t nw_qdrops; /* "" drops. */ 93204497Srwatson u_int64_t nw_queued; /* "" enqueues. */ 94204497Srwatson u_int64_t nw_handled; /* "" handled in worker. */ 95204497Srwatson}; 96204497Srwatson 97204497Srwatson/* 98204497Srwatson * Workstreams hold a queue of ordered work across each protocol, and are 99204497Srwatson * described by netisr_workstream. Each workstream is associated with a 100204497Srwatson * worker thread, which in turn is pinned to a CPU. Work associated with a 101204497Srwatson * workstream can be processd in other threads during direct dispatch; 102204497Srwatson * concurrent processing is prevented by the NWS_RUNNING flag, which 103204497Srwatson * indicates that a thread is already processing the work queue. It is 104204497Srwatson * important to prevent a directly dispatched packet from "skipping ahead" of 105204497Srwatson * work already in the workstream queue. 106204497Srwatson */ 107204497Srwatsonstruct netisr_workstream { 108204497Srwatson struct intr_event *nws_intr_event; /* Handler for stream. */ 109204497Srwatson void *nws_swi_cookie; /* swi(9) cookie for stream. */ 110204497Srwatson struct mtx nws_mtx; /* Synchronize work. */ 111204497Srwatson u_int nws_cpu; /* CPU pinning. */ 112204497Srwatson u_int nws_flags; /* Wakeup flags. */ 113204497Srwatson u_int nws_pendingbits; /* Scheduled protocols. */ 114204497Srwatson 115204497Srwatson /* 116204497Srwatson * Each protocol has per-workstream data. 117204497Srwatson */ 118204497Srwatson struct netisr_work nws_work[NETISR_MAXPROT]; 119204497Srwatson} __aligned(CACHE_LINE_SIZE); 120204497Srwatson 121204497Srwatson/* 122204497Srwatson * Per-workstream flags. 123204497Srwatson */ 124204497Srwatson#define NWS_RUNNING 0x00000001 /* Currently running in a thread. */ 125204497Srwatson#define NWS_DISPATCHING 0x00000002 /* Currently being direct-dispatched. */ 126204497Srwatson#define NWS_SCHEDULED 0x00000004 /* Signal issued. */ 127204497Srwatson 128204497Srwatson#endif /* !_NET_NETISR_INTERNAL_H_ */ 129