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 /* 224403Sgd78059 * Copyright 2007 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 382311Sseb /* 392412Sseb * Statistics maintained internally by the mac module. 402311Sseb */ 412412Sseb enum mac_mod_stat { 422311Sseb MAC_STAT_LINK_STATE, 432311Sseb MAC_STAT_LINK_UP, 442412Sseb MAC_STAT_PROMISC 452311Sseb }; 462311Sseb 470Sstevel@tonic-gate typedef struct mac_multicst_addr_s mac_multicst_addr_t; 480Sstevel@tonic-gate 490Sstevel@tonic-gate struct mac_multicst_addr_s { 500Sstevel@tonic-gate mac_multicst_addr_t *mma_nextp; 510Sstevel@tonic-gate uint_t mma_ref; 522311Sseb uint8_t mma_addr[MAXMACADDRLEN]; 530Sstevel@tonic-gate }; 540Sstevel@tonic-gate 550Sstevel@tonic-gate typedef struct mac_notify_fn_s mac_notify_fn_t; 560Sstevel@tonic-gate 570Sstevel@tonic-gate struct mac_notify_fn_s { 580Sstevel@tonic-gate mac_notify_fn_t *mnf_nextp; 590Sstevel@tonic-gate mac_notify_t mnf_fn; 600Sstevel@tonic-gate void *mnf_arg; 610Sstevel@tonic-gate }; 620Sstevel@tonic-gate 630Sstevel@tonic-gate typedef struct mac_rx_fn_s mac_rx_fn_t; 640Sstevel@tonic-gate 650Sstevel@tonic-gate struct mac_rx_fn_s { 660Sstevel@tonic-gate mac_rx_fn_t *mrf_nextp; 670Sstevel@tonic-gate mac_rx_t mrf_fn; 680Sstevel@tonic-gate void *mrf_arg; 694913Sethindra boolean_t mrf_inuse; 70*5084Sjohnlev boolean_t mrf_active; 710Sstevel@tonic-gate }; 720Sstevel@tonic-gate 730Sstevel@tonic-gate typedef struct mac_txloop_fn_s mac_txloop_fn_t; 740Sstevel@tonic-gate 750Sstevel@tonic-gate struct mac_txloop_fn_s { 760Sstevel@tonic-gate mac_txloop_fn_t *mtf_nextp; 770Sstevel@tonic-gate mac_txloop_t mtf_fn; 780Sstevel@tonic-gate void *mtf_arg; 790Sstevel@tonic-gate }; 800Sstevel@tonic-gate 812311Sseb typedef struct mactype_s { 822311Sseb const char *mt_ident; 832311Sseb uint32_t mt_ref; 842311Sseb uint_t mt_type; 853147Sxc151355 uint_t mt_nativetype; 862311Sseb size_t mt_addr_length; 872311Sseb uint8_t *mt_brdcst_addr; 882311Sseb mactype_ops_t mt_ops; 892311Sseb mac_stat_info_t *mt_stats; /* array of mac_stat_info_t elements */ 902311Sseb size_t mt_statcount; /* number of elements in mt_stats */ 912311Sseb } mactype_t; 920Sstevel@tonic-gate 93*5084Sjohnlev 94*5084Sjohnlev #define MAC_VNIC_TXINFO_REFHOLD(mvt) { \ 95*5084Sjohnlev mutex_enter(&(mvt)->mv_lock); \ 96*5084Sjohnlev (mvt)->mv_refs++; \ 97*5084Sjohnlev mutex_exit(&(mvt)->mv_lock); \ 98*5084Sjohnlev } 99*5084Sjohnlev 100*5084Sjohnlev #define MAC_VNIC_TXINFO_REFRELE(mvt) { \ 101*5084Sjohnlev mutex_enter(&(mvt)->mv_lock); \ 102*5084Sjohnlev if (--(mvt)->mv_refs == 0 && (mvt)->mv_clearing) { \ 103*5084Sjohnlev (mvt)->mv_clearing = B_FALSE; \ 104*5084Sjohnlev cv_signal(&(mvt)->mv_cv); \ 105*5084Sjohnlev } \ 106*5084Sjohnlev mutex_exit(&(mvt)->mv_lock); \ 107*5084Sjohnlev } 108*5084Sjohnlev 109*5084Sjohnlev typedef struct mac_vnic_tx_s { 110*5084Sjohnlev mac_txinfo_t mv_txinfo; /* provided by VNIC */ 111*5084Sjohnlev uint32_t mv_refs; 112*5084Sjohnlev kmutex_t mv_lock; 113*5084Sjohnlev kcondvar_t mv_cv; 114*5084Sjohnlev boolean_t mv_clearing; 115*5084Sjohnlev } mac_vnic_tx_t; 116*5084Sjohnlev 1172311Sseb /* 1182311Sseb * Each registered MAC is associated with a mac_t structure. 1192311Sseb */ 1202311Sseb typedef struct mac_impl_s { 1212311Sseb char mi_name[LIFNAMSIZ]; 1222311Sseb const char *mi_drvname; 1232311Sseb uint_t mi_instance; 1242311Sseb void *mi_driver; /* Driver private data */ 1252311Sseb mac_info_t mi_info; 1262311Sseb mactype_t *mi_type; 1272311Sseb void *mi_pdata; 1282311Sseb size_t mi_pdata_size; 1292311Sseb mac_callbacks_t *mi_callbacks; 1302311Sseb dev_info_t *mi_dip; 1310Sstevel@tonic-gate uint32_t mi_ref; 1321852Syz147064 boolean_t mi_disabled; 1330Sstevel@tonic-gate krwlock_t mi_state_lock; 1340Sstevel@tonic-gate uint_t mi_active; 1350Sstevel@tonic-gate krwlock_t mi_data_lock; 1362311Sseb link_state_t mi_linkstate; 1374403Sgd78059 link_state_t mi_lastlinkstate; 1380Sstevel@tonic-gate uint_t mi_promisc; 1390Sstevel@tonic-gate uint_t mi_devpromisc; 1402311Sseb uint8_t mi_addr[MAXMACADDRLEN]; 1412311Sseb uint8_t mi_dstaddr[MAXMACADDRLEN]; 1420Sstevel@tonic-gate mac_multicst_addr_t *mi_mmap; 1430Sstevel@tonic-gate krwlock_t mi_notify_lock; 1445009Sgd78059 uint32_t mi_notify_bits; 1455009Sgd78059 kmutex_t mi_notify_bits_lock; 1465009Sgd78059 kthread_t *mi_notify_thread; 1470Sstevel@tonic-gate mac_notify_fn_t *mi_mnfp; 1481852Syz147064 kcondvar_t mi_notify_cv; 1490Sstevel@tonic-gate krwlock_t mi_rx_lock; 1500Sstevel@tonic-gate mac_rx_fn_t *mi_mrfp; 151*5084Sjohnlev krwlock_t mi_tx_lock; 1520Sstevel@tonic-gate mac_txloop_fn_t *mi_mtfp; 1530Sstevel@tonic-gate krwlock_t mi_resource_lock; 1540Sstevel@tonic-gate mac_resource_add_t mi_resource_add; 1550Sstevel@tonic-gate void *mi_resource_add_arg; 1560Sstevel@tonic-gate kstat_t *mi_ksp; 1572311Sseb uint_t mi_kstat_count; 1580Sstevel@tonic-gate kmutex_t mi_activelink_lock; 1590Sstevel@tonic-gate boolean_t mi_activelink; 16056Smeem mac_txinfo_t mi_txinfo; 16156Smeem mac_txinfo_t mi_txloopinfo; 1624913Sethindra uint32_t mi_rx_ref; /* #threads in mac_rx() */ 1634913Sethindra uint32_t mi_rx_removed; /* #callbacks marked */ 1644913Sethindra /* for removal */ 1654913Sethindra kmutex_t mi_lock; 1664913Sethindra kcondvar_t mi_rx_cv; 167*5084Sjohnlev boolean_t mi_shareable; 168*5084Sjohnlev boolean_t mi_vnic_present; 169*5084Sjohnlev mac_vnic_tx_t *mi_vnic_tx; 170*5084Sjohnlev mac_txinfo_t mi_vnic_txinfo; 171*5084Sjohnlev mac_txinfo_t mi_vnic_txloopinfo; 172*5084Sjohnlev mac_getcapab_t mi_vnic_getcapab_fn; 173*5084Sjohnlev void *mi_vnic_getcapab_arg; 1742311Sseb } mac_impl_t; 1752311Sseb 1762311Sseb #define mi_getstat mi_callbacks->mc_getstat 1772311Sseb #define mi_start mi_callbacks->mc_start 1782311Sseb #define mi_stop mi_callbacks->mc_stop 1792311Sseb #define mi_setpromisc mi_callbacks->mc_setpromisc 1802311Sseb #define mi_multicst mi_callbacks->mc_multicst 1812311Sseb #define mi_unicst mi_callbacks->mc_unicst 1822311Sseb #define mi_resources mi_callbacks->mc_resources 1832311Sseb #define mi_tx mi_callbacks->mc_tx 1842311Sseb #define mi_ioctl mi_callbacks->mc_ioctl 1852311Sseb #define mi_getcapab mi_callbacks->mc_getcapab 1860Sstevel@tonic-gate 1870Sstevel@tonic-gate extern void mac_init(void); 1880Sstevel@tonic-gate extern int mac_fini(void); 1890Sstevel@tonic-gate 1900Sstevel@tonic-gate extern void mac_stat_create(mac_impl_t *); 1910Sstevel@tonic-gate extern void mac_stat_destroy(mac_impl_t *); 1922311Sseb extern uint64_t mac_stat_default(mac_impl_t *, uint_t); 1930Sstevel@tonic-gate 1940Sstevel@tonic-gate #ifdef __cplusplus 1950Sstevel@tonic-gate } 1960Sstevel@tonic-gate #endif 1970Sstevel@tonic-gate 1980Sstevel@tonic-gate #endif /* _SYS_MAC_IMPL_H */ 199