10Sstevel@tonic-gate /* 20Sstevel@tonic-gate * CDDL HEADER START 30Sstevel@tonic-gate * 40Sstevel@tonic-gate * The contents of this file are subject to the terms of the 51537Snd99603 * Common Development and Distribution License (the "License"). 61537Snd99603 * You may not use this file except in compliance with the License. 70Sstevel@tonic-gate * 80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 100Sstevel@tonic-gate * See the License for the specific language governing permissions 110Sstevel@tonic-gate * and limitations under the License. 120Sstevel@tonic-gate * 130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 180Sstevel@tonic-gate * 190Sstevel@tonic-gate * CDDL HEADER END 200Sstevel@tonic-gate */ 210Sstevel@tonic-gate /* 228833SVenu.Iyer@Sun.COM * Copyright 2009 Sun Microsystems, Inc. All rights reserved. 230Sstevel@tonic-gate * Use is subject to license terms. 240Sstevel@tonic-gate */ 250Sstevel@tonic-gate 260Sstevel@tonic-gate #ifndef _SYS_AGGR_IMPL_H 270Sstevel@tonic-gate #define _SYS_AGGR_IMPL_H 280Sstevel@tonic-gate 290Sstevel@tonic-gate #include <sys/types.h> 302311Sseb #include <sys/mac_ether.h> 318275SEric Cheng #include <sys/mac_provider.h> 328275SEric Cheng #include <sys/mac_client.h> 338275SEric Cheng #include <sys/mac_client_priv.h> 340Sstevel@tonic-gate #include <sys/aggr_lacp.h> 350Sstevel@tonic-gate 360Sstevel@tonic-gate #ifdef __cplusplus 370Sstevel@tonic-gate extern "C" { 380Sstevel@tonic-gate #endif 390Sstevel@tonic-gate 400Sstevel@tonic-gate #ifdef _KERNEL 410Sstevel@tonic-gate 42269Sericheng #define AGGR_MINOR_CTL 1 /* control interface minor */ 430Sstevel@tonic-gate 440Sstevel@tonic-gate /* flags for aggr_grp_modify() */ 450Sstevel@tonic-gate #define AGGR_MODIFY_POLICY 0x01 460Sstevel@tonic-gate #define AGGR_MODIFY_MAC 0x02 470Sstevel@tonic-gate #define AGGR_MODIFY_LACP_MODE 0x04 480Sstevel@tonic-gate #define AGGR_MODIFY_LACP_TIMER 0x08 490Sstevel@tonic-gate 500Sstevel@tonic-gate /* 518275SEric Cheng * Possible value of aggr_rseudo_rx_ring_t.arr_flags. Set when the ring entry 528275SEric Cheng * in the pseudo RX group is used. 538275SEric Cheng */ 548275SEric Cheng #define MAC_PSEUDO_RING_INUSE 0x01 558275SEric Cheng 568275SEric Cheng typedef struct aggr_unicst_addr_s { 578275SEric Cheng uint8_t aua_addr[ETHERADDRL]; 588275SEric Cheng struct aggr_unicst_addr_s *aua_next; 598275SEric Cheng } aggr_unicst_addr_t; 608275SEric Cheng 618275SEric Cheng typedef struct aggr_pseudo_rx_ring_s { 628275SEric Cheng mac_ring_handle_t arr_rh; /* filled in by aggr_fill_ring() */ 638275SEric Cheng struct aggr_port_s *arr_port; 648275SEric Cheng mac_ring_handle_t arr_hw_rh; 658275SEric Cheng uint_t arr_flags; 668275SEric Cheng uint64_t arr_gen; 678275SEric Cheng } aggr_pseudo_rx_ring_t; 688275SEric Cheng 698275SEric Cheng typedef struct aggr_pseudo_rx_group_s { 708275SEric Cheng struct aggr_grp_s *arg_grp; /* filled in by aggr_fill_group() */ 718275SEric Cheng mac_group_handle_t arg_gh; /* filled in by aggr_fill_group() */ 728275SEric Cheng aggr_unicst_addr_t *arg_macaddr; 738275SEric Cheng aggr_pseudo_rx_ring_t arg_rings[MAX_RINGS_PER_GROUP]; 748275SEric Cheng uint_t arg_ring_cnt; 758275SEric Cheng } aggr_pseudo_rx_group_t; 768275SEric Cheng 778275SEric Cheng /* 780Sstevel@tonic-gate * A link aggregation MAC port. 790Sstevel@tonic-gate * Note that lp_next is protected by the lg_lock of the group the 800Sstevel@tonic-gate * port is part of. 810Sstevel@tonic-gate */ 820Sstevel@tonic-gate typedef struct aggr_port_s { 830Sstevel@tonic-gate struct aggr_port_s *lp_next; 840Sstevel@tonic-gate struct aggr_grp_s *lp_grp; /* back ptr to group */ 855895Syz147064 datalink_id_t lp_linkid; 865102Syz147064 uint16_t lp_portid; 870Sstevel@tonic-gate uint8_t lp_addr[ETHERADDRL]; /* port MAC address */ 880Sstevel@tonic-gate uint32_t lp_refs; /* refcount */ 890Sstevel@tonic-gate aggr_port_state_t lp_state; 900Sstevel@tonic-gate uint32_t lp_started : 1, 910Sstevel@tonic-gate lp_tx_enabled : 1, 920Sstevel@tonic-gate lp_collector_enabled : 1, 930Sstevel@tonic-gate lp_promisc_on : 1, 945895Syz147064 lp_no_link_update : 1, 958275SEric Cheng lp_grp_added : 1, 968275SEric Cheng lp_closing : 1, 978275SEric Cheng lp_pad_bits : 25; 980Sstevel@tonic-gate mac_handle_t lp_mh; 998275SEric Cheng mac_client_handle_t lp_mch; 1000Sstevel@tonic-gate const mac_info_t *lp_mip; 1010Sstevel@tonic-gate mac_notify_handle_t lp_mnh; 1020Sstevel@tonic-gate uint_t lp_tx_idx; /* idx in group's tx array */ 1030Sstevel@tonic-gate uint64_t lp_ifspeed; 1040Sstevel@tonic-gate link_state_t lp_link_state; 1050Sstevel@tonic-gate link_duplex_t lp_link_duplex; 1060Sstevel@tonic-gate uint64_t lp_stat[MAC_NSTAT]; 1072311Sseb uint64_t lp_ether_stat[ETHER_NSTAT]; 1080Sstevel@tonic-gate aggr_lacp_port_t lp_lacp; /* LACP state */ 1090Sstevel@tonic-gate lacp_stats_t lp_lacp_stats; 1105895Syz147064 uint32_t lp_margin; 1118275SEric Cheng mac_promisc_handle_t lp_mphp; 1128275SEric Cheng mac_unicast_handle_t lp_mah; 1130Sstevel@tonic-gate 1148275SEric Cheng /* List of non-primary addresses that requires promiscous mode set */ 1158275SEric Cheng aggr_unicst_addr_t *lp_prom_addr; 1168275SEric Cheng /* handle of the underlying HW RX group */ 1178275SEric Cheng mac_group_handle_t lp_hwgh; 1188275SEric Cheng } aggr_port_t; 1197085Sudpa 1200Sstevel@tonic-gate /* 1210Sstevel@tonic-gate * A link aggregation group. 1220Sstevel@tonic-gate * 1230Sstevel@tonic-gate * The following per-group flags are defined: 1240Sstevel@tonic-gate * 1250Sstevel@tonic-gate * - lg_addr_fixed: set when the MAC address has been explicitely set 1260Sstevel@tonic-gate * when the group was created, or by a m_unicst_set() request. 1270Sstevel@tonic-gate * If this flag is not set, the MAC address of the group will be 1280Sstevel@tonic-gate * set to the first port that is added to the group. 1290Sstevel@tonic-gate * 1300Sstevel@tonic-gate * - lg_add_set: used only when lg_addr_fixed is not set. Captures whether 1310Sstevel@tonic-gate * the MAC address was initialized according to the members of the group. 1320Sstevel@tonic-gate * When set, the lg_port field points to the port from which the 1330Sstevel@tonic-gate * MAC address was initialized. 1340Sstevel@tonic-gate * 1350Sstevel@tonic-gate */ 1360Sstevel@tonic-gate typedef struct aggr_grp_s { 1375895Syz147064 datalink_id_t lg_linkid; 1380Sstevel@tonic-gate uint16_t lg_key; /* key (group port number) */ 1390Sstevel@tonic-gate uint32_t lg_refs; /* refcount */ 1400Sstevel@tonic-gate uint16_t lg_nports; /* number of MAC ports */ 1410Sstevel@tonic-gate uint8_t lg_addr[ETHERADDRL]; /* group MAC address */ 1420Sstevel@tonic-gate uint16_t 1432047Syz147064 lg_closing : 1, 1440Sstevel@tonic-gate lg_addr_fixed : 1, /* fixed MAC address? */ 1450Sstevel@tonic-gate lg_started : 1, /* group started? */ 1460Sstevel@tonic-gate lg_promisc : 1, /* in promiscuous mode? */ 1475895Syz147064 lg_zcopy : 1, 1485895Syz147064 lg_vlan : 1, 1495895Syz147064 lg_force : 1, 150*8970SRoamer@Sun.COM lg_lso : 1, 151*8970SRoamer@Sun.COM lg_pad_bits : 8; 1520Sstevel@tonic-gate aggr_port_t *lg_ports; /* list of configured ports */ 1530Sstevel@tonic-gate aggr_port_t *lg_mac_addr_port; 1542311Sseb mac_handle_t lg_mh; 1550Sstevel@tonic-gate uint_t lg_nattached_ports; 1568275SEric Cheng krwlock_t lg_tx_lock; 1570Sstevel@tonic-gate uint_t lg_ntx_ports; 1580Sstevel@tonic-gate aggr_port_t **lg_tx_ports; /* array of tx ports */ 1590Sstevel@tonic-gate uint_t lg_tx_ports_size; /* size of lg_tx_ports */ 1600Sstevel@tonic-gate uint32_t lg_tx_policy; /* outbound policy */ 1618833SVenu.Iyer@Sun.COM uint8_t lg_mac_tx_policy; 1620Sstevel@tonic-gate uint64_t lg_ifspeed; 1630Sstevel@tonic-gate link_state_t lg_link_state; 1640Sstevel@tonic-gate link_duplex_t lg_link_duplex; 1650Sstevel@tonic-gate uint64_t lg_stat[MAC_NSTAT]; 1662311Sseb uint64_t lg_ether_stat[ETHER_NSTAT]; 1670Sstevel@tonic-gate aggr_lacp_mode_t lg_lacp_mode; /* off, active, or passive */ 1680Sstevel@tonic-gate Agg_t aggr; /* 802.3ad data */ 1692311Sseb uint32_t lg_hcksum_txflags; 1702803Snd99603 uint_t lg_max_sdu; 1715895Syz147064 uint32_t lg_margin; 172*8970SRoamer@Sun.COM mac_capab_lso_t lg_cap_lso; 1730Sstevel@tonic-gate 1748275SEric Cheng /* 1758275SEric Cheng * The following fields are used by the LACP packets processing. 1768275SEric Cheng * Specifically, as the LACP packets processing is not performance 1778275SEric Cheng * critical, all LACP packets will be handled by a dedicated thread 1788275SEric Cheng * instead of in the mac_rx() call. This is to avoid the dead lock 1798275SEric Cheng * with mac_unicast_remove(), which holding the mac perimeter of the 1808275SEric Cheng * aggr, and wait for the mr_refcnt of the RX ring to drop to zero. 1818275SEric Cheng */ 1828275SEric Cheng kmutex_t lg_lacp_lock; 1838275SEric Cheng kcondvar_t lg_lacp_cv; 1848275SEric Cheng mblk_t *lg_lacp_head; 1858275SEric Cheng mblk_t *lg_lacp_tail; 1868275SEric Cheng kthread_t *lg_lacp_rx_thread; 1878275SEric Cheng boolean_t lg_lacp_done; 1888275SEric Cheng aggr_pseudo_rx_group_t lg_rx_group; 1898275SEric Cheng 1908275SEric Cheng /* 1918275SEric Cheng * The following fields are used by aggr to wait for all the 1928275SEric Cheng * aggr_port_notify_cb() and aggr_port_timer_thread() to finish 1938275SEric Cheng * before it calls mac_unregister() when the aggr is deleted. 1948275SEric Cheng */ 1958275SEric Cheng kmutex_t lg_port_lock; 1968275SEric Cheng kcondvar_t lg_port_cv; 1978275SEric Cheng int lg_port_ref; 1988275SEric Cheng } aggr_grp_t; 1990Sstevel@tonic-gate 2000Sstevel@tonic-gate #define AGGR_GRP_REFHOLD(grp) { \ 2010Sstevel@tonic-gate atomic_add_32(&(grp)->lg_refs, 1); \ 2020Sstevel@tonic-gate ASSERT((grp)->lg_refs != 0); \ 2030Sstevel@tonic-gate } 2040Sstevel@tonic-gate 2050Sstevel@tonic-gate #define AGGR_GRP_REFRELE(grp) { \ 2060Sstevel@tonic-gate ASSERT((grp)->lg_refs != 0); \ 2070Sstevel@tonic-gate membar_exit(); \ 2080Sstevel@tonic-gate if (atomic_add_32_nv(&(grp)->lg_refs, -1) == 0) \ 2090Sstevel@tonic-gate aggr_grp_free(grp); \ 2100Sstevel@tonic-gate } 2110Sstevel@tonic-gate 2120Sstevel@tonic-gate #define AGGR_PORT_REFHOLD(port) { \ 2130Sstevel@tonic-gate atomic_add_32(&(port)->lp_refs, 1); \ 2140Sstevel@tonic-gate ASSERT((port)->lp_refs != 0); \ 2150Sstevel@tonic-gate } 2160Sstevel@tonic-gate 2170Sstevel@tonic-gate #define AGGR_PORT_REFRELE(port) { \ 2180Sstevel@tonic-gate ASSERT((port)->lp_refs != 0); \ 2190Sstevel@tonic-gate membar_exit(); \ 2200Sstevel@tonic-gate if (atomic_add_32_nv(&(port)->lp_refs, -1) == 0) \ 2210Sstevel@tonic-gate aggr_port_free(port); \ 2220Sstevel@tonic-gate } 2230Sstevel@tonic-gate 2240Sstevel@tonic-gate extern dev_info_t *aggr_dip; 2257408SSebastien.Roy@Sun.COM extern int aggr_ioc_init(void); 2267408SSebastien.Roy@Sun.COM extern void aggr_ioc_fini(void); 2270Sstevel@tonic-gate 2285895Syz147064 typedef int (*aggr_grp_info_new_grp_fn_t)(void *, datalink_id_t, uint32_t, 2295895Syz147064 uchar_t *, boolean_t, boolean_t, uint32_t, uint32_t, aggr_lacp_mode_t, 2305895Syz147064 aggr_lacp_timer_t); 2315895Syz147064 typedef int (*aggr_grp_info_new_port_fn_t)(void *, datalink_id_t, uchar_t *, 2322311Sseb aggr_port_state_t, aggr_lacp_state_t *); 2330Sstevel@tonic-gate 2340Sstevel@tonic-gate extern void aggr_grp_init(void); 2351804Sericheng extern void aggr_grp_fini(void); 2365895Syz147064 extern int aggr_grp_create(datalink_id_t, uint32_t, uint_t, laioc_port_t *, 2375895Syz147064 uint32_t, boolean_t, boolean_t, uchar_t *, aggr_lacp_mode_t, 2385895Syz147064 aggr_lacp_timer_t); 2395895Syz147064 extern int aggr_grp_delete(datalink_id_t); 2400Sstevel@tonic-gate extern void aggr_grp_free(aggr_grp_t *); 2410Sstevel@tonic-gate 2425895Syz147064 extern int aggr_grp_info(datalink_id_t, void *, aggr_grp_info_new_grp_fn_t, 2435895Syz147064 aggr_grp_info_new_port_fn_t); 2440Sstevel@tonic-gate extern void aggr_grp_notify(aggr_grp_t *, uint32_t); 2450Sstevel@tonic-gate extern boolean_t aggr_grp_attach_port(aggr_grp_t *, aggr_port_t *); 2468275SEric Cheng extern boolean_t aggr_grp_detach_port(aggr_grp_t *, aggr_port_t *); 2472047Syz147064 extern void aggr_grp_port_mac_changed(aggr_grp_t *, aggr_port_t *, 2482047Syz147064 boolean_t *, boolean_t *); 2495895Syz147064 extern int aggr_grp_add_ports(datalink_id_t, uint_t, boolean_t, 2505895Syz147064 laioc_port_t *); 2515895Syz147064 extern int aggr_grp_rem_ports(datalink_id_t, uint_t, laioc_port_t *); 2522047Syz147064 extern boolean_t aggr_grp_update_ports_mac(aggr_grp_t *); 2538275SEric Cheng extern int aggr_grp_modify(datalink_id_t, uint8_t, uint32_t, boolean_t, 2548275SEric Cheng const uchar_t *, aggr_lacp_mode_t, aggr_lacp_timer_t); 2550Sstevel@tonic-gate extern void aggr_grp_multicst_port(aggr_port_t *, boolean_t); 256269Sericheng extern uint_t aggr_grp_count(void); 2570Sstevel@tonic-gate 2580Sstevel@tonic-gate extern void aggr_port_init(void); 2591804Sericheng extern void aggr_port_fini(void); 2608275SEric Cheng extern int aggr_port_create(aggr_grp_t *, const datalink_id_t, boolean_t, 2618275SEric Cheng aggr_port_t **); 2620Sstevel@tonic-gate extern void aggr_port_delete(aggr_port_t *); 2630Sstevel@tonic-gate extern void aggr_port_free(aggr_port_t *); 2640Sstevel@tonic-gate extern int aggr_port_start(aggr_port_t *); 2650Sstevel@tonic-gate extern void aggr_port_stop(aggr_port_t *); 2660Sstevel@tonic-gate extern int aggr_port_promisc(aggr_port_t *, boolean_t); 2678275SEric Cheng extern int aggr_port_unicst(aggr_port_t *); 2680Sstevel@tonic-gate extern int aggr_port_multicst(void *, boolean_t, const uint8_t *); 2692311Sseb extern uint64_t aggr_port_stat(aggr_port_t *, uint_t); 2708275SEric Cheng extern boolean_t aggr_port_notify_link(aggr_grp_t *, aggr_port_t *); 2712163Syz147064 extern void aggr_port_init_callbacks(aggr_port_t *); 2720Sstevel@tonic-gate 2738275SEric Cheng extern void aggr_recv_cb(void *, mac_resource_handle_t, mblk_t *, boolean_t); 2740Sstevel@tonic-gate 2750Sstevel@tonic-gate extern mblk_t *aggr_m_tx(void *, mblk_t *); 2760Sstevel@tonic-gate extern void aggr_send_port_enable(aggr_port_t *); 2770Sstevel@tonic-gate extern void aggr_send_port_disable(aggr_port_t *); 2780Sstevel@tonic-gate extern void aggr_send_update_policy(aggr_grp_t *, uint32_t); 2790Sstevel@tonic-gate 2801537Snd99603 extern void aggr_lacp_init(void); 2811537Snd99603 extern void aggr_lacp_fini(void); 2820Sstevel@tonic-gate extern void aggr_lacp_init_port(aggr_port_t *); 2830Sstevel@tonic-gate extern void aggr_lacp_init_grp(aggr_grp_t *); 2840Sstevel@tonic-gate extern void aggr_lacp_set_mode(aggr_grp_t *, aggr_lacp_mode_t, 2850Sstevel@tonic-gate aggr_lacp_timer_t); 2860Sstevel@tonic-gate extern void aggr_lacp_update_mode(aggr_grp_t *, aggr_lacp_mode_t); 2870Sstevel@tonic-gate extern void aggr_lacp_update_timer(aggr_grp_t *, aggr_lacp_timer_t); 2888275SEric Cheng extern void aggr_lacp_rx_enqueue(aggr_port_t *, mblk_t *); 2890Sstevel@tonic-gate extern void aggr_lacp_port_attached(aggr_port_t *); 2900Sstevel@tonic-gate extern void aggr_lacp_port_detached(aggr_port_t *); 2918275SEric Cheng extern void aggr_port_lacp_set_mode(aggr_grp_t *, aggr_port_t *); 2928275SEric Cheng 2938275SEric Cheng extern void aggr_lacp_rx_thread(void *); 2948275SEric Cheng extern void aggr_recv_lacp(aggr_port_t *, mac_resource_handle_t, mblk_t *); 2958275SEric Cheng 2968275SEric Cheng extern void aggr_grp_port_hold(aggr_port_t *); 2978275SEric Cheng extern void aggr_grp_port_rele(aggr_port_t *); 2988275SEric Cheng extern void aggr_grp_port_wait(aggr_grp_t *); 2998275SEric Cheng 3008275SEric Cheng extern int aggr_port_addmac(aggr_port_t *, const uint8_t *); 3018275SEric Cheng extern void aggr_port_remmac(aggr_port_t *, const uint8_t *); 3020Sstevel@tonic-gate 3030Sstevel@tonic-gate #endif /* _KERNEL */ 3040Sstevel@tonic-gate 3050Sstevel@tonic-gate #ifdef __cplusplus 3060Sstevel@tonic-gate } 3070Sstevel@tonic-gate #endif 3080Sstevel@tonic-gate 3090Sstevel@tonic-gate #endif /* _SYS_AGGR_IMPL_H */ 310