xref: /freebsd/sys/net/ifdi_if.m (revision 725e4008efef32dfbe57b3e21635fa80dde8ee38)
14c7070dbSScott Long#
27ff9ae90SMarius Strobl# Copyright (c) 2014, Matthew Macy (mmacy@mattmacy.io)
34c7070dbSScott Long# All rights reserved.
44c7070dbSScott Long#
54c7070dbSScott Long# Redistribution and use in source and binary forms, with or without
64c7070dbSScott Long# modification, are permitted provided that the following conditions are met:
74c7070dbSScott Long#
84c7070dbSScott Long#  1. Redistributions of source code must retain the above copyright notice,
94c7070dbSScott Long#     this list of conditions and the following disclaimer.
104c7070dbSScott Long#
114c7070dbSScott Long#  2. Neither the name of Matthew Macy nor the names of its
124c7070dbSScott Long#     contributors may be used to endorse or promote products derived from
134c7070dbSScott Long#     this software without specific prior written permission.
144c7070dbSScott Long#
154c7070dbSScott Long# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
164c7070dbSScott Long# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
174c7070dbSScott Long# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
184c7070dbSScott Long# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
194c7070dbSScott Long# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
204c7070dbSScott Long# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
214c7070dbSScott Long# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
224c7070dbSScott Long# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
234c7070dbSScott Long# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
244c7070dbSScott Long# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
254c7070dbSScott Long# POSSIBILITY OF SUCH DAMAGE.
264c7070dbSScott Long#
274c7070dbSScott Long#
284c7070dbSScott Long
294c7070dbSScott Long#include <sys/types.h>
304c7070dbSScott Long#include <sys/systm.h>
314c7070dbSScott Long#include <sys/socket.h>
324c7070dbSScott Long
334c7070dbSScott Long#include <machine/bus.h>
344c7070dbSScott Long#include <sys/bus.h>
354c7070dbSScott Long
364c7070dbSScott Long#include <net/ethernet.h>
374c7070dbSScott Long#include <net/if.h>
384c7070dbSScott Long#include <net/if_var.h>
394c7070dbSScott Long#include <net/if_media.h>
404c7070dbSScott Long#include <net/iflib.h>
413d0d5b21SJustin Hibbits#include <net/if_private.h>
424c7070dbSScott Long
434c7070dbSScott LongINTERFACE ifdi;
444c7070dbSScott Long
454c7070dbSScott LongCODE {
464c7070dbSScott Long
474c7070dbSScott Long	static void
484c7070dbSScott Long	null_void_op(if_ctx_t _ctx __unused)
494c7070dbSScott Long	{
504c7070dbSScott Long	}
514c7070dbSScott Long
524c7070dbSScott Long	static void
534c7070dbSScott Long	null_timer_op(if_ctx_t _ctx __unused, uint16_t _qsidx __unused)
544c7070dbSScott Long	{
554c7070dbSScott Long	}
564c7070dbSScott Long
574c7070dbSScott Long	static int
584c7070dbSScott Long	null_int_op(if_ctx_t _ctx __unused)
594c7070dbSScott Long	{
604c7070dbSScott Long		return (0);
614c7070dbSScott Long	}
624c7070dbSScott Long
6323ac9029SStephen Hurd	static int
644c7070dbSScott Long	null_queue_intr_enable(if_ctx_t _ctx __unused, uint16_t _qid __unused)
654c7070dbSScott Long	{
6623ac9029SStephen Hurd		return (ENOTSUP);
674c7070dbSScott Long	}
684c7070dbSScott Long
694c7070dbSScott Long	static void
704c7070dbSScott Long	null_led_func(if_ctx_t _ctx __unused, int _onoff __unused)
714c7070dbSScott Long	{
724c7070dbSScott Long	}
734c7070dbSScott Long
744c7070dbSScott Long	static void
754c7070dbSScott Long	null_vlan_register_op(if_ctx_t _ctx __unused, uint16_t vtag __unused)
764c7070dbSScott Long	{
774c7070dbSScott Long	}
784c7070dbSScott Long
794c7070dbSScott Long	static int
804c7070dbSScott Long	null_q_setup(if_ctx_t _ctx __unused, uint32_t _qid __unused)
814c7070dbSScott Long	{
824c7070dbSScott Long		return (0);
834c7070dbSScott Long	}
844c7070dbSScott Long
854c7070dbSScott Long	static int
864c7070dbSScott Long	null_i2c_req(if_ctx_t _sctx __unused, struct ifi2creq *_i2c __unused)
874c7070dbSScott Long	{
884c7070dbSScott Long		return (ENOTSUP);
894c7070dbSScott Long	}
904c7070dbSScott Long
914c7070dbSScott Long	static int
924c7070dbSScott Long	null_sysctl_int_delay(if_ctx_t _sctx __unused, if_int_delay_info_t _iidi __unused)
934c7070dbSScott Long	{
944c7070dbSScott Long		return (0);
954c7070dbSScott Long	}
964c7070dbSScott Long
974c7070dbSScott Long	static int
984c7070dbSScott Long	null_iov_init(if_ctx_t _ctx __unused, uint16_t num_vfs __unused, const nvlist_t *params __unused)
994c7070dbSScott Long	{
1004c7070dbSScott Long		return (ENOTSUP);
1014c7070dbSScott Long	}
1024c7070dbSScott Long
1034c7070dbSScott Long	static int
1044c7070dbSScott Long	null_vf_add(if_ctx_t _ctx __unused, uint16_t num_vfs __unused, const nvlist_t *params __unused)
1054c7070dbSScott Long	{
1064c7070dbSScott Long		return (ENOTSUP);
1074c7070dbSScott Long	}
1084c7070dbSScott Long
1094c7070dbSScott Long	static int
1104c7070dbSScott Long	null_priv_ioctl(if_ctx_t _ctx __unused, u_long command, caddr_t *data __unused)
1114c7070dbSScott Long	{
1124c7070dbSScott Long		return (ENOTSUP);
1134c7070dbSScott Long	}
11409f6ff4fSMatt Macy
11545818bf1SEric Joyner	static bool
11645818bf1SEric Joyner	null_needs_restart(if_ctx_t _ctx __unused, enum iflib_restart_event _event __unused)
11745818bf1SEric Joyner	{
118*725e4008SKevin Bowling		return (false);
11945818bf1SEric Joyner	}
1204c7070dbSScott Long};
1214c7070dbSScott Long
1224c7070dbSScott Long#
1234c7070dbSScott Long# bus interfaces
1244c7070dbSScott Long#
1254c7070dbSScott Long
1264c7070dbSScott LongMETHOD int attach_pre {
1274c7070dbSScott Long	if_ctx_t _ctx;
1287ff9ae90SMarius Strobl};
1294c7070dbSScott Long
1304c7070dbSScott LongMETHOD int attach_post {
1314c7070dbSScott Long	if_ctx_t _ctx;
1327ff9ae90SMarius Strobl};
13309f6ff4fSMatt Macy
13409f6ff4fSMatt MacyMETHOD int reinit_pre {
13509f6ff4fSMatt Macy	if_ctx_t _ctx;
1367ff9ae90SMarius Strobl};
13709f6ff4fSMatt Macy
13809f6ff4fSMatt MacyMETHOD int reinit_post {
13909f6ff4fSMatt Macy	if_ctx_t _ctx;
1407ff9ae90SMarius Strobl};
1414c7070dbSScott Long
1424c7070dbSScott LongMETHOD int detach {
1434c7070dbSScott Long	if_ctx_t _ctx;
1444c7070dbSScott Long};
1454c7070dbSScott Long
1464c7070dbSScott LongMETHOD int suspend {
1474c7070dbSScott Long	if_ctx_t _ctx;
1484c7070dbSScott Long} DEFAULT null_int_op;
1494c7070dbSScott Long
1504c7070dbSScott LongMETHOD int shutdown {
1514c7070dbSScott Long	if_ctx_t _ctx;
1524c7070dbSScott Long} DEFAULT null_int_op;
1534c7070dbSScott Long
1544c7070dbSScott LongMETHOD int resume {
1554c7070dbSScott Long	if_ctx_t _ctx;
1564c7070dbSScott Long} DEFAULT null_int_op;
1574c7070dbSScott Long
1584c7070dbSScott Long#
1594c7070dbSScott Long# downcall to driver to allocate its
1604c7070dbSScott Long# own queue state and tie it to the parent
1614c7070dbSScott Long#
1624c7070dbSScott Long
1634c7070dbSScott LongMETHOD int tx_queues_alloc {
1644c7070dbSScott Long	if_ctx_t _ctx;
1654c7070dbSScott Long	caddr_t *_vaddrs;
1664c7070dbSScott Long	uint64_t *_paddrs;
1674c7070dbSScott Long	int ntxqs;
1684c7070dbSScott Long	int ntxqsets;
1694c7070dbSScott Long};
1704c7070dbSScott Long
1714c7070dbSScott LongMETHOD int rx_queues_alloc {
1724c7070dbSScott Long	if_ctx_t _ctx;
1734c7070dbSScott Long	caddr_t *_vaddrs;
1744c7070dbSScott Long	uint64_t *_paddrs;
1754c7070dbSScott Long	int nrxqs;
1764c7070dbSScott Long	int nrxqsets;
1774c7070dbSScott Long};
1784c7070dbSScott Long
1794c7070dbSScott LongMETHOD void queues_free {
1804c7070dbSScott Long	if_ctx_t _ctx;
1817ff9ae90SMarius Strobl};
1824c7070dbSScott Long
1834c7070dbSScott Long#
1844c7070dbSScott Long# interface reset / stop
1854c7070dbSScott Long#
1864c7070dbSScott Long
1874c7070dbSScott LongMETHOD void init {
1884c7070dbSScott Long	if_ctx_t _ctx;
1894c7070dbSScott Long};
1904c7070dbSScott Long
1914c7070dbSScott LongMETHOD void stop {
1924c7070dbSScott Long	if_ctx_t _ctx;
1934c7070dbSScott Long};
1944c7070dbSScott Long
1954c7070dbSScott Long#
1964c7070dbSScott Long# interrupt setup and manipulation
1974c7070dbSScott Long#
1984c7070dbSScott Long
1994c7070dbSScott LongMETHOD int msix_intr_assign {
2004c7070dbSScott Long	if_ctx_t _sctx;
2014c7070dbSScott Long	int msix;
2027ff9ae90SMarius Strobl};
2034c7070dbSScott Long
2044c7070dbSScott LongMETHOD void intr_enable {
2054c7070dbSScott Long	if_ctx_t _ctx;
2064c7070dbSScott Long};
2074c7070dbSScott Long
2084c7070dbSScott LongMETHOD void intr_disable {
2094c7070dbSScott Long	if_ctx_t _ctx;
2104c7070dbSScott Long};
2114c7070dbSScott Long
21295246abbSSean BrunoMETHOD int rx_queue_intr_enable {
21395246abbSSean Bruno	if_ctx_t _ctx;
21495246abbSSean Bruno	uint16_t _qid;
21595246abbSSean Bruno} DEFAULT null_queue_intr_enable;
21695246abbSSean Bruno
21795246abbSSean BrunoMETHOD int tx_queue_intr_enable {
2184c7070dbSScott Long	if_ctx_t _ctx;
2194c7070dbSScott Long	uint16_t _qid;
2204c7070dbSScott Long} DEFAULT null_queue_intr_enable;
2214c7070dbSScott Long
2224c7070dbSScott LongMETHOD void link_intr_enable {
2234c7070dbSScott Long	if_ctx_t _ctx;
2244c7070dbSScott Long} DEFAULT null_void_op;
2254c7070dbSScott Long
22609c3f04fSMarcin WojtasMETHOD void admin_completion_handle {
22709c3f04fSMarcin Wojtas	if_ctx_t _ctx;
22809c3f04fSMarcin Wojtas} DEFAULT null_void_op;
22909c3f04fSMarcin Wojtas
2304c7070dbSScott Long#
2314c7070dbSScott Long# interface configuration
2324c7070dbSScott Long#
2334c7070dbSScott Long
2344c7070dbSScott LongMETHOD void multi_set {
2354c7070dbSScott Long	if_ctx_t _ctx;
2364c7070dbSScott Long};
2374c7070dbSScott Long
2384c7070dbSScott LongMETHOD int mtu_set {
2394c7070dbSScott Long	if_ctx_t _ctx;
2404c7070dbSScott Long	uint32_t _mtu;
2414c7070dbSScott Long};
2424c7070dbSScott Long
2434c7070dbSScott LongMETHOD void media_set{
2444c7070dbSScott Long	if_ctx_t _ctx;
2454c7070dbSScott Long} DEFAULT null_void_op;
2464c7070dbSScott Long
2474c7070dbSScott LongMETHOD int promisc_set {
2484c7070dbSScott Long	if_ctx_t _ctx;
2494c7070dbSScott Long	int _flags;
2504c7070dbSScott Long};
2514c7070dbSScott Long
2524c7070dbSScott LongMETHOD void crcstrip_set {
2534c7070dbSScott Long	if_ctx_t _ctx;
2544c7070dbSScott Long	int _onoff;
2551248952aSSean Bruno	int _strip;
2564c7070dbSScott Long};
2574c7070dbSScott Long
2584c7070dbSScott Long#
2594c7070dbSScott Long# IOV handling
2604c7070dbSScott Long#
2614c7070dbSScott Long
2624c7070dbSScott LongMETHOD void vflr_handle {
2634c7070dbSScott Long	if_ctx_t _ctx;
2644c7070dbSScott Long} DEFAULT null_void_op;
2654c7070dbSScott Long
2664c7070dbSScott LongMETHOD int iov_init {
2674c7070dbSScott Long	if_ctx_t _ctx;
2684c7070dbSScott Long	uint16_t num_vfs;
2694c7070dbSScott Long	const nvlist_t * params;
2704c7070dbSScott Long} DEFAULT null_iov_init;
2714c7070dbSScott Long
2724c7070dbSScott LongMETHOD void iov_uninit {
2734c7070dbSScott Long	if_ctx_t _ctx;
2744c7070dbSScott Long} DEFAULT null_void_op;
2754c7070dbSScott Long
2764c7070dbSScott LongMETHOD int iov_vf_add {
2774c7070dbSScott Long	if_ctx_t _ctx;
2784c7070dbSScott Long	uint16_t num_vfs;
2794c7070dbSScott Long	const nvlist_t * params;
2804c7070dbSScott Long} DEFAULT null_vf_add;
2814c7070dbSScott Long
2824c7070dbSScott Long
2834c7070dbSScott Long#
2844c7070dbSScott Long# Device status
2854c7070dbSScott Long#
2864c7070dbSScott Long
2874c7070dbSScott LongMETHOD void update_admin_status {
2884c7070dbSScott Long	if_ctx_t _ctx;
2894c7070dbSScott Long};
2904c7070dbSScott Long
2914c7070dbSScott LongMETHOD void media_status {
2924c7070dbSScott Long	if_ctx_t _ctx;
2934c7070dbSScott Long	struct ifmediareq *_ifm;
2947ff9ae90SMarius Strobl};
2954c7070dbSScott Long
2964c7070dbSScott LongMETHOD int media_change {
2974c7070dbSScott Long	if_ctx_t _ctx;
2987ff9ae90SMarius Strobl};
2994c7070dbSScott Long
3004c7070dbSScott LongMETHOD uint64_t get_counter {
3014c7070dbSScott Long	if_ctx_t _ctx;
3024c7070dbSScott Long	ift_counter cnt;
3034c7070dbSScott Long};
3044c7070dbSScott Long
3054c7070dbSScott LongMETHOD int priv_ioctl {
3064c7070dbSScott Long	if_ctx_t _ctx;
3074c7070dbSScott Long	u_long   _cmd;
3084c7070dbSScott Long	caddr_t _data;
3094c7070dbSScott Long} DEFAULT null_priv_ioctl;
3104c7070dbSScott Long
3114c7070dbSScott Long#
3124c7070dbSScott Long# optional methods
3134c7070dbSScott Long#
3144c7070dbSScott Long
3154c7070dbSScott LongMETHOD int i2c_req {
3164c7070dbSScott Long	if_ctx_t _ctx;
3174c7070dbSScott Long	struct ifi2creq *_req;
3184c7070dbSScott Long} DEFAULT null_i2c_req;
3194c7070dbSScott Long
3204c7070dbSScott LongMETHOD int txq_setup {
3214c7070dbSScott Long	if_ctx_t _ctx;
3224c7070dbSScott Long	uint32_t _txqid;
3234c7070dbSScott Long} DEFAULT null_q_setup;
3244c7070dbSScott Long
3254c7070dbSScott LongMETHOD int rxq_setup {
3264c7070dbSScott Long	if_ctx_t _ctx;
3274c7070dbSScott Long	uint32_t _txqid;
3284c7070dbSScott Long} DEFAULT null_q_setup;
3294c7070dbSScott Long
3304c7070dbSScott LongMETHOD void timer {
3314c7070dbSScott Long	if_ctx_t _ctx;
3324c7070dbSScott Long	uint16_t _txqid;
3334c7070dbSScott Long} DEFAULT null_timer_op;
3344c7070dbSScott Long
3354c7070dbSScott LongMETHOD void watchdog_reset {
3364c7070dbSScott Long	if_ctx_t _ctx;
3374c7070dbSScott Long} DEFAULT null_void_op;
3384c7070dbSScott Long
3394c7070dbSScott LongMETHOD void led_func {
3404c7070dbSScott Long	if_ctx_t _ctx;
3414c7070dbSScott Long	int _onoff;
3424c7070dbSScott Long} DEFAULT null_led_func;
3434c7070dbSScott Long
3444c7070dbSScott LongMETHOD void vlan_register {
3454c7070dbSScott Long	if_ctx_t _ctx;
3464c7070dbSScott Long	uint16_t _vtag;
3474c7070dbSScott Long} DEFAULT null_vlan_register_op;
3484c7070dbSScott Long
3494c7070dbSScott LongMETHOD void vlan_unregister {
3504c7070dbSScott Long	if_ctx_t _ctx;
3514c7070dbSScott Long	uint16_t _vtag;
3524c7070dbSScott Long} DEFAULT null_vlan_register_op;
3534c7070dbSScott Long
3544c7070dbSScott LongMETHOD int sysctl_int_delay {
3554c7070dbSScott Long	if_ctx_t _sctx;
3564c7070dbSScott Long	if_int_delay_info_t _iidi;
3574c7070dbSScott Long} DEFAULT null_sysctl_int_delay;
3584c7070dbSScott Long
35995246abbSSean BrunoMETHOD void debug {
36095246abbSSean Bruno	if_ctx_t _ctx;
36195246abbSSean Bruno} DEFAULT null_void_op;
36245818bf1SEric Joyner
36345818bf1SEric JoynerMETHOD bool needs_restart {
36445818bf1SEric Joyner	if_ctx_t _ctx;
36545818bf1SEric Joyner	enum iflib_restart_event _event;
36645818bf1SEric Joyner} DEFAULT null_needs_restart;
367