1 /* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License (the "License"). 6 * You may not use this file except in compliance with the License. 7 * 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9 * or http://www.opensolaris.org/os/licensing. 10 * See the License for the specific language governing permissions 11 * and limitations under the License. 12 * 13 * When distributing Covered Code, include this CDDL HEADER in each 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15 * If applicable, add the following below this CDDL HEADER, with the 16 * fields enclosed by brackets "[]" replaced with your own identifying 17 * information: Portions Copyright [yyyy] [name of copyright owner] 18 * 19 * CDDL HEADER END 20 */ 21 /* 22 * Copyright 2008 Sun Microsystems, Inc. All rights reserved. 23 * Use is subject to license terms. 24 */ 25 26 #ifndef _SYS_AGGR_IMPL_H 27 #define _SYS_AGGR_IMPL_H 28 29 #include <sys/types.h> 30 #include <sys/mac_ether.h> 31 #include <sys/mac_provider.h> 32 #include <sys/mac_client.h> 33 #include <sys/mac_client_priv.h> 34 #include <sys/aggr_lacp.h> 35 36 #ifdef __cplusplus 37 extern "C" { 38 #endif 39 40 #ifdef _KERNEL 41 42 #define AGGR_MINOR_CTL 1 /* control interface minor */ 43 44 /* flags for aggr_grp_modify() */ 45 #define AGGR_MODIFY_POLICY 0x01 46 #define AGGR_MODIFY_MAC 0x02 47 #define AGGR_MODIFY_LACP_MODE 0x04 48 #define AGGR_MODIFY_LACP_TIMER 0x08 49 50 /* 51 * Possible value of aggr_rseudo_rx_ring_t.arr_flags. Set when the ring entry 52 * in the pseudo RX group is used. 53 */ 54 #define MAC_PSEUDO_RING_INUSE 0x01 55 56 typedef struct aggr_unicst_addr_s { 57 uint8_t aua_addr[ETHERADDRL]; 58 struct aggr_unicst_addr_s *aua_next; 59 } aggr_unicst_addr_t; 60 61 typedef struct aggr_pseudo_rx_ring_s { 62 mac_ring_handle_t arr_rh; /* filled in by aggr_fill_ring() */ 63 struct aggr_port_s *arr_port; 64 mac_ring_handle_t arr_hw_rh; 65 uint_t arr_flags; 66 uint64_t arr_gen; 67 } aggr_pseudo_rx_ring_t; 68 69 typedef struct aggr_pseudo_rx_group_s { 70 struct aggr_grp_s *arg_grp; /* filled in by aggr_fill_group() */ 71 mac_group_handle_t arg_gh; /* filled in by aggr_fill_group() */ 72 aggr_unicst_addr_t *arg_macaddr; 73 aggr_pseudo_rx_ring_t arg_rings[MAX_RINGS_PER_GROUP]; 74 uint_t arg_ring_cnt; 75 } aggr_pseudo_rx_group_t; 76 77 /* 78 * A link aggregation MAC port. 79 * Note that lp_next is protected by the lg_lock of the group the 80 * port is part of. 81 */ 82 typedef struct aggr_port_s { 83 struct aggr_port_s *lp_next; 84 struct aggr_grp_s *lp_grp; /* back ptr to group */ 85 datalink_id_t lp_linkid; 86 uint16_t lp_portid; 87 uint8_t lp_addr[ETHERADDRL]; /* port MAC address */ 88 uint32_t lp_refs; /* refcount */ 89 aggr_port_state_t lp_state; 90 uint32_t lp_started : 1, 91 lp_tx_enabled : 1, 92 lp_collector_enabled : 1, 93 lp_promisc_on : 1, 94 lp_no_link_update : 1, 95 lp_grp_added : 1, 96 lp_closing : 1, 97 lp_pad_bits : 25; 98 mac_handle_t lp_mh; 99 mac_client_handle_t lp_mch; 100 const mac_info_t *lp_mip; 101 mac_notify_handle_t lp_mnh; 102 uint_t lp_tx_idx; /* idx in group's tx array */ 103 uint64_t lp_ifspeed; 104 link_state_t lp_link_state; 105 link_duplex_t lp_link_duplex; 106 uint64_t lp_stat[MAC_NSTAT]; 107 uint64_t lp_ether_stat[ETHER_NSTAT]; 108 aggr_lacp_port_t lp_lacp; /* LACP state */ 109 lacp_stats_t lp_lacp_stats; 110 uint32_t lp_margin; 111 mac_promisc_handle_t lp_mphp; 112 mac_unicast_handle_t lp_mah; 113 114 /* List of non-primary addresses that requires promiscous mode set */ 115 aggr_unicst_addr_t *lp_prom_addr; 116 /* handle of the underlying HW RX group */ 117 mac_group_handle_t lp_hwgh; 118 } aggr_port_t; 119 120 /* 121 * A link aggregation group. 122 * 123 * The following per-group flags are defined: 124 * 125 * - lg_addr_fixed: set when the MAC address has been explicitely set 126 * when the group was created, or by a m_unicst_set() request. 127 * If this flag is not set, the MAC address of the group will be 128 * set to the first port that is added to the group. 129 * 130 * - lg_add_set: used only when lg_addr_fixed is not set. Captures whether 131 * the MAC address was initialized according to the members of the group. 132 * When set, the lg_port field points to the port from which the 133 * MAC address was initialized. 134 * 135 */ 136 typedef struct aggr_grp_s { 137 datalink_id_t lg_linkid; 138 uint16_t lg_key; /* key (group port number) */ 139 uint32_t lg_refs; /* refcount */ 140 uint16_t lg_nports; /* number of MAC ports */ 141 uint8_t lg_addr[ETHERADDRL]; /* group MAC address */ 142 uint16_t 143 lg_closing : 1, 144 lg_addr_fixed : 1, /* fixed MAC address? */ 145 lg_started : 1, /* group started? */ 146 lg_promisc : 1, /* in promiscuous mode? */ 147 lg_zcopy : 1, 148 lg_vlan : 1, 149 lg_force : 1, 150 lg_pad_bits : 9; 151 aggr_port_t *lg_ports; /* list of configured ports */ 152 aggr_port_t *lg_mac_addr_port; 153 mac_handle_t lg_mh; 154 uint_t lg_nattached_ports; 155 krwlock_t lg_tx_lock; 156 uint_t lg_ntx_ports; 157 aggr_port_t **lg_tx_ports; /* array of tx ports */ 158 uint_t lg_tx_ports_size; /* size of lg_tx_ports */ 159 uint32_t lg_tx_policy; /* outbound policy */ 160 uint64_t lg_ifspeed; 161 link_state_t lg_link_state; 162 link_duplex_t lg_link_duplex; 163 uint64_t lg_stat[MAC_NSTAT]; 164 uint64_t lg_ether_stat[ETHER_NSTAT]; 165 aggr_lacp_mode_t lg_lacp_mode; /* off, active, or passive */ 166 Agg_t aggr; /* 802.3ad data */ 167 uint32_t lg_hcksum_txflags; 168 uint_t lg_max_sdu; 169 uint32_t lg_margin; 170 171 /* 172 * The following fields are used by the LACP packets processing. 173 * Specifically, as the LACP packets processing is not performance 174 * critical, all LACP packets will be handled by a dedicated thread 175 * instead of in the mac_rx() call. This is to avoid the dead lock 176 * with mac_unicast_remove(), which holding the mac perimeter of the 177 * aggr, and wait for the mr_refcnt of the RX ring to drop to zero. 178 */ 179 kmutex_t lg_lacp_lock; 180 kcondvar_t lg_lacp_cv; 181 mblk_t *lg_lacp_head; 182 mblk_t *lg_lacp_tail; 183 kthread_t *lg_lacp_rx_thread; 184 boolean_t lg_lacp_done; 185 aggr_pseudo_rx_group_t lg_rx_group; 186 187 /* 188 * The following fields are used by aggr to wait for all the 189 * aggr_port_notify_cb() and aggr_port_timer_thread() to finish 190 * before it calls mac_unregister() when the aggr is deleted. 191 */ 192 kmutex_t lg_port_lock; 193 kcondvar_t lg_port_cv; 194 int lg_port_ref; 195 } aggr_grp_t; 196 197 #define AGGR_GRP_REFHOLD(grp) { \ 198 atomic_add_32(&(grp)->lg_refs, 1); \ 199 ASSERT((grp)->lg_refs != 0); \ 200 } 201 202 #define AGGR_GRP_REFRELE(grp) { \ 203 ASSERT((grp)->lg_refs != 0); \ 204 membar_exit(); \ 205 if (atomic_add_32_nv(&(grp)->lg_refs, -1) == 0) \ 206 aggr_grp_free(grp); \ 207 } 208 209 #define AGGR_PORT_REFHOLD(port) { \ 210 atomic_add_32(&(port)->lp_refs, 1); \ 211 ASSERT((port)->lp_refs != 0); \ 212 } 213 214 #define AGGR_PORT_REFRELE(port) { \ 215 ASSERT((port)->lp_refs != 0); \ 216 membar_exit(); \ 217 if (atomic_add_32_nv(&(port)->lp_refs, -1) == 0) \ 218 aggr_port_free(port); \ 219 } 220 221 extern dev_info_t *aggr_dip; 222 extern int aggr_ioc_init(void); 223 extern void aggr_ioc_fini(void); 224 225 typedef int (*aggr_grp_info_new_grp_fn_t)(void *, datalink_id_t, uint32_t, 226 uchar_t *, boolean_t, boolean_t, uint32_t, uint32_t, aggr_lacp_mode_t, 227 aggr_lacp_timer_t); 228 typedef int (*aggr_grp_info_new_port_fn_t)(void *, datalink_id_t, uchar_t *, 229 aggr_port_state_t, aggr_lacp_state_t *); 230 231 extern void aggr_grp_init(void); 232 extern void aggr_grp_fini(void); 233 extern int aggr_grp_create(datalink_id_t, uint32_t, uint_t, laioc_port_t *, 234 uint32_t, boolean_t, boolean_t, uchar_t *, aggr_lacp_mode_t, 235 aggr_lacp_timer_t); 236 extern int aggr_grp_delete(datalink_id_t); 237 extern void aggr_grp_free(aggr_grp_t *); 238 239 extern int aggr_grp_info(datalink_id_t, void *, aggr_grp_info_new_grp_fn_t, 240 aggr_grp_info_new_port_fn_t); 241 extern void aggr_grp_notify(aggr_grp_t *, uint32_t); 242 extern boolean_t aggr_grp_attach_port(aggr_grp_t *, aggr_port_t *); 243 extern boolean_t aggr_grp_detach_port(aggr_grp_t *, aggr_port_t *); 244 extern void aggr_grp_port_mac_changed(aggr_grp_t *, aggr_port_t *, 245 boolean_t *, boolean_t *); 246 extern int aggr_grp_add_ports(datalink_id_t, uint_t, boolean_t, 247 laioc_port_t *); 248 extern int aggr_grp_rem_ports(datalink_id_t, uint_t, laioc_port_t *); 249 extern boolean_t aggr_grp_update_ports_mac(aggr_grp_t *); 250 extern int aggr_grp_modify(datalink_id_t, uint8_t, uint32_t, boolean_t, 251 const uchar_t *, aggr_lacp_mode_t, aggr_lacp_timer_t); 252 extern void aggr_grp_multicst_port(aggr_port_t *, boolean_t); 253 extern uint_t aggr_grp_count(void); 254 255 extern void aggr_port_init(void); 256 extern void aggr_port_fini(void); 257 extern int aggr_port_create(aggr_grp_t *, const datalink_id_t, boolean_t, 258 aggr_port_t **); 259 extern void aggr_port_delete(aggr_port_t *); 260 extern void aggr_port_free(aggr_port_t *); 261 extern int aggr_port_start(aggr_port_t *); 262 extern void aggr_port_stop(aggr_port_t *); 263 extern int aggr_port_promisc(aggr_port_t *, boolean_t); 264 extern int aggr_port_unicst(aggr_port_t *); 265 extern int aggr_port_multicst(void *, boolean_t, const uint8_t *); 266 extern uint64_t aggr_port_stat(aggr_port_t *, uint_t); 267 extern boolean_t aggr_port_notify_link(aggr_grp_t *, aggr_port_t *); 268 extern void aggr_port_init_callbacks(aggr_port_t *); 269 270 extern void aggr_recv_cb(void *, mac_resource_handle_t, mblk_t *, boolean_t); 271 272 extern mblk_t *aggr_m_tx(void *, mblk_t *); 273 extern void aggr_send_port_enable(aggr_port_t *); 274 extern void aggr_send_port_disable(aggr_port_t *); 275 extern void aggr_send_update_policy(aggr_grp_t *, uint32_t); 276 277 extern void aggr_lacp_init(void); 278 extern void aggr_lacp_fini(void); 279 extern void aggr_lacp_init_port(aggr_port_t *); 280 extern void aggr_lacp_init_grp(aggr_grp_t *); 281 extern void aggr_lacp_set_mode(aggr_grp_t *, aggr_lacp_mode_t, 282 aggr_lacp_timer_t); 283 extern void aggr_lacp_update_mode(aggr_grp_t *, aggr_lacp_mode_t); 284 extern void aggr_lacp_update_timer(aggr_grp_t *, aggr_lacp_timer_t); 285 extern void aggr_lacp_rx_enqueue(aggr_port_t *, mblk_t *); 286 extern void aggr_lacp_port_attached(aggr_port_t *); 287 extern void aggr_lacp_port_detached(aggr_port_t *); 288 extern void aggr_port_lacp_set_mode(aggr_grp_t *, aggr_port_t *); 289 290 extern void aggr_lacp_rx_thread(void *); 291 extern void aggr_recv_lacp(aggr_port_t *, mac_resource_handle_t, mblk_t *); 292 293 extern void aggr_grp_port_hold(aggr_port_t *); 294 extern void aggr_grp_port_rele(aggr_port_t *); 295 extern void aggr_grp_port_wait(aggr_grp_t *); 296 297 extern int aggr_port_addmac(aggr_port_t *, const uint8_t *); 298 extern void aggr_port_remmac(aggr_port_t *, const uint8_t *); 299 300 #endif /* _KERNEL */ 301 302 #ifdef __cplusplus 303 } 304 #endif 305 306 #endif /* _SYS_AGGR_IMPL_H */ 307