netisr_internal.h revision 302408
10Sstevel@tonic-gate/*-
20Sstevel@tonic-gate * Copyright (c) 2007-2009 Robert N. M. Watson
30Sstevel@tonic-gate * Copyright (c) 2010-2011 Juniper Networks, Inc.
40Sstevel@tonic-gate * All rights reserved.
50Sstevel@tonic-gate *
60Sstevel@tonic-gate * This software was developed by Robert N. M. Watson under contract
70Sstevel@tonic-gate * to Juniper Networks, Inc.
80Sstevel@tonic-gate *
90Sstevel@tonic-gate * Redistribution and use in source and binary forms, with or without
100Sstevel@tonic-gate * modification, are permitted provided that the following conditions
110Sstevel@tonic-gate * are met:
120Sstevel@tonic-gate * 1. Redistributions of source code must retain the above copyright
130Sstevel@tonic-gate *    notice, this list of conditions and the following disclaimer.
140Sstevel@tonic-gate * 2. Redistributions in binary form must reproduce the above copyright
150Sstevel@tonic-gate *    notice, this list of conditions and the following disclaimer in the
160Sstevel@tonic-gate *    documentation and/or other materials provided with the distribution.
170Sstevel@tonic-gate *
180Sstevel@tonic-gate * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
190Sstevel@tonic-gate * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
200Sstevel@tonic-gate * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
210Sstevel@tonic-gate * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
220Sstevel@tonic-gate * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
230Sstevel@tonic-gate * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
240Sstevel@tonic-gate * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
250Sstevel@tonic-gate * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
260Sstevel@tonic-gate * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
270Sstevel@tonic-gate * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
280Sstevel@tonic-gate * SUCH DAMAGE.
290Sstevel@tonic-gate *
300Sstevel@tonic-gate * $FreeBSD: stable/11/sys/net/netisr_internal.h 222249 2011-05-24 12:34:19Z rwatson $
310Sstevel@tonic-gate */
320Sstevel@tonic-gate
330Sstevel@tonic-gate#ifndef _NET_NETISR_INTERNAL_H_
340Sstevel@tonic-gate#define	_NET_NETISR_INTERNAL_H_
350Sstevel@tonic-gate
360Sstevel@tonic-gate#ifndef _WANT_NETISR_INTERNAL
370Sstevel@tonic-gate#error "no user-serviceable parts inside"
380Sstevel@tonic-gate#endif
390Sstevel@tonic-gate
400Sstevel@tonic-gate/*
410Sstevel@tonic-gate * These definitions are private to the netisr implementation, but provided
420Sstevel@tonic-gate * here for use by post-mortem crashdump analysis tools.  They should not be
430Sstevel@tonic-gate * used in any other context as they can and will change.  Public definitions
440Sstevel@tonic-gate * may be found in netisr.h.
450Sstevel@tonic-gate */
460Sstevel@tonic-gate
470Sstevel@tonic-gate#ifndef _KERNEL
480Sstevel@tonic-gatetypedef void *netisr_handler_t;
490Sstevel@tonic-gatetypedef void *netisr_m2flow_t;
500Sstevel@tonic-gatetypedef void *netisr_m2cpuid_t;
510Sstevel@tonic-gatetypedef void *netisr_drainedcpu_t;
520Sstevel@tonic-gate#endif
530Sstevel@tonic-gate
540Sstevel@tonic-gate/*
550Sstevel@tonic-gate * Each protocol is described by a struct netisr_proto, which holds all
560Sstevel@tonic-gate * global per-protocol information.  This data structure is set up by
570Sstevel@tonic-gate * netisr_register(), and derived from the public struct netisr_handler.
580Sstevel@tonic-gate */
590Sstevel@tonic-gatestruct netisr_proto {
600Sstevel@tonic-gate	const char	*np_name;	/* Character string protocol name. */
610Sstevel@tonic-gate	netisr_handler_t *np_handler;	/* Protocol handler. */
620Sstevel@tonic-gate	netisr_m2flow_t	*np_m2flow;	/* Query flow for untagged packet. */
630Sstevel@tonic-gate	netisr_m2cpuid_t *np_m2cpuid;	/* Query CPU to process packet on. */
640Sstevel@tonic-gate	netisr_drainedcpu_t *np_drainedcpu; /* Callback when drained a queue. */
650Sstevel@tonic-gate	u_int		 np_qlimit;	/* Maximum per-CPU queue depth. */
660Sstevel@tonic-gate	u_int		 np_policy;	/* Work placement policy. */
670Sstevel@tonic-gate	u_int		 np_dispatch;	/* Work dispatch policy. */
680Sstevel@tonic-gate};
690Sstevel@tonic-gate
700Sstevel@tonic-gate#define	NETISR_MAXPROT	16		/* Compile-time limit. */
710Sstevel@tonic-gate
720Sstevel@tonic-gate/*
730Sstevel@tonic-gate * Protocol-specific work for each workstream is described by struct
740Sstevel@tonic-gate * netisr_work.  Each work descriptor consists of an mbuf queue and
750Sstevel@tonic-gate * statistics.
760Sstevel@tonic-gate */
770Sstevel@tonic-gatestruct netisr_work {
780Sstevel@tonic-gate	/*
790Sstevel@tonic-gate	 * Packet queue, linked by m_nextpkt.
800Sstevel@tonic-gate	 */
810Sstevel@tonic-gate	struct mbuf	*nw_head;
820Sstevel@tonic-gate	struct mbuf	*nw_tail;
830Sstevel@tonic-gate	u_int		 nw_len;
840Sstevel@tonic-gate	u_int		 nw_qlimit;
850Sstevel@tonic-gate	u_int		 nw_watermark;
860Sstevel@tonic-gate
870Sstevel@tonic-gate	/*
880Sstevel@tonic-gate	 * Statistics -- written unlocked, but mostly from curcpu.
890Sstevel@tonic-gate	 */
900Sstevel@tonic-gate	u_int64_t	 nw_dispatched; /* Number of direct dispatches. */
910Sstevel@tonic-gate	u_int64_t	 nw_hybrid_dispatched; /* "" hybrid dispatches. */
920Sstevel@tonic-gate	u_int64_t	 nw_qdrops;	/* "" drops. */
930Sstevel@tonic-gate	u_int64_t	 nw_queued;	/* "" enqueues. */
940Sstevel@tonic-gate	u_int64_t	 nw_handled;	/* "" handled in worker. */
950Sstevel@tonic-gate};
960Sstevel@tonic-gate
970Sstevel@tonic-gate/*
980Sstevel@tonic-gate * Workstreams hold a queue of ordered work across each protocol, and are
990Sstevel@tonic-gate * described by netisr_workstream.  Each workstream is associated with a
1000Sstevel@tonic-gate * worker thread, which in turn is pinned to a CPU.  Work associated with a
1010Sstevel@tonic-gate * workstream can be processd in other threads during direct dispatch;
1020Sstevel@tonic-gate * concurrent processing is prevented by the NWS_RUNNING flag, which
1030Sstevel@tonic-gate * indicates that a thread is already processing the work queue.  It is
1040Sstevel@tonic-gate * important to prevent a directly dispatched packet from "skipping ahead" of
1050Sstevel@tonic-gate * work already in the workstream queue.
1060Sstevel@tonic-gate */
1070Sstevel@tonic-gatestruct netisr_workstream {
1080Sstevel@tonic-gate	struct intr_event *nws_intr_event;	/* Handler for stream. */
1090Sstevel@tonic-gate	void		*nws_swi_cookie;	/* swi(9) cookie for stream. */
1100Sstevel@tonic-gate	struct mtx	 nws_mtx;		/* Synchronize work. */
1110Sstevel@tonic-gate	u_int		 nws_cpu;		/* CPU pinning. */
1120Sstevel@tonic-gate	u_int		 nws_flags;		/* Wakeup flags. */
1130Sstevel@tonic-gate	u_int		 nws_pendingbits;	/* Scheduled protocols. */
1140Sstevel@tonic-gate
1150Sstevel@tonic-gate	/*
1160Sstevel@tonic-gate	 * Each protocol has per-workstream data.
1170Sstevel@tonic-gate	 */
1180Sstevel@tonic-gate	struct netisr_work	nws_work[NETISR_MAXPROT];
1190Sstevel@tonic-gate} __aligned(CACHE_LINE_SIZE);
1200Sstevel@tonic-gate
1210Sstevel@tonic-gate/*
1220Sstevel@tonic-gate * Per-workstream flags.
1230Sstevel@tonic-gate */
1240Sstevel@tonic-gate#define	NWS_RUNNING	0x00000001	/* Currently running in a thread. */
1250Sstevel@tonic-gate#define	NWS_DISPATCHING	0x00000002	/* Currently being direct-dispatched. */
1260Sstevel@tonic-gate#define	NWS_SCHEDULED	0x00000004	/* Signal issued. */
1270Sstevel@tonic-gate
1280Sstevel@tonic-gate#endif /* !_NET_NETISR_INTERNAL_H_ */
1290Sstevel@tonic-gate