1/* $NetBSD: if_agrvar_impl.h,v 1.10 2010/05/26 23:46:44 dyoung 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/mutex.h>
37#include <sys/queue.h>
38
39struct agr_port;
40struct agr_softc;
41
42struct 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
60struct 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
100struct agr_ifreq {
101 char ifr_name[IFNAMSIZ];
102 struct sockaddr_storage ifr_ss;
103};
104
105struct agr_softc {
106 kmutex_t sc_entry_mtx;
107 kmutex_t sc_lock;
108 kcondvar_t sc_ports_cv;
109 kcondvar_t sc_insc_cv;
110 volatile int sc_noentry;
111 volatile int sc_insc;
112 volatile bool sc_wrports;
113 volatile int sc_rdports;
114 volatile int sc_paused;
115 struct callout sc_callout;
116 int sc_nports;
117 TAILQ_HEAD(, agr_port) sc_ports;
118 const struct agr_iftype_ops *sc_iftop;
119 uint32_t sc_rr_counter; /* distributor algorithm specific */
120 void *sc_iftprivate;
121 int sc_nvlans; /* number of vlans attached */
122 struct ifnet sc_if; /* should be the last. see agr_alloc_softc(). */
123};
124
125#define AGR_SC_FROM_PORT(port) \
126 ((struct agr_softc *)(port)->port_agrifp->if_softc)
127
128#define AGR_LOCK(sc) agr_lock(sc)
129#define AGR_UNLOCK(sc) agr_unlock(sc)
130#define AGR_ASSERT_LOCKED(sc) KASSERT(mutex_owned(&(sc)->sc_lock))
131
132void agr_lock(struct agr_softc *);
133void agr_unlock(struct agr_softc *);
134
135int agrport_ioctl(struct agr_port *, u_long, void *);
136
137struct agr_softc *agr_alloc_softc(void);
138void agr_free_softc(struct agr_softc *);
139
140int agr_xmit_frame(struct ifnet *, struct mbuf *); /* XXX */
141
142#define AGR_ROUNDROBIN(sc) (((sc)->sc_if.if_flags & IFF_LINK0) != 0)
143#define AGR_STATIC(sc) (((sc)->sc_if.if_flags & IFF_LINK1) != 0)
144
145void agrtimer_init(struct agr_softc *);
146void agrtimer_destroy(struct agr_softc *);
147void agrtimer_start(struct agr_softc *);
148void agrtimer_stop(struct agr_softc *);
149
150void agrport_monitor(struct agr_port *);
151
152#endif /* !_NET_AGR_IF_AGRVAR_IMPL_H_ */
153