xref: /freebsd/sys/net/ifdi_if.m (revision 43a5ec4eb41567cc92586503212743d89686d78f)
1#
2# Copyright (c) 2014-2018, Matthew Macy (mmacy@mattmacy.io)
3# All rights reserved.
4#
5# Redistribution and use in source and binary forms, with or without
6# modification, are permitted provided that the following conditions are met:
7#
8#  1. Redistributions of source code must retain the above copyright notice,
9#     this list of conditions and the following disclaimer.
10#
11#  2. Neither the name of Matthew Macy nor the names of its
12#     contributors may be used to endorse or promote products derived from
13#     this software without specific prior written permission.
14#
15# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
16# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
19# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25# POSSIBILITY OF SUCH DAMAGE.
26#
27# $FreeBSD$
28#
29
30#include <sys/types.h>
31#include <sys/systm.h>
32#include <sys/socket.h>
33
34#include <machine/bus.h>
35#include <sys/bus.h>
36
37#include <net/ethernet.h>
38#include <net/if.h>
39#include <net/if_var.h>
40#include <net/if_media.h>
41#include <net/iflib.h>
42#include <net/if_clone.h>
43#include <net/if_dl.h>
44#include <net/if_types.h>
45
46INTERFACE ifdi;
47
48CODE {
49
50	static void
51	null_void_op(if_ctx_t _ctx __unused)
52	{
53	}
54
55	static int
56	null_knlist_add(if_ctx_t _ctx __unused, struct knote *_kn)
57	{
58	    return (0);
59	}
60
61	static int
62	null_knote_event(if_ctx_t _ctx __unused, struct knote *_kn, int _hint)
63	{
64	    return (0);
65	}
66
67	static void
68	null_timer_op(if_ctx_t _ctx __unused, uint16_t _qsidx __unused)
69	{
70	}
71
72	static int
73	null_int_op(if_ctx_t _ctx __unused)
74	{
75		return (0);
76	}
77
78	static int
79	null_int_int_op(if_ctx_t _ctx __unused, int arg0 __unused)
80	{
81		return (ENOTSUP);
82	}
83
84	static int
85	null_queue_intr_enable(if_ctx_t _ctx __unused, uint16_t _qid __unused)
86	{
87		return (ENOTSUP);
88	}
89
90	static void
91	null_led_func(if_ctx_t _ctx __unused, int _onoff __unused)
92	{
93	}
94
95	static void
96	null_vlan_register_op(if_ctx_t _ctx __unused, uint16_t vtag __unused)
97	{
98	}
99
100	static int
101	null_q_setup(if_ctx_t _ctx __unused, uint32_t _qid __unused)
102	{
103		return (0);
104	}
105
106	static int
107	null_i2c_req(if_ctx_t _sctx __unused, struct ifi2creq *_i2c __unused)
108	{
109		return (ENOTSUP);
110	}
111
112	static int
113	null_sysctl_int_delay(if_ctx_t _sctx __unused, if_int_delay_info_t _iidi __unused)
114	{
115		return (0);
116	}
117
118	static int
119	null_iov_init(if_ctx_t _ctx __unused, uint16_t num_vfs __unused, const nvlist_t *params __unused)
120	{
121		return (ENOTSUP);
122	}
123
124	static int
125	null_vf_add(if_ctx_t _ctx __unused, uint16_t num_vfs __unused, const nvlist_t *params __unused)
126	{
127		return (ENOTSUP);
128	}
129
130	static int
131	null_priv_ioctl(if_ctx_t _ctx __unused, u_long command, caddr_t *data __unused)
132	{
133		return (ENOTSUP);
134	}
135
136	static void
137	null_media_status(if_ctx_t ctx __unused, struct ifmediareq *ifmr)
138	{
139	    ifmr->ifm_status = IFM_AVALID | IFM_ACTIVE;
140	    ifmr->ifm_active = IFM_ETHER | IFM_25G_ACC | IFM_FDX;
141	}
142
143	static int
144	null_cloneattach(if_ctx_t ctx __unused, struct if_clone *ifc __unused,
145			 const char *name __unused, caddr_t params __unused)
146	{
147	    return (0);
148	}
149
150	static void
151	null_rx_clset(if_ctx_t _ctx __unused, uint16_t _flid __unused,
152		      uint16_t _qid __unused, caddr_t *_sdcl __unused)
153	{
154	}
155	static void
156	null_object_info_get(if_ctx_t ctx __unused, void *data __unused, int size __unused)
157	{
158	}
159	static int
160	default_mac_set(if_ctx_t ctx, const uint8_t *mac)
161	{
162	    struct ifnet *ifp = iflib_get_ifp(ctx);
163	    struct sockaddr_dl *sdl;
164
165	    if (ifp && ifp->if_addr) {
166		sdl = (struct sockaddr_dl *)ifp->if_addr->ifa_addr;
167		MPASS(sdl->sdl_type == IFT_ETHER);
168		memcpy(LLADDR(sdl), mac, ETHER_ADDR_LEN);
169	    }
170	    return (0);
171	}
172
173	static bool
174	null_needs_restart(if_ctx_t _ctx __unused, enum iflib_restart_event _event __unused)
175	{
176		return (true);
177	}
178};
179
180#
181# kevent interfaces
182#
183
184METHOD int knlist_add {
185	if_ctx_t _ctx;
186	struct knote *_kn;
187} DEFAULT null_knlist_add;
188
189METHOD int knote_event {
190	if_ctx_t _ctx;
191	struct knote *_kn;
192	int hint;
193} DEFAULT null_knote_event;
194
195
196#
197# query
198#
199
200METHOD int object_info_get {
201	if_ctx_t _ctx;
202	void *data;
203	int size;
204} DEFAULT null_object_info_get;
205
206#
207# bus interfaces
208#
209
210METHOD int attach_pre {
211	if_ctx_t _ctx;
212} DEFAULT null_int_op;
213
214METHOD int attach_post {
215	if_ctx_t _ctx;
216} DEFAULT null_int_op;
217
218METHOD int reinit_pre {
219	if_ctx_t _ctx;
220} DEFAULT null_int_op;
221
222METHOD int reinit_post {
223	if_ctx_t _ctx;
224} DEFAULT null_int_op;
225
226METHOD int cloneattach {
227	if_ctx_t _ctx;
228	struct if_clone *_ifc;
229	const char *_name;
230	caddr_t params;
231} DEFAULT null_cloneattach;
232
233METHOD int detach {
234	if_ctx_t _ctx;
235};
236
237METHOD int suspend {
238	if_ctx_t _ctx;
239} DEFAULT null_int_op;
240
241METHOD int shutdown {
242	if_ctx_t _ctx;
243} DEFAULT null_int_op;
244
245METHOD int resume {
246	if_ctx_t _ctx;
247} DEFAULT null_int_op;
248
249#
250# downcall to driver to allocate its
251# own queue state and tie it to the parent
252#
253
254METHOD int tx_queues_alloc {
255	if_ctx_t _ctx;
256	caddr_t *_vaddrs;
257	uint64_t *_paddrs;
258	int ntxqs;
259	int ntxqsets;
260};
261
262METHOD int rx_queues_alloc {
263	if_ctx_t _ctx;
264	caddr_t *_vaddrs;
265	uint64_t *_paddrs;
266	int nrxqs;
267	int nrxqsets;
268};
269
270METHOD void queues_free {
271	if_ctx_t _ctx;
272} DEFAULT null_void_op;
273
274METHOD void rx_clset {
275	if_ctx_t _ctx;
276	uint16_t _fl;
277	uint16_t _qsetid;
278	caddr_t *_sdcl;
279} DEFAULT null_rx_clset;
280
281#
282# interface reset / stop
283#
284
285METHOD void init {
286	if_ctx_t _ctx;
287};
288
289METHOD void stop {
290	if_ctx_t _ctx;
291};
292
293#
294# interrupt setup and manipulation
295#
296
297METHOD int msix_intr_assign {
298	if_ctx_t _sctx;
299	int msix;
300} DEFAULT null_int_int_op;
301
302METHOD void intr_enable {
303	if_ctx_t _ctx;
304};
305
306METHOD void intr_disable {
307	if_ctx_t _ctx;
308};
309
310METHOD int rx_queue_intr_enable {
311	if_ctx_t _ctx;
312	uint16_t _qid;
313} DEFAULT null_queue_intr_enable;
314
315METHOD int tx_queue_intr_enable {
316	if_ctx_t _ctx;
317	uint16_t _qid;
318} DEFAULT null_queue_intr_enable;
319
320METHOD void link_intr_enable {
321	if_ctx_t _ctx;
322} DEFAULT null_void_op;
323
324METHOD void admin_completion_handle {
325	if_ctx_t _ctx;
326} DEFAULT null_void_op;
327
328#
329# interface configuration
330#
331
332METHOD void multi_set {
333	if_ctx_t _ctx;
334};
335
336METHOD int mtu_set {
337	if_ctx_t _ctx;
338	uint32_t _mtu;
339};
340METHOD int mac_set {
341	if_ctx_t _ctx;
342	const uint8_t *_mac;
343} DEFAULT default_mac_set;
344
345METHOD void media_set{
346	if_ctx_t _ctx;
347} DEFAULT null_void_op;
348
349METHOD int promisc_set {
350	if_ctx_t _ctx;
351	int _flags;
352};
353
354METHOD void crcstrip_set {
355	if_ctx_t _ctx;
356	int _onoff;
357	int _strip;
358};
359
360#
361# IOV handling
362#
363
364METHOD void vflr_handle {
365	if_ctx_t _ctx;
366} DEFAULT null_void_op;
367
368METHOD int iov_init {
369	if_ctx_t _ctx;
370	uint16_t num_vfs;
371	const nvlist_t * params;
372} DEFAULT null_iov_init;
373
374METHOD void iov_uninit {
375	if_ctx_t _ctx;
376} DEFAULT null_void_op;
377
378METHOD int iov_vf_add {
379	if_ctx_t _ctx;
380	uint16_t num_vfs;
381	const nvlist_t * params;
382} DEFAULT null_vf_add;
383
384
385#
386# Device status
387#
388
389METHOD void update_admin_status {
390	if_ctx_t _ctx;
391};
392
393METHOD void media_status {
394	if_ctx_t _ctx;
395	struct ifmediareq *_ifm;
396} DEFAULT null_media_status;
397
398METHOD int media_change {
399	if_ctx_t _ctx;
400} DEFAULT null_int_op;
401
402METHOD uint64_t get_counter {
403	if_ctx_t _ctx;
404	ift_counter cnt;
405};
406
407METHOD int priv_ioctl {
408	if_ctx_t _ctx;
409	u_long   _cmd;
410	caddr_t _data;
411} DEFAULT null_priv_ioctl;
412
413#
414# optional methods
415#
416
417METHOD int i2c_req {
418	if_ctx_t _ctx;
419	struct ifi2creq *_req;
420} DEFAULT null_i2c_req;
421
422METHOD int txq_setup {
423	if_ctx_t _ctx;
424	uint32_t _txqid;
425} DEFAULT null_q_setup;
426
427METHOD int rxq_setup {
428	if_ctx_t _ctx;
429	uint32_t _txqid;
430} DEFAULT null_q_setup;
431
432METHOD void timer {
433	if_ctx_t _ctx;
434	uint16_t _txqid;
435} DEFAULT null_timer_op;
436
437METHOD void watchdog_reset {
438	if_ctx_t _ctx;
439} DEFAULT null_void_op;
440
441METHOD void watchdog_reset_queue {
442	if_ctx_t _ctx;
443	uint16_t _q;
444} DEFAULT null_timer_op;
445
446METHOD void led_func {
447	if_ctx_t _ctx;
448	int _onoff;
449} DEFAULT null_led_func;
450
451METHOD void vlan_register {
452	if_ctx_t _ctx;
453	uint16_t _vtag;
454} DEFAULT null_vlan_register_op;
455
456METHOD void vlan_unregister {
457	if_ctx_t _ctx;
458	uint16_t _vtag;
459} DEFAULT null_vlan_register_op;
460
461METHOD int sysctl_int_delay {
462	if_ctx_t _sctx;
463	if_int_delay_info_t _iidi;
464} DEFAULT null_sysctl_int_delay;
465
466METHOD void debug {
467	if_ctx_t _ctx;
468} DEFAULT null_void_op;
469
470METHOD bool needs_restart {
471	if_ctx_t _ctx;
472	enum iflib_restart_event _event;
473} DEFAULT null_needs_restart;
474