1938448cdSRobert Watson /*- 2*4d846d26SWarner Losh * SPDX-License-Identifier: BSD-2-Clause 3fe267a55SPedro F. Giffuni * 4938448cdSRobert Watson * Copyright (c) 2007-2009 Robert N. M. Watson 5f2d2d694SRobert Watson * Copyright (c) 2010-2011 Juniper Networks, Inc. 6938448cdSRobert Watson * All rights reserved. 7938448cdSRobert Watson * 8938448cdSRobert Watson * This software was developed by Robert N. M. Watson under contract 9938448cdSRobert Watson * to Juniper Networks, Inc. 10938448cdSRobert Watson * 11938448cdSRobert Watson * Redistribution and use in source and binary forms, with or without 12938448cdSRobert Watson * modification, are permitted provided that the following conditions 13938448cdSRobert Watson * are met: 14938448cdSRobert Watson * 1. Redistributions of source code must retain the above copyright 15938448cdSRobert Watson * notice, this list of conditions and the following disclaimer. 16938448cdSRobert Watson * 2. Redistributions in binary form must reproduce the above copyright 17938448cdSRobert Watson * notice, this list of conditions and the following disclaimer in the 18938448cdSRobert Watson * documentation and/or other materials provided with the distribution. 19938448cdSRobert Watson * 20938448cdSRobert Watson * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 21938448cdSRobert Watson * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22938448cdSRobert Watson * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23938448cdSRobert Watson * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 24938448cdSRobert Watson * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25938448cdSRobert Watson * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 26938448cdSRobert Watson * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27938448cdSRobert Watson * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 28938448cdSRobert Watson * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 29938448cdSRobert Watson * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 30938448cdSRobert Watson * SUCH DAMAGE. 31938448cdSRobert Watson */ 32938448cdSRobert Watson 33938448cdSRobert Watson #ifndef _NET_NETISR_INTERNAL_H_ 34938448cdSRobert Watson #define _NET_NETISR_INTERNAL_H_ 35938448cdSRobert Watson 36938448cdSRobert Watson #ifndef _WANT_NETISR_INTERNAL 37938448cdSRobert Watson #error "no user-serviceable parts inside" 38938448cdSRobert Watson #endif 39938448cdSRobert Watson 40938448cdSRobert Watson /* 41938448cdSRobert Watson * These definitions are private to the netisr implementation, but provided 42938448cdSRobert Watson * here for use by post-mortem crashdump analysis tools. They should not be 43938448cdSRobert Watson * used in any other context as they can and will change. Public definitions 44938448cdSRobert Watson * may be found in netisr.h. 45938448cdSRobert Watson */ 46938448cdSRobert Watson 47938448cdSRobert Watson #ifndef _KERNEL 48938448cdSRobert Watson typedef void *netisr_handler_t; 49938448cdSRobert Watson typedef void *netisr_m2flow_t; 50938448cdSRobert Watson typedef void *netisr_m2cpuid_t; 51938448cdSRobert Watson typedef void *netisr_drainedcpu_t; 52938448cdSRobert Watson #endif 53938448cdSRobert Watson 54938448cdSRobert Watson /* 55938448cdSRobert Watson * Each protocol is described by a struct netisr_proto, which holds all 56938448cdSRobert Watson * global per-protocol information. This data structure is set up by 57938448cdSRobert Watson * netisr_register(), and derived from the public struct netisr_handler. 58938448cdSRobert Watson */ 59938448cdSRobert Watson struct netisr_proto { 60938448cdSRobert Watson const char *np_name; /* Character string protocol name. */ 61938448cdSRobert Watson netisr_handler_t *np_handler; /* Protocol handler. */ 62938448cdSRobert Watson netisr_m2flow_t *np_m2flow; /* Query flow for untagged packet. */ 63938448cdSRobert Watson netisr_m2cpuid_t *np_m2cpuid; /* Query CPU to process packet on. */ 64938448cdSRobert Watson netisr_drainedcpu_t *np_drainedcpu; /* Callback when drained a queue. */ 65938448cdSRobert Watson u_int np_qlimit; /* Maximum per-CPU queue depth. */ 66938448cdSRobert Watson u_int np_policy; /* Work placement policy. */ 67f2d2d694SRobert Watson u_int np_dispatch; /* Work dispatch policy. */ 68938448cdSRobert Watson }; 69938448cdSRobert Watson 70938448cdSRobert Watson #define NETISR_MAXPROT 16 /* Compile-time limit. */ 71938448cdSRobert Watson 72938448cdSRobert Watson /* 73938448cdSRobert Watson * Protocol-specific work for each workstream is described by struct 74938448cdSRobert Watson * netisr_work. Each work descriptor consists of an mbuf queue and 75938448cdSRobert Watson * statistics. 76938448cdSRobert Watson */ 77938448cdSRobert Watson struct netisr_work { 78938448cdSRobert Watson /* 79938448cdSRobert Watson * Packet queue, linked by m_nextpkt. 80938448cdSRobert Watson */ 81938448cdSRobert Watson struct mbuf *nw_head; 82938448cdSRobert Watson struct mbuf *nw_tail; 83938448cdSRobert Watson u_int nw_len; 84938448cdSRobert Watson u_int nw_qlimit; 85938448cdSRobert Watson u_int nw_watermark; 86938448cdSRobert Watson 87938448cdSRobert Watson /* 88938448cdSRobert Watson * Statistics -- written unlocked, but mostly from curcpu. 89938448cdSRobert Watson */ 90938448cdSRobert Watson u_int64_t nw_dispatched; /* Number of direct dispatches. */ 91938448cdSRobert Watson u_int64_t nw_hybrid_dispatched; /* "" hybrid dispatches. */ 92938448cdSRobert Watson u_int64_t nw_qdrops; /* "" drops. */ 93938448cdSRobert Watson u_int64_t nw_queued; /* "" enqueues. */ 94938448cdSRobert Watson u_int64_t nw_handled; /* "" handled in worker. */ 95938448cdSRobert Watson }; 96938448cdSRobert Watson 97938448cdSRobert Watson /* 98938448cdSRobert Watson * Workstreams hold a queue of ordered work across each protocol, and are 99938448cdSRobert Watson * described by netisr_workstream. Each workstream is associated with a 100938448cdSRobert Watson * worker thread, which in turn is pinned to a CPU. Work associated with a 101938448cdSRobert Watson * workstream can be processd in other threads during direct dispatch; 102938448cdSRobert Watson * concurrent processing is prevented by the NWS_RUNNING flag, which 103938448cdSRobert Watson * indicates that a thread is already processing the work queue. It is 104938448cdSRobert Watson * important to prevent a directly dispatched packet from "skipping ahead" of 105938448cdSRobert Watson * work already in the workstream queue. 106938448cdSRobert Watson */ 107938448cdSRobert Watson struct netisr_workstream { 108938448cdSRobert Watson struct intr_event *nws_intr_event; /* Handler for stream. */ 109938448cdSRobert Watson void *nws_swi_cookie; /* swi(9) cookie for stream. */ 110938448cdSRobert Watson struct mtx nws_mtx; /* Synchronize work. */ 111938448cdSRobert Watson u_int nws_cpu; /* CPU pinning. */ 112938448cdSRobert Watson u_int nws_flags; /* Wakeup flags. */ 113938448cdSRobert Watson u_int nws_pendingbits; /* Scheduled protocols. */ 114938448cdSRobert Watson 115938448cdSRobert Watson /* 116938448cdSRobert Watson * Each protocol has per-workstream data. 117938448cdSRobert Watson */ 118938448cdSRobert Watson struct netisr_work nws_work[NETISR_MAXPROT]; 119938448cdSRobert Watson } __aligned(CACHE_LINE_SIZE); 120938448cdSRobert Watson 121938448cdSRobert Watson /* 122938448cdSRobert Watson * Per-workstream flags. 123938448cdSRobert Watson */ 124938448cdSRobert Watson #define NWS_RUNNING 0x00000001 /* Currently running in a thread. */ 125938448cdSRobert Watson #define NWS_DISPATCHING 0x00000002 /* Currently being direct-dispatched. */ 126938448cdSRobert Watson #define NWS_SCHEDULED 0x00000004 /* Signal issued. */ 127938448cdSRobert Watson 128938448cdSRobert Watson #endif /* !_NET_NETISR_INTERNAL_H_ */ 129