if_agrvar_impl.h revision 1.7 1 1.7 yamt /* $NetBSD: if_agrvar_impl.h,v 1.7 2007/05/20 07:57:04 yamt 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.7 yamt kmutex_t sc_ioctl_lock;
107 1.7 yamt kmutex_t sc_lock;
108 1.1 yamt struct callout sc_callout;
109 1.1 yamt int sc_nports;
110 1.1 yamt TAILQ_HEAD(, agr_port) sc_ports;
111 1.1 yamt const struct agr_iftype_ops *sc_iftop;
112 1.1 yamt uint32_t sc_rr_counter; /* distributor algorithm specific */
113 1.1 yamt void *sc_iftprivate;
114 1.1 yamt struct ifnet sc_if; /* should be the last. see agr_alloc_softc(). */
115 1.1 yamt };
116 1.1 yamt
117 1.1 yamt #define AGR_SC_FROM_PORT(port) \
118 1.1 yamt ((struct agr_softc *)(port)->port_agrifp->if_softc)
119 1.1 yamt
120 1.1 yamt #define AGR_LOCK(sc) agr_lock(sc)
121 1.7 yamt #define AGR_UNLOCK(sc) agr_unlock(sc)
122 1.7 yamt #define AGR_ASSERT_LOCKED(sc) KASSERT(mutex_owned(&(sc)->sc_lock))
123 1.1 yamt
124 1.7 yamt void agr_lock(struct agr_softc *);
125 1.7 yamt void agr_unlock(struct agr_softc *);
126 1.1 yamt
127 1.1 yamt void agr_ioctl_lock(struct agr_softc *);
128 1.1 yamt void agr_ioctl_unlock(struct agr_softc *);
129 1.1 yamt
130 1.6 christos int agrport_ioctl(struct agr_port *, u_long, void *);
131 1.1 yamt
132 1.1 yamt struct agr_softc *agr_alloc_softc(void);
133 1.1 yamt void agr_free_softc(struct agr_softc *);
134 1.1 yamt
135 1.1 yamt int agr_xmit_frame(struct ifnet *, struct mbuf *); /* XXX */
136 1.1 yamt
137 1.1 yamt #define AGR_ROUNDROBIN(sc) (((sc)->sc_if.if_flags & IFF_LINK0) != 0)
138 1.1 yamt
139 1.1 yamt void agrtimer_init(struct agr_softc *);
140 1.1 yamt void agrtimer_start(struct agr_softc *);
141 1.1 yamt void agrtimer_stop(struct agr_softc *);
142 1.1 yamt
143 1.1 yamt void agrport_monitor(struct agr_port *);
144 1.1 yamt
145 1.3 yamt #endif /* !_NET_AGR_IF_AGRVAR_IMPL_H_ */
146