1 /* $NetBSD: ieee8023ad_lacp_impl.h,v 1.5 2007/02/21 23:00:06 thorpej 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_IEEE8023AD_LACP_IMPL_H_ 30 #define _NET_AGR_IEEE8023AD_LACP_IMPL_H_ 31 32 /* 33 * IEEE802.3ad LACP 34 * 35 * implementation details. 36 */ 37 38 #include <sys/queue.h> 39 40 #define LACP_TIMER_CURRENT_WHILE 0 41 #define LACP_TIMER_PERIODIC 1 42 #define LACP_TIMER_WAIT_WHILE 2 43 #define LACP_NTIMER 3 44 45 #define LACP_TIMER_ARM(port, timer, val) \ 46 (port)->lp_timer[(timer)] = (val) 47 #define LACP_TIMER_DISARM(port, timer) \ 48 (port)->lp_timer[(timer)] = 0 49 #define LACP_TIMER_ISARMED(port, timer) \ 50 ((port)->lp_timer[(timer)] > 0) 51 52 struct lacp_aggregator { 53 TAILQ_ENTRY(lacp_aggregator) la_q; 54 int la_refcnt; /* number of ports which selected us */ 55 int la_nports; /* number of distributing ports */ 56 TAILQ_HEAD(, lacp_port) la_ports; /* distributing ports */ 57 struct lacp_peerinfo la_partner; 58 struct lacp_peerinfo la_actor; 59 int la_pending; /* number of ports which is waiting wait_while */ 60 }; 61 62 struct lacp_softc { 63 struct lacp_aggregator *lsc_active_aggregator; 64 TAILQ_HEAD(, lacp_aggregator) lsc_aggregators; 65 bool lsc_suppress_distributing; 66 struct callout lsc_transit_callout; 67 }; 68 69 #define LACP_TRANSIT_DELAY 1000 /* in msec */ 70 71 enum lacp_selected { 72 LACP_UNSELECTED, 73 LACP_STANDBY, /* not used in this implementation */ 74 LACP_SELECTED, 75 }; 76 77 enum lacp_mux_state { 78 LACP_MUX_DETACHED, 79 LACP_MUX_WAITING, 80 LACP_MUX_ATTACHED, 81 LACP_MUX_COLLECTING, 82 LACP_MUX_DISTRIBUTING, 83 }; 84 85 struct lacp_port { 86 TAILQ_ENTRY(lacp_port) lp_dist_q; 87 struct agr_port *lp_agrport; 88 struct lacp_peerinfo lp_partner; 89 struct lacp_peerinfo lp_actor; 90 #define lp_state lp_actor.lip_state 91 #define lp_key lp_actor.lip_key 92 int lp_last_lacpdu_sent; 93 enum lacp_mux_state lp_mux_state; 94 enum lacp_selected lp_selected; 95 int lp_flags; 96 u_int lp_media; /* XXX redundant */ 97 int lp_timer[LACP_NTIMER]; 98 99 struct lacp_aggregator *lp_aggregator; 100 }; 101 102 #define LACPPORT_NTT 1 /* need to transmit */ 103 104 #define LACP_SOFTC(sc) \ 105 (&IEEE8023AD_SOFTC(sc)->isc_lacpsc) 106 #define LACP_PORT(port) \ 107 (&IEEE8023AD_PORT(port)->iport_lacpport) 108 109 void lacp_run_timers(struct lacp_port *); 110 void lacp_portinit(struct agr_port *); 111 void lacp_portfini(struct agr_port *); 112 int lacp_compare_peerinfo(const struct lacp_peerinfo *, 113 const struct lacp_peerinfo *); 114 int lacp_compare_systemid(const struct lacp_systemid *, 115 const struct lacp_systemid *); 116 int lacp_compare_portid(const struct lacp_portid *, 117 const struct lacp_portid *); 118 119 void lacp_select(struct lacp_port *); 120 void lacp_unselect(struct lacp_port *); 121 122 void lacp_disable_collecting(struct lacp_port *); 123 void lacp_enable_collecting(struct lacp_port *); 124 void lacp_disable_distributing(struct lacp_port *); 125 void lacp_enable_distributing(struct lacp_port *); 126 127 int lacp_xmit_lacpdu(struct lacp_port *); 128 129 #endif /* !_NET_AGR_IEEE8023AD_LACP_IMPL_H_ */ 130