1 /*
2 * Copyright (c) 2015-2022 Apple Inc. All rights reserved.
3 *
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
5 *
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. The rights granted to you under the License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
14 *
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
17 *
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
24 * limitations under the License.
25 *
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
27 */
28
29 /*
30 * Copyright (C) 2011-2014 Matteo Landi, Luigi Rizzo. All rights reserved.
31 * Copyright (C) 2013-2014 Universita` di Pisa. All rights reserved.
32 *
33 * Redistribution and use in source and binary forms, with or without
34 * modification, are permitted provided that the following conditions
35 * are met:
36 * 1. Redistributions of source code must retain the above copyright
37 * notice, this list of conditions and the following disclaimer.
38 * 2. Redistributions in binary form must reproduce the above copyright
39 * notice, this list of conditions and the following disclaimer in the
40 * documentation and/or other materials provided with the distribution.
41 *
42 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
43 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
44 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
45 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
46 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
47 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
48 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
49 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
50 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
51 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
52 * SUCH DAMAGE.
53 */
54
55 #ifndef _SKYWALK_NEXUS_ADAPTER_H_
56 #define _SKYWALK_NEXUS_ADAPTER_H_
57
58 #ifdef BSD_KERNEL_PRIVATE
59 #include <skywalk/os_skywalk_private.h>
60 #include <skywalk/os_packet_private.h>
61
62 #define NEXUS_ADAPTER_NAMELEN 64
63
64 struct chreq;
65 struct kern_nexus;
66 struct __kern_channel_ring;
67 struct nexus_vp_adapter;
68 struct nexus_upipe_adapter;
69
70 typedef enum {
71 NA_INVALID = 0, /* uninitialized */
72 NA_PSEUDO, /* struct nexus_adapter */
73 #if CONFIG_NEXUS_USER_PIPE
74 NA_USER_PIPE, /* struct nexus_upipe_adapter */
75 #endif /* CONFIG_NEXUS_USER_PIPE */
76 #if CONFIG_NEXUS_KERNEL_PIPE
77 NA_KERNEL_PIPE, /* struct nexus_kpipe_adapter */
78 #endif /* CONFIG_NEXUS_KERNEL_PIPE */
79 #if CONFIG_NEXUS_MONITOR
80 NA_MONITOR, /* struct nexus_monitor_adapter */
81 #endif /* CONFIG_NEXUS_MONITOR */
82 #if CONFIG_NEXUS_NETIF
83 NA_NETIF_DEV, /* struct nexus_netif_adapter (dev) */
84 NA_NETIF_HOST, /* struct nexus_netif_adapter (host) */
85 NA_NETIF_COMPAT_DEV, /* struct nexus_netif_compat_adapter (dev) */
86 NA_NETIF_COMPAT_HOST, /* struct nexus_netif_compat_adapter (host) */
87 NA_NETIF_FILTER, /* struct nexus_netif_adapter (vp) */
88 NA_NETIF_VP, /* struct nexus_netif_adapter (vp) */
89 #endif /* CONFIG_NEXUS_NETIF */
90 #if CONFIG_NEXUS_FLOWSWITCH
91 NA_FLOWSWITCH_VP, /* struct nexus_vp_adapter */
92 #endif /* CONFIG_NEXUS_FLOWSWITCH */
93 } nexus_adapter_type_t;
94
95 typedef enum {
96 NXSPEC_CMD_CONNECT = 0,
97 NXSPEC_CMD_DISCONNECT = 1,
98 NXSPEC_CMD_START = 2,
99 NXSPEC_CMD_STOP = 3,
100 } nxspec_cmd_t;
101
102 typedef enum {
103 NA_ACTIVATE_MODE_ON = 0, /* activate adapter */
104 NA_ACTIVATE_MODE_DEFUNCT, /* defunct an activate adapter */
105 NA_ACTIVATE_MODE_OFF, /* deactivate adapter */
106 } na_activate_mode_t;
107
108 struct nexus_pkt_stats {
109 uint64_t nps_pkts;
110 uint64_t nps_bytes;
111 };
112
113 /*
114 * The "struct nexus_adapter" contains all base fields needed to support
115 * Nexus adapter operations. There are different types of Nexus adapters
116 * (upipe, kpipe, fsw, monitor, vp, ...) so a nexus_adapter is
117 * always the first field in the derived type.
118 */
119 struct nexus_adapter {
120 volatile uint32_t na_flags; /* NAF_* flags */
121 nexus_adapter_type_t na_type; /* nexus type */
122 const nexus_meta_type_t na_md_type; /* metadata type */
123 const nexus_meta_subtype_t na_md_subtype; /* metadata subtype */
124
125 nexus_port_t na_nx_port;
126
127 /*
128 * Number of user-space descriptors using this interface,
129 * which is equal to the number of channel schema objects
130 * in the mapped region.
131 */
132 uint32_t na_channels;
133
134 /* number of adapter transmit and receive rings */
135 uint32_t na_num_rx_rings;
136 uint32_t na_num_tx_rings;
137
138 /* number of ring pairs used by packet allocator */
139 uint32_t na_num_allocator_ring_pairs;
140
141 /* number of event rings */
142 uint32_t na_num_event_rings;
143
144 uint64_t na_work_ts; /* when we last worked on it */
145
146 /*
147 * na_{tx,rx,alloc,free,event}_rings are private but allocated
148 * as a contiguous chunk of memory.
149 */
150 struct __kern_channel_ring *na_tx_rings; /* array of TX rings. */
151 struct __kern_channel_ring *na_rx_rings; /* array of RX rings. */
152
153 /*
154 * na_nx refers to the nexus instance associated with this
155 * nexus adapter; in cases such as the virtual port adapter
156 * of a flow switch nexus used for user pipe, this will
157 * indicate the latter. The na_nxdom_prov will point to
158 * the actual nexus domain associated with the adapter.
159 */
160 struct kern_nexus *na_nx;
161
162 /*
163 * Standard refcount to control the lifetime of the adapter
164 * (it should be equal to the lifetime of the corresponding ifp)
165 */
166 volatile uint32_t na_refcount;
167
168 int na_si_users[NR_ALL]; /* # of users per global wait queue */
169 struct ch_selinfo na_si[NR_ALL]; /* global wait queues */
170
171 /*
172 * Memory arena.
173 */
174 struct skmem_arena *na_arena;
175
176 /*
177 * Number of descriptor in each queue.
178 */
179 uint32_t na_num_tx_slots;
180 uint32_t na_num_rx_slots;
181 uint32_t na_num_allocator_slots;
182 uint32_t na_num_event_slots;
183
184 /*
185 * Combined slot count of all rings.
186 * Used for allocating slot_ctx and scratch memory.
187 */
188 uint32_t na_total_slots;
189
190 /*
191 * Flow advisory (if applicable).
192 */
193 const uint32_t na_flowadv_max; /* max # of flow advisory entries */
194
195 /*
196 * Shareable statistics (if applicable).
197 */
198 const nexus_stats_type_t na_stats_type; /* stats type */
199
200 /*
201 * Array of packet allocator and event rings
202 */
203 struct __kern_channel_ring *na_alloc_rings;
204 struct __kern_channel_ring *na_free_rings;
205 struct __kern_channel_ring *na_event_rings;
206
207 uint64_t na_ch_mit_ival; /* mitigation interval */
208
209 /*
210 * The actual nexus domain associated with the adapter.
211 */
212 struct kern_nexus_domain_provider *na_nxdom_prov;
213
214 /*
215 * Array of slot contexts. This covers enough space to hold
216 * slot contexts of slot_ctx size for all of the TX and RX rings,
217 * It is optional and is requested at na_krings_create() time.
218 */
219 struct slot_ctx *na_slot_ctxs;
220
221 /*
222 * Array of packet handlers, enough for all slots in the
223 * TX and RX rings of this adapter. It is automatically
224 * created at na_krings_create() time.
225 */
226 kern_packet_t *na_scratch;
227
228 struct __kern_channel_ring *na_tail; /* pointer past the last ring */
229
230 #if CONFIG_NEXUS_FLOWSWITCH || CONFIG_NEXUS_NETIF
231 /*
232 * Additional information attached to this adapter by other
233 * Skywalk subsystems; currently used by flow switch and netif.
234 */
235 void *na_private;
236
237 /*
238 * References to the ifnet and device routines, used by the netif
239 * nexus adapter functions. A non-NULL na_ifp indicates an io ref
240 * count to the ifnet that needs to be released at adapter detach
241 * time (at which point it will be nullifed).
242 */
243 struct ifnet *na_ifp;
244 /*
245 * lookup table to retrieve the ring corresponding to a service
246 * class. we store the ring index in na_(tx/rx)_rings array.
247 */
248 uint8_t na_kring_svc_lut[KPKT_SC_MAX_CLASSES];
249 #endif /* CONFIG_NEXUS_FLOWSWITCH || CONFIG_NEXUS_NETIF */
250
251 #if CONFIG_NEXUS_USER_PIPE
252 uint32_t na_next_pipe; /* next free slot in the array */
253 uint32_t na_max_pipes; /* size of the array */
254 /* array of pipes that have this adapter as a parent */
255 struct nexus_upipe_adapter **na_pipes;
256 #endif /* CONFIG_NEXUS_USER_PIPE */
257
258 char na_name[NEXUS_ADAPTER_NAMELEN]; /* diagnostics */
259 uuid_t na_uuid;
260
261 /*
262 * na_activate() is called to activate, defunct or deactivate a nexus
263 * adapter. This is invoked by na_bind_channel(), the first time a
264 * channel is opened to the adapter; by na_defunct() when an open
265 * channel gets defunct; as well as by na_unbind_channel() when the
266 * last channel instance opened to the adapter is closed.
267 */
268 int (*na_activate)(struct nexus_adapter *, na_activate_mode_t);
269 /*
270 * na_special() is an optional callback implemented by nexus types
271 * that support kernel channel (special mode). This allows the nexus
272 * to override the logic surrounding na_{bind,unbind}_channel() calls.
273 */
274 int (*na_special)(struct nexus_adapter *, struct kern_channel *,
275 struct chreq *, nxspec_cmd_t);
276 /*
277 * na_txsync() pushes packets to the underlying device;
278 * na_rxsync() collects packets from the underlying device.
279 */
280 int (*na_txsync)(struct __kern_channel_ring *kring, struct proc *,
281 uint32_t flags);
282 int (*na_rxsync)(struct __kern_channel_ring *kring, struct proc *,
283 uint32_t flags);
284 #define NA_SYNCF_MONITOR 0x1
285 #define NA_SYNCF_FORCE_READ 0x2
286 #define NA_SYNCF_FORCE_RECLAIM 0x4
287 #define NA_SYNCF_NETIF 0x8 /* netif normal sync */
288 #define NA_SYNCF_NETIF_ASYNC 0x10 /* asynchronous doorbell */
289 #define NA_SYNCF_NETIF_DOORBELL 0x20 /* doorbell request */
290 #define NA_SYNCF_NETIF_IFSTART 0x40 /* in if_start context */
291 #define NA_SYNCF_FORCE_UPP_SYNC 0x80 /* force upp sync alloc/free */
292 #define NA_SYNCF_UPP_PURGE 0x100 /* purge upp alloc pool */
293 #define NA_SYNCF_SYNC_ONLY 0x200 /* sync only, no doorbell */
294
295 /*
296 * na_notify() is used to act ater data have become available,
297 * or the state of the ring has changed. Depending on the nexus
298 * type, this may involve triggering an event and/or performing
299 * additional work such as calling na_txsync().
300 */
301 int (*na_notify)(struct __kern_channel_ring *kring, struct proc *,
302 uint32_t flags);
303 #define NA_NOTEF_MONITOR 0x1
304 #define NA_NOTEF_IN_KEVENT 0x2
305 #define NA_NOTEF_CAN_SLEEP 0x4 /* OK to block in kr_enter() */
306 #define NA_NOTEF_NETIF 0x8 /* same as NA_SYNCF_NETIF */
307 #define NA_NOTEF_PUSH 0x100 /* need immediate attention */
308
309 /*
310 * na_channel_event_notify() is used to send events on the user channel.
311 */
312 int (*na_channel_event_notify)(struct nexus_adapter *,
313 struct __kern_channel_event *, uint16_t);
314 /*
315 * na_config() is an optional callback for returning nexus-specific
316 * configuration information. This is implemented by nexus types
317 * that handle dynamically changing configs.
318 */
319 int (*na_config)(struct nexus_adapter *,
320 uint32_t *txr, uint32_t *txd, uint32_t *rxr, uint32_t *rxd);
321 /*
322 * na_krings_create() creates and initializes the __kern_channel_ring
323 * arrays, as well as initializing the callback routines within;
324 * na_krings_delete() cleans up and destroys the kernel rings.
325 */
326 int (*na_krings_create)(struct nexus_adapter *, struct kern_channel *);
327 void (*na_krings_delete)(struct nexus_adapter *, struct kern_channel *,
328 boolean_t);
329 /*
330 * na_dtor() is the destructor callback that is invoked when the
331 * last reference to the nexus adapter has been released.
332 */
333 void (*na_dtor)(struct nexus_adapter *);
334 /*
335 * na_free() is the free callback that gets invoked after the
336 * adapter has been destroyed.
337 */
338 void (*na_free)(struct nexus_adapter *);
339
340 /*
341 * packet-chain-based callbacks for passing packets up the stack.
342 * The inject variant is used by filters for rejecting packets
343 * into the rx path from user space.
344 */
345 void (*na_rx)(struct nexus_adapter *,
346 struct __kern_packet *, struct nexus_pkt_stats *);
347 };
348
349 /* valid values for na_flags */
350 #define NAF_ACTIVE 0x1 /* skywalk is active */
351 #define NAF_HOST_ONLY 0x2 /* host adapter (no device rings) */
352 #define NAF_SPEC_INIT 0x4 /* na_special() initialized */
353 #define NAF_NATIVE 0x8 /* skywalk native netif adapter */
354 #define NAF_MEM_NO_INIT 0x10 /* na_kr_setup() skipped */
355 #define NAF_SLOT_CONTEXT 0x20 /* na_slot_ctxs is valid */
356 #define NAF_USER_PKT_POOL 0x40 /* na supports user packet pool */
357 #define NAF_TX_MITIGATION 0x80 /* na supports TX event mitigation */
358 #define NAF_RX_MITIGATION 0x100 /* na supports RX event mitigation */
359 #define NAF_DEFUNCT 0x200 /* no longer in service */
360 #define NAF_MEM_LOANED 0x400 /* arena owned by another adapter */
361 #define NAF_REJECT 0x800 /* not accepting channel activities */
362 #define NAF_EVENT_RING 0x1000 /* NA is providing event ring */
363 #define NAF_CHANNEL_EVENT_ATTACHED 0x2000 /* kevent registered for ch events */
364 #define NAF_VIRTUAL_DEVICE 0x8000 /* netif adapter for virtual device */
365 #define NAF_MODE_FSW 0x10000 /* NA is owned by fsw */
366 #define NAF_MODE_LLW 0x20000 /* NA is owned by llw */
367 #define NAF_LOW_LATENCY 0x40000 /* Low latency NA */
368 #define NAF_DRAINING 0x80000 /* NA is being drained */
369 /*
370 * defunct allowed flag.
371 * Currently used only by the parent nexus adapter of user-pipe nexus
372 * to indicate that defuncting is allowed on the channels.
373 */
374 #define NAF_DEFUNCT_OK 0x100000
375 #define NAF_KERNEL_ONLY (1U << 31) /* used internally, not usable by userland */
376
377 #define NAF_BITS \
378 "\020\01ACTIVE\02HOST_ONLY\03SPEC_INIT\04NATIVE" \
379 "\05MEM_NO_INIT\06SLOT_CONTEXT\07USER_PKT_POOL" \
380 "\010TX_MITIGATION\011RX_MITIGATION\012DEFUNCT\013MEM_LOANED" \
381 "\014REJECT\015EVENT_RING\016EVENT_ATTACH" \
382 "\020VIRTUAL\021MODE_FSW\022MODE_LLW\023LOW_LATENCY\024DRAINING" \
383 "\025DEFUNCT_OK\040KERNEL_ONLY"
384
385 #define NA_FREE(na) do { \
386 (na)->na_free(na); \
387 } while (0)
388
389 /*
390 * NA returns a pointer to the struct nexus_adapter from the ifp's netif nexus.
391 */
392 #define NA(_ifp) ((_ifp)->if_na)
393
394 __attribute__((always_inline))
395 static inline uint32_t
na_get_nslots(const struct nexus_adapter * na,enum txrx t)396 na_get_nslots(const struct nexus_adapter *na, enum txrx t)
397 {
398 switch (t) {
399 case NR_TX:
400 return na->na_num_tx_slots;
401 case NR_RX:
402 return na->na_num_rx_slots;
403 case NR_A:
404 case NR_F:
405 return na->na_num_allocator_slots;
406 case NR_EV:
407 return na->na_num_event_slots;
408 default:
409 VERIFY(0);
410 /* NOTREACHED */
411 __builtin_unreachable();
412 }
413 }
414
415 __attribute__((always_inline))
416 static inline void
na_set_nslots(struct nexus_adapter * na,enum txrx t,uint32_t v)417 na_set_nslots(struct nexus_adapter *na, enum txrx t, uint32_t v)
418 {
419 switch (t) {
420 case NR_TX:
421 na->na_num_tx_slots = v;
422 break;
423 case NR_RX:
424 na->na_num_rx_slots = v;
425 break;
426 case NR_A:
427 case NR_F:
428 na->na_num_allocator_slots = v;
429 break;
430 case NR_EV:
431 na->na_num_event_slots = v;
432 break;
433 default:
434 VERIFY(0);
435 /* NOTREACHED */
436 __builtin_unreachable();
437 }
438 }
439
440 __attribute__((always_inline))
441 static inline uint32_t
na_get_nrings(const struct nexus_adapter * na,enum txrx t)442 na_get_nrings(const struct nexus_adapter *na, enum txrx t)
443 {
444 switch (t) {
445 case NR_TX:
446 return na->na_num_tx_rings;
447 case NR_RX:
448 return na->na_num_rx_rings;
449 case NR_A:
450 case NR_F:
451 return na->na_num_allocator_ring_pairs;
452 case NR_EV:
453 return na->na_num_event_rings;
454 default:
455 VERIFY(0);
456 /* NOTREACHED */
457 __builtin_unreachable();
458 }
459 }
460
461 __attribute__((always_inline))
462 static inline void
na_set_nrings(struct nexus_adapter * na,enum txrx t,uint32_t v)463 na_set_nrings(struct nexus_adapter *na, enum txrx t, uint32_t v)
464 {
465 switch (t) {
466 case NR_TX:
467 na->na_num_tx_rings = v;
468 break;
469 case NR_RX:
470 na->na_num_rx_rings = v;
471 break;
472 case NR_A:
473 case NR_F:
474 na->na_num_allocator_ring_pairs = v;
475 break;
476 case NR_EV:
477 na->na_num_event_rings = v;
478 break;
479 default:
480 VERIFY(0);
481 /* NOTREACHED */
482 __builtin_unreachable();
483 }
484 }
485
486 __attribute__((always_inline))
487 static inline struct __kern_channel_ring *
NAKR(struct nexus_adapter * na,enum txrx t)488 NAKR(struct nexus_adapter *na, enum txrx t)
489 {
490 switch (t) {
491 case NR_TX:
492 return na->na_tx_rings;
493 case NR_RX:
494 return na->na_rx_rings;
495 case NR_A:
496 return na->na_alloc_rings;
497 case NR_F:
498 return na->na_free_rings;
499 case NR_EV:
500 return na->na_event_rings;
501 default:
502 VERIFY(0);
503 /* NOTREACHED */
504 __builtin_unreachable();
505 }
506 }
507
508 /*
509 * If the adapter is owned by the kernel, neither another flow switch nor user
510 * can use it; if the adapter is owned by a user, only users can share it.
511 * Evaluation must be done under SK_LOCK().
512 */
513 #define NA_KERNEL_ONLY(_na) (((_na)->na_flags & NAF_KERNEL_ONLY) != 0)
514 #define NA_OWNED_BY_ANY(_na) \
515 (NA_KERNEL_ONLY(_na) || ((_na)->na_channels > 0))
516 #define NA_OWNED_BY_FSW(_na) \
517 (((_na)->na_flags & NAF_MODE_FSW) != 0)
518 #define NA_OWNED_BY_LLW(_na) \
519 (((_na)->na_flags & NAF_MODE_LLW) != 0)
520
521 /*
522 * Whether the adapter has been activated via na_activate() call.
523 */
524 #define NA_IS_ACTIVE(_na) (((_na)->na_flags & NAF_ACTIVE) != 0)
525 #define NA_IS_DEFUNCT(_na) (((_na)->na_flags & NAF_DEFUNCT) != 0)
526 #define NA_CHANNEL_EVENT_ATTACHED(_na) \
527 (((_na)->na_flags & NAF_CHANNEL_EVENT_ATTACHED) != 0)
528 /*
529 * Whether channel activities are rejected by the adapter. This takes the
530 * nexus adapter argument separately, as ch->ch_na may not be set yet.
531 */
532 __attribute__((always_inline))
533 static inline boolean_t
na_reject_channel(struct kern_channel * ch,struct nexus_adapter * na)534 na_reject_channel(struct kern_channel *ch, struct nexus_adapter *na)
535 {
536 boolean_t reject;
537
538 ASSERT(ch->ch_na == NULL || ch->ch_na == na);
539
540 if ((na->na_flags & NAF_REJECT) || NX_REJECT_ACT(na->na_nx)) {
541 /* set trapdoor NAF_REJECT flag */
542 if (!(na->na_flags & NAF_REJECT)) {
543 SK_ERR("%s(%d) marked as non-permissive",
544 ch->ch_name, ch->ch_pid);
545 atomic_bitset_32(&na->na_flags, NAF_REJECT);
546 ch_deactivate(ch);
547 }
548 reject = TRUE;
549 } else {
550 reject = FALSE;
551 }
552
553 return reject;
554 }
555
556 #if SK_LOG
557 __attribute__((always_inline))
558 static inline const char *
na_activate_mode2str(na_activate_mode_t m)559 na_activate_mode2str(na_activate_mode_t m)
560 {
561 switch (m) {
562 case NA_ACTIVATE_MODE_ON:
563 return "on";
564 case NA_ACTIVATE_MODE_DEFUNCT:
565 return "defunct";
566 case NA_ACTIVATE_MODE_OFF:
567 return "off";
568 default:
569 VERIFY(0);
570 /* NOTREACHED */
571 __builtin_unreachable();
572 }
573 }
574 #endif /* SK_LOG */
575
576 __BEGIN_DECLS
577 extern void na_init(void);
578 extern void na_fini(void);
579
580 extern int na_bind_channel(struct nexus_adapter *na, struct kern_channel *ch,
581 struct chreq *);
582 extern void na_unbind_channel(struct kern_channel *ch);
583
584 /*
585 * Common routine for all functions that create a nexus adapter. It performs
586 * two main tasks:
587 * - if the na points to an ifp, mark the ifp as Skywalk capable
588 * using na as its native adapter;
589 * - provide defaults for the setup callbacks and the memory allocator
590 */
591 extern void na_attach_common(struct nexus_adapter *,
592 struct kern_nexus *, struct kern_nexus_domain_provider *);
593 /*
594 * Update the ring parameters (number and size of tx and rx rings).
595 * It calls the nm_config callback, if available.
596 */
597 extern int na_update_config(struct nexus_adapter *na);
598
599 extern int na_rings_mem_setup(struct nexus_adapter *, boolean_t,
600 struct kern_channel *);
601 extern void na_rings_mem_teardown(struct nexus_adapter *,
602 struct kern_channel *, boolean_t);
603 extern void na_ch_rings_defunct(struct kern_channel *, struct proc *);
604
605 /* convenience wrappers for na_set_all_rings, used in drivers */
606 extern void na_disable_all_rings(struct nexus_adapter *);
607 extern void na_enable_all_rings(struct nexus_adapter *);
608 extern void na_lock_all_rings(struct nexus_adapter *);
609 extern void na_unlock_all_rings(struct nexus_adapter *);
610 extern int na_interp_ringid(struct nexus_adapter *, ring_id_t, ring_set_t,
611 uint32_t[NR_TXRX], uint32_t[NR_TXRX]);
612 extern struct kern_pbufpool *na_kr_get_pp(struct nexus_adapter *, enum txrx);
613
614 extern int na_find(struct kern_channel *, struct kern_nexus *,
615 struct chreq *, struct kern_channel *, struct nxbind *,
616 struct proc *, struct nexus_adapter **, boolean_t);
617 extern void na_retain_locked(struct nexus_adapter *na);
618 extern int na_release_locked(struct nexus_adapter *na);
619
620 extern int na_connect(struct kern_nexus *, struct kern_channel *,
621 struct chreq *, struct kern_channel *, struct nxbind *, struct proc *);
622 extern void na_disconnect(struct kern_nexus *, struct kern_channel *);
623 extern void na_defunct(struct kern_nexus *, struct kern_channel *,
624 struct nexus_adapter *, boolean_t);
625 extern int na_connect_spec(struct kern_nexus *, struct kern_channel *,
626 struct chreq *, struct proc *);
627 extern void na_disconnect_spec(struct kern_nexus *, struct kern_channel *);
628 extern void na_start_spec(struct kern_nexus *, struct kern_channel *);
629 extern void na_stop_spec(struct kern_nexus *, struct kern_channel *);
630
631 extern int na_pseudo_create(struct kern_nexus *, struct chreq *,
632 struct nexus_adapter **);
633 extern void na_kr_drop(struct nexus_adapter *, boolean_t);
634 extern void na_flowadv_entry_alloc(const struct nexus_adapter *, uuid_t,
635 const flowadv_idx_t, const uint32_t);
636 extern void na_flowadv_entry_free(const struct nexus_adapter *, uuid_t,
637 const flowadv_idx_t, const uint32_t);
638 extern bool na_flowadv_set(const struct nexus_adapter *,
639 const flowadv_idx_t, const flowadv_token_t);
640 extern boolean_t na_flowadv_clear(const struct kern_channel *,
641 const flowadv_idx_t, const flowadv_token_t);
642 extern void na_flowadv_event(struct __kern_channel_ring *);
643 extern void na_post_event(struct __kern_channel_ring *, boolean_t, boolean_t,
644 boolean_t, uint32_t);
645
646 extern void na_drain(struct nexus_adapter *, boolean_t);
647
648 __END_DECLS
649 #endif /* BSD_KERNEL_PRIVATE */
650 #endif /* _SKYWALK_NEXUS_ADAPTER_H_ */
651