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