1 1.12 andvar /* $NetBSD: if_agrvar_impl.h,v 1.12 2023/03/26 19:10:33 andvar Exp $ */ 2 1.1 yamt 3 1.1 yamt /*- 4 1.1 yamt * Copyright (c)2005 YAMAMOTO Takashi, 5 1.1 yamt * All rights reserved. 6 1.1 yamt * 7 1.1 yamt * Redistribution and use in source and binary forms, with or without 8 1.1 yamt * modification, are permitted provided that the following conditions 9 1.1 yamt * are met: 10 1.1 yamt * 1. Redistributions of source code must retain the above copyright 11 1.1 yamt * notice, this list of conditions and the following disclaimer. 12 1.1 yamt * 2. Redistributions in binary form must reproduce the above copyright 13 1.1 yamt * notice, this list of conditions and the following disclaimer in the 14 1.1 yamt * documentation and/or other materials provided with the distribution. 15 1.1 yamt * 16 1.1 yamt * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 17 1.1 yamt * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 1.1 yamt * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 1.1 yamt * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 20 1.1 yamt * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21 1.1 yamt * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 22 1.1 yamt * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23 1.1 yamt * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24 1.1 yamt * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25 1.1 yamt * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26 1.1 yamt * SUCH DAMAGE. 27 1.1 yamt */ 28 1.1 yamt 29 1.3 yamt #ifndef _NET_AGR_IF_AGRVAR_IMPL_H_ 30 1.3 yamt #define _NET_AGR_IF_AGRVAR_IMPL_H_ 31 1.1 yamt 32 1.1 yamt /* 33 1.12 andvar * implementation details for agr(4) driver. (contrast to if_agrvar.h) 34 1.1 yamt */ 35 1.1 yamt 36 1.7 yamt #include <sys/mutex.h> 37 1.4 yamt #include <sys/queue.h> 38 1.11 maya #include <sys/workqueue.h> 39 1.4 yamt 40 1.1 yamt struct agr_port; 41 1.1 yamt struct agr_softc; 42 1.1 yamt 43 1.1 yamt struct agr_port { 44 1.1 yamt struct ifnet *port_agrifp; 45 1.1 yamt struct ifnet *port_ifp; 46 1.1 yamt TAILQ_ENTRY(agr_port) port_q; 47 1.6 christos int (*port_ioctl)(struct ifnet *, u_long, void *); 48 1.1 yamt void *port_iftprivate; 49 1.1 yamt int port_flags; 50 1.1 yamt u_int port_media; 51 1.1 yamt char port_origlladdr[0]; 52 1.1 yamt }; 53 1.1 yamt #define AGRPORT_COLLECTING 0x00000001 54 1.1 yamt #define AGRPORT_DISTRIBUTING 0x00000002 55 1.1 yamt #define AGRPORT_PROMISC 0x00000004 56 1.1 yamt #define AGRPORT_LADDRCHANGED 0x00000008 57 1.1 yamt #define AGRPORT_ATTACHED 0x00000010 58 1.1 yamt #define AGRPORT_LARVAL 0x00000020 59 1.1 yamt #define AGRPORT_DETACHING 0x00000040 60 1.1 yamt 61 1.1 yamt struct agr_iftype_ops { 62 1.1 yamt 63 1.1 yamt void (*iftop_tick)(struct agr_softc *); 64 1.1 yamt void (*iftop_porttick)(struct agr_softc *, struct agr_port *); 65 1.1 yamt void (*iftop_portstate)(struct agr_port *); 66 1.1 yamt 67 1.1 yamt /* 68 1.1 yamt * iftop_ctor: 69 1.1 yamt * - inherit setting (eg. L1 address) from the first port. 70 1.1 yamt * - initialize if_output, if_input, if_dlt, etc. 71 1.1 yamt * (in the case of IFT_ETHER, ether_ifattach. 72 1.1 yamt */ 73 1.1 yamt 74 1.1 yamt int (*iftop_ctor)(struct agr_softc *, struct ifnet *); 75 1.1 yamt 76 1.1 yamt void (*iftop_dtor)(struct agr_softc *); 77 1.1 yamt 78 1.1 yamt /* 79 1.1 yamt * iftop_portinit: 80 1.1 yamt * propagate setting to a newly added port. 81 1.1 yamt */ 82 1.1 yamt 83 1.1 yamt int (*iftop_portinit)(struct agr_softc *, struct agr_port *); 84 1.1 yamt 85 1.1 yamt /* 86 1.1 yamt * iftop_portfini: 87 1.1 yamt * restore setting of a port being removed. 88 1.1 yamt */ 89 1.1 yamt int (*iftop_portfini)(struct agr_softc *, struct agr_port *); 90 1.1 yamt 91 1.1 yamt struct agr_port *(*iftop_select_tx_port)(struct agr_softc *, 92 1.1 yamt struct mbuf *); 93 1.1 yamt uint32_t (*iftop_hashmbuf)(struct agr_softc *, struct mbuf *); 94 1.1 yamt 95 1.1 yamt int (*iftop_configmulti_port)(struct agr_softc *, struct agr_port *, 96 1.5 thorpej bool); 97 1.1 yamt int (*iftop_configmulti_ifreq)(struct agr_softc *, struct ifreq *, 98 1.5 thorpej bool); 99 1.1 yamt }; 100 1.1 yamt 101 1.1 yamt struct agr_ifreq { 102 1.1 yamt char ifr_name[IFNAMSIZ]; 103 1.1 yamt struct sockaddr_storage ifr_ss; 104 1.1 yamt }; 105 1.1 yamt 106 1.1 yamt struct agr_softc { 107 1.9 dyoung kmutex_t sc_entry_mtx; 108 1.7 yamt kmutex_t sc_lock; 109 1.9 dyoung kcondvar_t sc_ports_cv; 110 1.9 dyoung kcondvar_t sc_insc_cv; 111 1.10 dyoung volatile int sc_noentry; 112 1.10 dyoung volatile int sc_insc; 113 1.10 dyoung volatile bool sc_wrports; 114 1.10 dyoung volatile int sc_rdports; 115 1.10 dyoung volatile int sc_paused; 116 1.11 maya struct workqueue *sc_wq; 117 1.11 maya struct work sc_wk; 118 1.1 yamt struct callout sc_callout; 119 1.1 yamt int sc_nports; 120 1.1 yamt TAILQ_HEAD(, agr_port) sc_ports; 121 1.1 yamt const struct agr_iftype_ops *sc_iftop; 122 1.1 yamt uint32_t sc_rr_counter; /* distributor algorithm specific */ 123 1.1 yamt void *sc_iftprivate; 124 1.8 darran int sc_nvlans; /* number of vlans attached */ 125 1.1 yamt struct ifnet sc_if; /* should be the last. see agr_alloc_softc(). */ 126 1.1 yamt }; 127 1.1 yamt 128 1.1 yamt #define AGR_SC_FROM_PORT(port) \ 129 1.1 yamt ((struct agr_softc *)(port)->port_agrifp->if_softc) 130 1.1 yamt 131 1.1 yamt #define AGR_LOCK(sc) agr_lock(sc) 132 1.7 yamt #define AGR_UNLOCK(sc) agr_unlock(sc) 133 1.7 yamt #define AGR_ASSERT_LOCKED(sc) KASSERT(mutex_owned(&(sc)->sc_lock)) 134 1.1 yamt 135 1.7 yamt void agr_lock(struct agr_softc *); 136 1.7 yamt void agr_unlock(struct agr_softc *); 137 1.1 yamt 138 1.6 christos int agrport_ioctl(struct agr_port *, u_long, void *); 139 1.1 yamt 140 1.1 yamt struct agr_softc *agr_alloc_softc(void); 141 1.1 yamt void agr_free_softc(struct agr_softc *); 142 1.1 yamt 143 1.1 yamt int agr_xmit_frame(struct ifnet *, struct mbuf *); /* XXX */ 144 1.1 yamt 145 1.1 yamt #define AGR_ROUNDROBIN(sc) (((sc)->sc_if.if_flags & IFF_LINK0) != 0) 146 1.8 darran #define AGR_STATIC(sc) (((sc)->sc_if.if_flags & IFF_LINK1) != 0) 147 1.1 yamt 148 1.11 maya int agrtimer_init(struct agr_softc *); 149 1.9 dyoung void agrtimer_destroy(struct agr_softc *); 150 1.1 yamt void agrtimer_start(struct agr_softc *); 151 1.1 yamt void agrtimer_stop(struct agr_softc *); 152 1.1 yamt 153 1.1 yamt void agrport_monitor(struct agr_port *); 154 1.1 yamt 155 1.3 yamt #endif /* !_NET_AGR_IF_AGRVAR_IMPL_H_ */ 156