xref: /freebsd/lib/librss/librss.h (revision b3e7694832e81d7a904a10f525f8797b753bf0d3)
1*35c05a4fSAdrian Chadd /*
2*35c05a4fSAdrian Chadd  * Copyright (c) 2016 Adrian Chadd <adrian@FreeBSD.org>
3*35c05a4fSAdrian Chadd  * All rights reserved.
4*35c05a4fSAdrian Chadd  *
5*35c05a4fSAdrian Chadd  * Redistribution and use in source and binary forms, with or without
6*35c05a4fSAdrian Chadd  * modification, are permitted provided that the following conditions
7*35c05a4fSAdrian Chadd  * are met:
8*35c05a4fSAdrian Chadd  * 1. Redistributions of source code must retain the above copyright
9*35c05a4fSAdrian Chadd  *    notice, this list of conditions and the following disclaimer.
10*35c05a4fSAdrian Chadd  * 2. Redistributions in binary form must reproduce the above copyright
11*35c05a4fSAdrian Chadd  *    notice, this list of conditions and the following disclaimer in the
12*35c05a4fSAdrian Chadd  *    documentation and/or other materials provided with the distribution.
13*35c05a4fSAdrian Chadd  *
14*35c05a4fSAdrian Chadd  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15*35c05a4fSAdrian Chadd  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16*35c05a4fSAdrian Chadd  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17*35c05a4fSAdrian Chadd  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18*35c05a4fSAdrian Chadd  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19*35c05a4fSAdrian Chadd  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20*35c05a4fSAdrian Chadd  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21*35c05a4fSAdrian Chadd  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22*35c05a4fSAdrian Chadd  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23*35c05a4fSAdrian Chadd  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24*35c05a4fSAdrian Chadd  * SUCH DAMAGE.
25*35c05a4fSAdrian Chadd  */
26*35c05a4fSAdrian Chadd 
27*35c05a4fSAdrian Chadd #ifndef	__LIBRSS_H__
28*35c05a4fSAdrian Chadd #define	__LIBRSS_H__
29*35c05a4fSAdrian Chadd 
30*35c05a4fSAdrian Chadd struct rss_config {
31*35c05a4fSAdrian Chadd 	int rss_ncpus;
32*35c05a4fSAdrian Chadd 	int rss_nbuckets;
33*35c05a4fSAdrian Chadd 	int rss_basecpu;
34*35c05a4fSAdrian Chadd 	int *rss_bucket_map;
35*35c05a4fSAdrian Chadd };
36*35c05a4fSAdrian Chadd 
37*35c05a4fSAdrian Chadd typedef enum {
38*35c05a4fSAdrian Chadd 	RSS_BUCKET_TYPE_NONE = 0,
39*35c05a4fSAdrian Chadd 	RSS_BUCKET_TYPE_KERNEL_ALL = 1,
40*35c05a4fSAdrian Chadd 	RSS_BUCKET_TYPE_KERNEL_TX = 2,
41*35c05a4fSAdrian Chadd 	RSS_BUCKET_TYPE_KERNEL_RX = 3,
42*35c05a4fSAdrian Chadd 	RSS_BUCKET_TYPE_MAX = 3,
43*35c05a4fSAdrian Chadd } rss_bucket_type_t;
44*35c05a4fSAdrian Chadd 
45*35c05a4fSAdrian Chadd typedef void rss_bucket_rebalance_cb_t(void *arg);
46*35c05a4fSAdrian Chadd 
47*35c05a4fSAdrian Chadd /*
48*35c05a4fSAdrian Chadd  * Enable or disable receiving RSS/flowid information on
49*35c05a4fSAdrian Chadd  * received UDP frames.
50*35c05a4fSAdrian Chadd  */
51*35c05a4fSAdrian Chadd extern	int rss_sock_set_recvrss(int fd, int af, int val);
52*35c05a4fSAdrian Chadd 
53*35c05a4fSAdrian Chadd /*
54*35c05a4fSAdrian Chadd  * Fetch RSS configuration information.
55*35c05a4fSAdrian Chadd  */
56*35c05a4fSAdrian Chadd extern	struct rss_config * rss_config_get(void);
57*35c05a4fSAdrian Chadd 
58*35c05a4fSAdrian Chadd /*
59*35c05a4fSAdrian Chadd  * Free an RSS configuration structure.
60*35c05a4fSAdrian Chadd  */
61*35c05a4fSAdrian Chadd extern	void rss_config_free(struct rss_config *rc);
62*35c05a4fSAdrian Chadd 
63*35c05a4fSAdrian Chadd /*
64*35c05a4fSAdrian Chadd  * Return how many RSS buckets there are.
65*35c05a4fSAdrian Chadd  */
66*35c05a4fSAdrian Chadd extern	int rss_config_get_bucket_count(struct rss_config *rc);
67*35c05a4fSAdrian Chadd 
68*35c05a4fSAdrian Chadd /*
69*35c05a4fSAdrian Chadd  * Fetch the cpuset configuration for the given RSS bucket and
70*35c05a4fSAdrian Chadd  * type.
71*35c05a4fSAdrian Chadd  */
72*35c05a4fSAdrian Chadd extern	int rss_get_bucket_cpuset(struct rss_config *rc,
73*35c05a4fSAdrian Chadd     rss_bucket_type_t btype, int bucket, cpuset_t *cs);
74*35c05a4fSAdrian Chadd 
75*35c05a4fSAdrian Chadd /*
76*35c05a4fSAdrian Chadd  * Set a callback for bucket rebalancing.
77*35c05a4fSAdrian Chadd  *
78*35c05a4fSAdrian Chadd  * This will occur in a separate thread context rather than
79*35c05a4fSAdrian Chadd  * a signal handler.
80*35c05a4fSAdrian Chadd  */
81*35c05a4fSAdrian Chadd extern	int rss_set_bucket_rebalance_cb(rss_bucket_rebalance_cb_t *cb,
82*35c05a4fSAdrian Chadd 	    void *cbdata);
83*35c05a4fSAdrian Chadd 
84*35c05a4fSAdrian Chadd #endif /* __LIBRSS_H__ */
85