Home | History | Annotate | Line # | Download | only in agr
if_agrvar_impl.h revision 1.6
      1 /*	$NetBSD: if_agrvar_impl.h,v 1.6 2007/03/04 06:03:18 christos 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  * implementaion details for agr(4) driver.  (contrast to if_agrvar.h)
     34  */
     35 
     36 #include <sys/lock.h>
     37 #include <sys/queue.h>
     38 
     39 struct agr_port;
     40 struct agr_softc;
     41 
     42 struct agr_port {
     43 	struct ifnet *port_agrifp;
     44 	struct ifnet *port_ifp;
     45 	TAILQ_ENTRY(agr_port) port_q;
     46 	int (*port_ioctl)(struct ifnet *, u_long, void *);
     47 	void *port_iftprivate;
     48 	int port_flags;
     49 	u_int port_media;
     50 	char port_origlladdr[0];
     51 };
     52 #define	AGRPORT_COLLECTING	0x00000001
     53 #define	AGRPORT_DISTRIBUTING	0x00000002
     54 #define	AGRPORT_PROMISC		0x00000004
     55 #define	AGRPORT_LADDRCHANGED	0x00000008
     56 #define	AGRPORT_ATTACHED	0x00000010
     57 #define	AGRPORT_LARVAL		0x00000020
     58 #define	AGRPORT_DETACHING	0x00000040
     59 
     60 struct agr_iftype_ops {
     61 
     62 	void (*iftop_tick)(struct agr_softc *);
     63 	void (*iftop_porttick)(struct agr_softc *, struct agr_port *);
     64 	void (*iftop_portstate)(struct agr_port *);
     65 
     66 	/*
     67 	 * iftop_ctor:
     68 	 * - inherit setting (eg. L1 address) from the first port.
     69 	 * - initialize if_output, if_input, if_dlt, etc.
     70 	 *   (in the case of IFT_ETHER, ether_ifattach.
     71 	 */
     72 
     73 	int (*iftop_ctor)(struct agr_softc *, struct ifnet *);
     74 
     75 	void (*iftop_dtor)(struct agr_softc *);
     76 
     77 	/*
     78 	 * iftop_portinit:
     79 	 * propagate setting to a newly added port.
     80 	 */
     81 
     82 	int (*iftop_portinit)(struct agr_softc *, struct agr_port *);
     83 
     84 	/*
     85 	 * iftop_portfini:
     86 	 * restore setting of a port being removed.
     87 	 */
     88 	int (*iftop_portfini)(struct agr_softc *, struct agr_port *);
     89 
     90 	struct agr_port *(*iftop_select_tx_port)(struct agr_softc *,
     91 	    struct mbuf *);
     92 	uint32_t (*iftop_hashmbuf)(struct agr_softc *, struct mbuf *);
     93 
     94 	int (*iftop_configmulti_port)(struct agr_softc *, struct agr_port *,
     95 	    bool);
     96 	int (*iftop_configmulti_ifreq)(struct agr_softc *, struct ifreq *,
     97 	    bool);
     98 };
     99 
    100 struct agr_ifreq {
    101 	char ifr_name[IFNAMSIZ];
    102 	struct sockaddr_storage ifr_ss;
    103 };
    104 
    105 struct agr_softc {
    106 	struct lock sc_ioctl_lock;
    107 	struct simplelock sc_lock;
    108 	struct callout sc_callout;
    109 	int sc_nports;
    110 	TAILQ_HEAD(, agr_port) sc_ports;
    111 	const struct agr_iftype_ops *sc_iftop;
    112 	uint32_t sc_rr_counter;	/* distributor algorithm specific */
    113 	void *sc_iftprivate;
    114 	struct ifnet sc_if; /* should be the last. see agr_alloc_softc(). */
    115 };
    116 
    117 #define	AGR_SC_FROM_PORT(port) \
    118 	((struct agr_softc *)(port)->port_agrifp->if_softc)
    119 
    120 #define	AGR_LOCK(sc)		agr_lock(sc)
    121 #define	AGR_UNLOCK(sc, s)	agr_unlock((sc), (s))
    122 #define	AGR_ASSERT_LOCKED(sc)	LOCK_ASSERT(simple_lock_held(&(sc)->sc_lock))
    123 
    124 int agr_lock(struct agr_softc *);
    125 void agr_unlock(struct agr_softc *, int);
    126 
    127 void agr_ioctl_lock(struct agr_softc *);
    128 void agr_ioctl_unlock(struct agr_softc *);
    129 
    130 int agrport_ioctl(struct agr_port *, u_long, void *);
    131 
    132 struct agr_softc *agr_alloc_softc(void);
    133 void agr_free_softc(struct agr_softc *);
    134 
    135 int agr_xmit_frame(struct ifnet *, struct mbuf *); /* XXX */
    136 
    137 #define	AGR_ROUNDROBIN(sc)	(((sc)->sc_if.if_flags & IFF_LINK0) != 0)
    138 
    139 void agrtimer_init(struct agr_softc *);
    140 void agrtimer_start(struct agr_softc *);
    141 void agrtimer_stop(struct agr_softc *);
    142 
    143 void agrport_monitor(struct agr_port *);
    144 
    145 #endif /* !_NET_AGR_IF_AGRVAR_IMPL_H_ */
    146