xref: /freebsd/sys/net/ifdi_if.m (revision 3d0d5b21)
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_private.h>
45#include <net/if_types.h>
46
47INTERFACE ifdi;
48
49CODE {
50
51	static void
52	null_void_op(if_ctx_t _ctx __unused)
53	{
54	}
55
56	static int
57	null_knlist_add(if_ctx_t _ctx __unused, struct knote *_kn)
58	{
59	    return (0);
60	}
61
62	static int
63	null_knote_event(if_ctx_t _ctx __unused, struct knote *_kn, int _hint)
64	{
65	    return (0);
66	}
67
68	static void
69	null_timer_op(if_ctx_t _ctx __unused, uint16_t _qsidx __unused)
70	{
71	}
72
73	static int
74	null_int_op(if_ctx_t _ctx __unused)
75	{
76		return (0);
77	}
78
79	static int
80	null_int_int_op(if_ctx_t _ctx __unused, int arg0 __unused)
81	{
82		return (ENOTSUP);
83	}
84
85	static int
86	null_queue_intr_enable(if_ctx_t _ctx __unused, uint16_t _qid __unused)
87	{
88		return (ENOTSUP);
89	}
90
91	static void
92	null_led_func(if_ctx_t _ctx __unused, int _onoff __unused)
93	{
94	}
95
96	static void
97	null_vlan_register_op(if_ctx_t _ctx __unused, uint16_t vtag __unused)
98	{
99	}
100
101	static int
102	null_q_setup(if_ctx_t _ctx __unused, uint32_t _qid __unused)
103	{
104		return (0);
105	}
106
107	static int
108	null_i2c_req(if_ctx_t _sctx __unused, struct ifi2creq *_i2c __unused)
109	{
110		return (ENOTSUP);
111	}
112
113	static int
114	null_sysctl_int_delay(if_ctx_t _sctx __unused, if_int_delay_info_t _iidi __unused)
115	{
116		return (0);
117	}
118
119	static int
120	null_iov_init(if_ctx_t _ctx __unused, uint16_t num_vfs __unused, const nvlist_t *params __unused)
121	{
122		return (ENOTSUP);
123	}
124
125	static int
126	null_vf_add(if_ctx_t _ctx __unused, uint16_t num_vfs __unused, const nvlist_t *params __unused)
127	{
128		return (ENOTSUP);
129	}
130
131	static int
132	null_priv_ioctl(if_ctx_t _ctx __unused, u_long command, caddr_t *data __unused)
133	{
134		return (ENOTSUP);
135	}
136
137	static void
138	null_media_status(if_ctx_t ctx __unused, struct ifmediareq *ifmr)
139	{
140	    ifmr->ifm_status = IFM_AVALID | IFM_ACTIVE;
141	    ifmr->ifm_active = IFM_ETHER | IFM_25G_ACC | IFM_FDX;
142	}
143
144	static int
145	null_cloneattach(if_ctx_t ctx __unused, struct if_clone *ifc __unused,
146			 const char *name __unused, caddr_t params __unused)
147	{
148	    return (0);
149	}
150
151	static void
152	null_rx_clset(if_ctx_t _ctx __unused, uint16_t _flid __unused,
153		      uint16_t _qid __unused, caddr_t *_sdcl __unused)
154	{
155	}
156	static void
157	null_object_info_get(if_ctx_t ctx __unused, void *data __unused, int size __unused)
158	{
159	}
160	static int
161	default_mac_set(if_ctx_t ctx, const uint8_t *mac)
162	{
163	    struct ifnet *ifp = iflib_get_ifp(ctx);
164	    struct sockaddr_dl *sdl;
165
166	    if (ifp && ifp->if_addr) {
167		sdl = (struct sockaddr_dl *)ifp->if_addr->ifa_addr;
168		MPASS(sdl->sdl_type == IFT_ETHER);
169		memcpy(LLADDR(sdl), mac, ETHER_ADDR_LEN);
170	    }
171	    return (0);
172	}
173
174	static bool
175	null_needs_restart(if_ctx_t _ctx __unused, enum iflib_restart_event _event __unused)
176	{
177		return (true);
178	}
179};
180
181#
182# kevent interfaces
183#
184
185METHOD int knlist_add {
186	if_ctx_t _ctx;
187	struct knote *_kn;
188} DEFAULT null_knlist_add;
189
190METHOD int knote_event {
191	if_ctx_t _ctx;
192	struct knote *_kn;
193	int hint;
194} DEFAULT null_knote_event;
195
196
197#
198# query
199#
200
201METHOD int object_info_get {
202	if_ctx_t _ctx;
203	void *data;
204	int size;
205} DEFAULT null_object_info_get;
206
207#
208# bus interfaces
209#
210
211METHOD int attach_pre {
212	if_ctx_t _ctx;
213} DEFAULT null_int_op;
214
215METHOD int attach_post {
216	if_ctx_t _ctx;
217} DEFAULT null_int_op;
218
219METHOD int reinit_pre {
220	if_ctx_t _ctx;
221} DEFAULT null_int_op;
222
223METHOD int reinit_post {
224	if_ctx_t _ctx;
225} DEFAULT null_int_op;
226
227METHOD int cloneattach {
228	if_ctx_t _ctx;
229	struct if_clone *_ifc;
230	const char *_name;
231	caddr_t params;
232} DEFAULT null_cloneattach;
233
234METHOD int detach {
235	if_ctx_t _ctx;
236};
237
238METHOD int suspend {
239	if_ctx_t _ctx;
240} DEFAULT null_int_op;
241
242METHOD int shutdown {
243	if_ctx_t _ctx;
244} DEFAULT null_int_op;
245
246METHOD int resume {
247	if_ctx_t _ctx;
248} DEFAULT null_int_op;
249
250#
251# downcall to driver to allocate its
252# own queue state and tie it to the parent
253#
254
255METHOD int tx_queues_alloc {
256	if_ctx_t _ctx;
257	caddr_t *_vaddrs;
258	uint64_t *_paddrs;
259	int ntxqs;
260	int ntxqsets;
261};
262
263METHOD int rx_queues_alloc {
264	if_ctx_t _ctx;
265	caddr_t *_vaddrs;
266	uint64_t *_paddrs;
267	int nrxqs;
268	int nrxqsets;
269};
270
271METHOD void queues_free {
272	if_ctx_t _ctx;
273} DEFAULT null_void_op;
274
275METHOD void rx_clset {
276	if_ctx_t _ctx;
277	uint16_t _fl;
278	uint16_t _qsetid;
279	caddr_t *_sdcl;
280} DEFAULT null_rx_clset;
281
282#
283# interface reset / stop
284#
285
286METHOD void init {
287	if_ctx_t _ctx;
288};
289
290METHOD void stop {
291	if_ctx_t _ctx;
292};
293
294#
295# interrupt setup and manipulation
296#
297
298METHOD int msix_intr_assign {
299	if_ctx_t _sctx;
300	int msix;
301} DEFAULT null_int_int_op;
302
303METHOD void intr_enable {
304	if_ctx_t _ctx;
305};
306
307METHOD void intr_disable {
308	if_ctx_t _ctx;
309};
310
311METHOD int rx_queue_intr_enable {
312	if_ctx_t _ctx;
313	uint16_t _qid;
314} DEFAULT null_queue_intr_enable;
315
316METHOD int tx_queue_intr_enable {
317	if_ctx_t _ctx;
318	uint16_t _qid;
319} DEFAULT null_queue_intr_enable;
320
321METHOD void link_intr_enable {
322	if_ctx_t _ctx;
323} DEFAULT null_void_op;
324
325METHOD void admin_completion_handle {
326	if_ctx_t _ctx;
327} DEFAULT null_void_op;
328
329#
330# interface configuration
331#
332
333METHOD void multi_set {
334	if_ctx_t _ctx;
335};
336
337METHOD int mtu_set {
338	if_ctx_t _ctx;
339	uint32_t _mtu;
340};
341METHOD int mac_set {
342	if_ctx_t _ctx;
343	const uint8_t *_mac;
344} DEFAULT default_mac_set;
345
346METHOD void media_set{
347	if_ctx_t _ctx;
348} DEFAULT null_void_op;
349
350METHOD int promisc_set {
351	if_ctx_t _ctx;
352	int _flags;
353};
354
355METHOD void crcstrip_set {
356	if_ctx_t _ctx;
357	int _onoff;
358	int _strip;
359};
360
361#
362# IOV handling
363#
364
365METHOD void vflr_handle {
366	if_ctx_t _ctx;
367} DEFAULT null_void_op;
368
369METHOD int iov_init {
370	if_ctx_t _ctx;
371	uint16_t num_vfs;
372	const nvlist_t * params;
373} DEFAULT null_iov_init;
374
375METHOD void iov_uninit {
376	if_ctx_t _ctx;
377} DEFAULT null_void_op;
378
379METHOD int iov_vf_add {
380	if_ctx_t _ctx;
381	uint16_t num_vfs;
382	const nvlist_t * params;
383} DEFAULT null_vf_add;
384
385
386#
387# Device status
388#
389
390METHOD void update_admin_status {
391	if_ctx_t _ctx;
392};
393
394METHOD void media_status {
395	if_ctx_t _ctx;
396	struct ifmediareq *_ifm;
397} DEFAULT null_media_status;
398
399METHOD int media_change {
400	if_ctx_t _ctx;
401} DEFAULT null_int_op;
402
403METHOD uint64_t get_counter {
404	if_ctx_t _ctx;
405	ift_counter cnt;
406};
407
408METHOD int priv_ioctl {
409	if_ctx_t _ctx;
410	u_long   _cmd;
411	caddr_t _data;
412} DEFAULT null_priv_ioctl;
413
414#
415# optional methods
416#
417
418METHOD int i2c_req {
419	if_ctx_t _ctx;
420	struct ifi2creq *_req;
421} DEFAULT null_i2c_req;
422
423METHOD int txq_setup {
424	if_ctx_t _ctx;
425	uint32_t _txqid;
426} DEFAULT null_q_setup;
427
428METHOD int rxq_setup {
429	if_ctx_t _ctx;
430	uint32_t _txqid;
431} DEFAULT null_q_setup;
432
433METHOD void timer {
434	if_ctx_t _ctx;
435	uint16_t _txqid;
436} DEFAULT null_timer_op;
437
438METHOD void watchdog_reset {
439	if_ctx_t _ctx;
440} DEFAULT null_void_op;
441
442METHOD void watchdog_reset_queue {
443	if_ctx_t _ctx;
444	uint16_t _q;
445} DEFAULT null_timer_op;
446
447METHOD void led_func {
448	if_ctx_t _ctx;
449	int _onoff;
450} DEFAULT null_led_func;
451
452METHOD void vlan_register {
453	if_ctx_t _ctx;
454	uint16_t _vtag;
455} DEFAULT null_vlan_register_op;
456
457METHOD void vlan_unregister {
458	if_ctx_t _ctx;
459	uint16_t _vtag;
460} DEFAULT null_vlan_register_op;
461
462METHOD int sysctl_int_delay {
463	if_ctx_t _sctx;
464	if_int_delay_info_t _iidi;
465} DEFAULT null_sysctl_int_delay;
466
467METHOD void debug {
468	if_ctx_t _ctx;
469} DEFAULT null_void_op;
470
471METHOD bool needs_restart {
472	if_ctx_t _ctx;
473	enum iflib_restart_event _event;
474} DEFAULT null_needs_restart;
475