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 51852Syz147064 * Common Development and Distribution License (the "License"). 61852Syz147064 * 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 /* 22*5895Syz147064 * Copyright 2008 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_MAC_IMPL_H 270Sstevel@tonic-gate #define _SYS_MAC_IMPL_H 280Sstevel@tonic-gate 290Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 300Sstevel@tonic-gate 310Sstevel@tonic-gate #include <sys/mac.h> 322311Sseb #include <net/if.h> 330Sstevel@tonic-gate 340Sstevel@tonic-gate #ifdef __cplusplus 350Sstevel@tonic-gate extern "C" { 360Sstevel@tonic-gate #endif 370Sstevel@tonic-gate 380Sstevel@tonic-gate typedef struct mac_multicst_addr_s mac_multicst_addr_t; 390Sstevel@tonic-gate 400Sstevel@tonic-gate struct mac_multicst_addr_s { 410Sstevel@tonic-gate mac_multicst_addr_t *mma_nextp; 420Sstevel@tonic-gate uint_t mma_ref; 432311Sseb uint8_t mma_addr[MAXMACADDRLEN]; 440Sstevel@tonic-gate }; 450Sstevel@tonic-gate 46*5895Syz147064 typedef struct mac_margin_req_s mac_margin_req_t; 47*5895Syz147064 48*5895Syz147064 struct mac_margin_req_s { 49*5895Syz147064 mac_margin_req_t *mmr_nextp; 50*5895Syz147064 uint_t mmr_ref; 51*5895Syz147064 uint32_t mmr_margin; 52*5895Syz147064 }; 53*5895Syz147064 540Sstevel@tonic-gate typedef struct mac_notify_fn_s mac_notify_fn_t; 550Sstevel@tonic-gate 560Sstevel@tonic-gate struct mac_notify_fn_s { 570Sstevel@tonic-gate mac_notify_fn_t *mnf_nextp; 580Sstevel@tonic-gate mac_notify_t mnf_fn; 590Sstevel@tonic-gate void *mnf_arg; 600Sstevel@tonic-gate }; 610Sstevel@tonic-gate 620Sstevel@tonic-gate typedef struct mac_rx_fn_s mac_rx_fn_t; 630Sstevel@tonic-gate 640Sstevel@tonic-gate struct mac_rx_fn_s { 650Sstevel@tonic-gate mac_rx_fn_t *mrf_nextp; 660Sstevel@tonic-gate mac_rx_t mrf_fn; 670Sstevel@tonic-gate void *mrf_arg; 684913Sethindra boolean_t mrf_inuse; 695084Sjohnlev boolean_t mrf_active; 700Sstevel@tonic-gate }; 710Sstevel@tonic-gate 720Sstevel@tonic-gate typedef struct mac_txloop_fn_s mac_txloop_fn_t; 730Sstevel@tonic-gate 740Sstevel@tonic-gate struct mac_txloop_fn_s { 750Sstevel@tonic-gate mac_txloop_fn_t *mtf_nextp; 760Sstevel@tonic-gate mac_txloop_t mtf_fn; 770Sstevel@tonic-gate void *mtf_arg; 780Sstevel@tonic-gate }; 790Sstevel@tonic-gate 802311Sseb typedef struct mactype_s { 812311Sseb const char *mt_ident; 822311Sseb uint32_t mt_ref; 832311Sseb uint_t mt_type; 843147Sxc151355 uint_t mt_nativetype; 852311Sseb size_t mt_addr_length; 862311Sseb uint8_t *mt_brdcst_addr; 872311Sseb mactype_ops_t mt_ops; 882311Sseb mac_stat_info_t *mt_stats; /* array of mac_stat_info_t elements */ 892311Sseb size_t mt_statcount; /* number of elements in mt_stats */ 902311Sseb } mactype_t; 910Sstevel@tonic-gate 925084Sjohnlev 935084Sjohnlev #define MAC_VNIC_TXINFO_REFHOLD(mvt) { \ 945084Sjohnlev mutex_enter(&(mvt)->mv_lock); \ 955084Sjohnlev (mvt)->mv_refs++; \ 965084Sjohnlev mutex_exit(&(mvt)->mv_lock); \ 975084Sjohnlev } 985084Sjohnlev 995084Sjohnlev #define MAC_VNIC_TXINFO_REFRELE(mvt) { \ 1005084Sjohnlev mutex_enter(&(mvt)->mv_lock); \ 1015084Sjohnlev if (--(mvt)->mv_refs == 0 && (mvt)->mv_clearing) { \ 1025084Sjohnlev (mvt)->mv_clearing = B_FALSE; \ 1035084Sjohnlev cv_signal(&(mvt)->mv_cv); \ 1045084Sjohnlev } \ 1055084Sjohnlev mutex_exit(&(mvt)->mv_lock); \ 1065084Sjohnlev } 1075084Sjohnlev 1085084Sjohnlev typedef struct mac_vnic_tx_s { 1095084Sjohnlev mac_txinfo_t mv_txinfo; /* provided by VNIC */ 1105084Sjohnlev uint32_t mv_refs; 1115084Sjohnlev kmutex_t mv_lock; 1125084Sjohnlev kcondvar_t mv_cv; 1135084Sjohnlev boolean_t mv_clearing; 1145084Sjohnlev } mac_vnic_tx_t; 1155084Sjohnlev 1162311Sseb /* 1172311Sseb * Each registered MAC is associated with a mac_t structure. 1182311Sseb */ 1192311Sseb typedef struct mac_impl_s { 120*5895Syz147064 /* 121*5895Syz147064 * The following fields are set in mac_register() and will not be 122*5895Syz147064 * changed until mac_unregister(). No lock is needed to access them. 123*5895Syz147064 */ 1242311Sseb char mi_name[LIFNAMSIZ]; 1252311Sseb void *mi_driver; /* Driver private data */ 1262311Sseb mac_info_t mi_info; 1272311Sseb mactype_t *mi_type; 1282311Sseb void *mi_pdata; 1292311Sseb size_t mi_pdata_size; 1302311Sseb mac_callbacks_t *mi_callbacks; 1312311Sseb dev_info_t *mi_dip; 132*5895Syz147064 minor_t mi_minor; 133*5895Syz147064 dev_t mi_phy_dev; 134*5895Syz147064 kstat_t *mi_ksp; 135*5895Syz147064 uint_t mi_kstat_count; 136*5895Syz147064 mac_txinfo_t mi_txinfo; 137*5895Syz147064 mac_txinfo_t mi_txloopinfo; 138*5895Syz147064 139*5895Syz147064 krwlock_t mi_gen_lock; 140*5895Syz147064 uint32_t mi_oref; 1410Sstevel@tonic-gate uint32_t mi_ref; 1421852Syz147064 boolean_t mi_disabled; 143*5895Syz147064 boolean_t mi_exclusive; 144*5895Syz147064 1450Sstevel@tonic-gate krwlock_t mi_state_lock; 1460Sstevel@tonic-gate uint_t mi_active; 147*5895Syz147064 1480Sstevel@tonic-gate krwlock_t mi_data_lock; 1492311Sseb link_state_t mi_linkstate; 1504403Sgd78059 link_state_t mi_lastlinkstate; 1510Sstevel@tonic-gate uint_t mi_promisc; 1520Sstevel@tonic-gate uint_t mi_devpromisc; 1532311Sseb uint8_t mi_addr[MAXMACADDRLEN]; 1542311Sseb uint8_t mi_dstaddr[MAXMACADDRLEN]; 1550Sstevel@tonic-gate mac_multicst_addr_t *mi_mmap; 156*5895Syz147064 1570Sstevel@tonic-gate krwlock_t mi_notify_lock; 1585009Sgd78059 uint32_t mi_notify_bits; 1595009Sgd78059 kmutex_t mi_notify_bits_lock; 1605009Sgd78059 kthread_t *mi_notify_thread; 1610Sstevel@tonic-gate mac_notify_fn_t *mi_mnfp; 1621852Syz147064 kcondvar_t mi_notify_cv; 163*5895Syz147064 1640Sstevel@tonic-gate krwlock_t mi_rx_lock; 1650Sstevel@tonic-gate mac_rx_fn_t *mi_mrfp; 1665084Sjohnlev krwlock_t mi_tx_lock; 1670Sstevel@tonic-gate mac_txloop_fn_t *mi_mtfp; 168*5895Syz147064 1690Sstevel@tonic-gate krwlock_t mi_resource_lock; 1700Sstevel@tonic-gate mac_resource_add_t mi_resource_add; 1710Sstevel@tonic-gate void *mi_resource_add_arg; 172*5895Syz147064 1730Sstevel@tonic-gate kmutex_t mi_activelink_lock; 1740Sstevel@tonic-gate boolean_t mi_activelink; 175*5895Syz147064 1764913Sethindra uint32_t mi_rx_ref; /* #threads in mac_rx() */ 1774913Sethindra uint32_t mi_rx_removed; /* #callbacks marked */ 1784913Sethindra /* for removal */ 1794913Sethindra kmutex_t mi_lock; 1804913Sethindra kcondvar_t mi_rx_cv; 1815084Sjohnlev boolean_t mi_shareable; 1825084Sjohnlev boolean_t mi_vnic_present; 1835084Sjohnlev mac_vnic_tx_t *mi_vnic_tx; 1845084Sjohnlev mac_txinfo_t mi_vnic_txinfo; 1855084Sjohnlev mac_txinfo_t mi_vnic_txloopinfo; 1865084Sjohnlev mac_getcapab_t mi_vnic_getcapab_fn; 1875084Sjohnlev void *mi_vnic_getcapab_arg; 188*5895Syz147064 189*5895Syz147064 boolean_t mi_legacy; 190*5895Syz147064 uint32_t mi_unsup_note; 191*5895Syz147064 uint32_t mi_margin; 192*5895Syz147064 193*5895Syz147064 /* 194*5895Syz147064 * List of margin value requests added by mac clients. This list is 195*5895Syz147064 * sorted: the first one has the greatest value. 196*5895Syz147064 */ 197*5895Syz147064 mac_margin_req_t *mi_mmrp; 1982311Sseb } mac_impl_t; 1992311Sseb 2002311Sseb #define mi_getstat mi_callbacks->mc_getstat 2012311Sseb #define mi_start mi_callbacks->mc_start 2022311Sseb #define mi_stop mi_callbacks->mc_stop 203*5895Syz147064 #define mi_open mi_callbacks->mc_open 204*5895Syz147064 #define mi_close mi_callbacks->mc_close 2052311Sseb #define mi_setpromisc mi_callbacks->mc_setpromisc 2062311Sseb #define mi_multicst mi_callbacks->mc_multicst 2072311Sseb #define mi_unicst mi_callbacks->mc_unicst 2082311Sseb #define mi_resources mi_callbacks->mc_resources 2092311Sseb #define mi_tx mi_callbacks->mc_tx 2102311Sseb #define mi_ioctl mi_callbacks->mc_ioctl 2112311Sseb #define mi_getcapab mi_callbacks->mc_getcapab 2120Sstevel@tonic-gate 2130Sstevel@tonic-gate extern void mac_init(void); 2140Sstevel@tonic-gate extern int mac_fini(void); 2150Sstevel@tonic-gate 2160Sstevel@tonic-gate extern void mac_stat_create(mac_impl_t *); 2170Sstevel@tonic-gate extern void mac_stat_destroy(mac_impl_t *); 2182311Sseb extern uint64_t mac_stat_default(mac_impl_t *, uint_t); 2190Sstevel@tonic-gate 2200Sstevel@tonic-gate #ifdef __cplusplus 2210Sstevel@tonic-gate } 2220Sstevel@tonic-gate #endif 2230Sstevel@tonic-gate 2240Sstevel@tonic-gate #endif /* _SYS_MAC_IMPL_H */ 225