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