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