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*8833SVenu.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_MAC_IMPL_H 270Sstevel@tonic-gate #define _SYS_MAC_IMPL_H 280Sstevel@tonic-gate 298275SEric Cheng #include <sys/modhash.h> 308275SEric Cheng #include <sys/mac_client.h> 318275SEric Cheng #include <sys/mac_provider.h> 322311Sseb #include <net/if.h> 338275SEric Cheng #include <sys/mac_flow_impl.h> 348275SEric Cheng #include <netinet/ip6.h> 350Sstevel@tonic-gate 360Sstevel@tonic-gate #ifdef __cplusplus 370Sstevel@tonic-gate extern "C" { 380Sstevel@tonic-gate #endif 390Sstevel@tonic-gate 405895Syz147064 typedef struct mac_margin_req_s mac_margin_req_t; 415895Syz147064 425895Syz147064 struct mac_margin_req_s { 435895Syz147064 mac_margin_req_t *mmr_nextp; 445895Syz147064 uint_t mmr_ref; 455895Syz147064 uint32_t mmr_margin; 465895Syz147064 }; 475895Syz147064 488275SEric Cheng /* Generic linked chain type */ 498275SEric Cheng typedef struct mac_chain_s { 508275SEric Cheng struct mac_chain_s *next; 518275SEric Cheng void *item; 528275SEric Cheng } mac_chain_t; 538275SEric Cheng 548275SEric Cheng /* 558275SEric Cheng * Generic mac callback list manipulation structures and macros. The mac_cb_t 568275SEric Cheng * represents a general callback list element embedded in a particular 578275SEric Cheng * data structure such as a mac_notify_cb_t or a mac_promisc_impl_t. 588275SEric Cheng * The mac_cb_info_t represents general information about list walkers. 598275SEric Cheng * Please see the comments above mac_callback_add for more information. 608275SEric Cheng */ 618275SEric Cheng /* mcb_flags */ 628275SEric Cheng #define MCB_CONDEMNED 0x1 /* Logically deleted */ 638275SEric Cheng #define MCB_NOTIFY_CB_T 0x2 648275SEric Cheng #define MCB_TX_NOTIFY_CB_T 0x4 650Sstevel@tonic-gate 668275SEric Cheng typedef struct mac_cb_s { 678275SEric Cheng struct mac_cb_s *mcb_nextp; /* Linked list of callbacks */ 688275SEric Cheng void *mcb_objp; /* Ptr to enclosing object */ 698275SEric Cheng size_t mcb_objsize; /* Sizeof the enclosing obj */ 708275SEric Cheng uint_t mcb_flags; 718275SEric Cheng } mac_cb_t; 720Sstevel@tonic-gate 738275SEric Cheng typedef struct mac_cb_info_s { 748275SEric Cheng kmutex_t *mcbi_lockp; 758275SEric Cheng kcondvar_t mcbi_cv; 768275SEric Cheng uint_t mcbi_del_cnt; /* Deleted callback cnt */ 778275SEric Cheng uint_t mcbi_walker_cnt; /* List walker count */ 788275SEric Cheng } mac_cb_info_t; 798275SEric Cheng 808275SEric Cheng typedef struct mac_notify_cb_s { 818275SEric Cheng mac_cb_t mncb_link; /* Linked list of callbacks */ 828275SEric Cheng mac_notify_t mncb_fn; /* callback function */ 838275SEric Cheng void *mncb_arg; /* callback argument */ 848275SEric Cheng struct mac_impl_s *mncb_mip; 858275SEric Cheng } mac_notify_cb_t; 860Sstevel@tonic-gate 878275SEric Cheng /* 888275SEric Cheng * mac_callback_add(listinfo, listhead, listelement) 898275SEric Cheng * mac_callback_remove(listinfo, listhead, listelement) 908275SEric Cheng */ 918275SEric Cheng typedef boolean_t (*mcb_func_t)(mac_cb_info_t *, mac_cb_t **, mac_cb_t *); 928275SEric Cheng 938275SEric Cheng #define MAC_CALLBACK_WALKER_INC(mcbi) { \ 948275SEric Cheng mutex_enter((mcbi)->mcbi_lockp); \ 958275SEric Cheng (mcbi)->mcbi_walker_cnt++; \ 968275SEric Cheng mutex_exit((mcbi)->mcbi_lockp); \ 978275SEric Cheng } 988275SEric Cheng 998275SEric Cheng #define MAC_CALLBACK_WALKER_INC_HELD(mcbi) (mcbi)->mcbi_walker_cnt++; 1000Sstevel@tonic-gate 1018275SEric Cheng #define MAC_CALLBACK_WALKER_DCR(mcbi, headp) { \ 1028275SEric Cheng mac_cb_t *rmlist; \ 1038275SEric Cheng \ 1048275SEric Cheng mutex_enter((mcbi)->mcbi_lockp); \ 1058275SEric Cheng if (--(mcbi)->mcbi_walker_cnt == 0 && (mcbi)->mcbi_del_cnt != 0) { \ 1068275SEric Cheng rmlist = mac_callback_walker_cleanup((mcbi), headp); \ 1078275SEric Cheng mac_callback_free(rmlist); \ 1088275SEric Cheng cv_broadcast(&(mcbi)->mcbi_cv); \ 1098275SEric Cheng } \ 1108275SEric Cheng mutex_exit((mcbi)->mcbi_lockp); \ 1118275SEric Cheng } 1120Sstevel@tonic-gate 1138275SEric Cheng #define MAC_PROMISC_WALKER_INC(mip) \ 1148275SEric Cheng MAC_CALLBACK_WALKER_INC(&(mip)->mi_promisc_cb_info) 1158275SEric Cheng 1168275SEric Cheng #define MAC_PROMISC_WALKER_DCR(mip) { \ 1178275SEric Cheng mac_cb_info_t *mcbi; \ 1188275SEric Cheng \ 1198275SEric Cheng mcbi = &(mip)->mi_promisc_cb_info; \ 1208275SEric Cheng mutex_enter(mcbi->mcbi_lockp); \ 1218275SEric Cheng if (--mcbi->mcbi_walker_cnt == 0 && mcbi->mcbi_del_cnt != 0) { \ 1228275SEric Cheng i_mac_promisc_walker_cleanup(mip); \ 1238275SEric Cheng cv_broadcast(&mcbi->mcbi_cv); \ 1248275SEric Cheng } \ 1258275SEric Cheng mutex_exit(mcbi->mcbi_lockp); \ 1268275SEric Cheng } 1270Sstevel@tonic-gate 1282311Sseb typedef struct mactype_s { 1292311Sseb const char *mt_ident; 1302311Sseb uint32_t mt_ref; 1312311Sseb uint_t mt_type; 1323147Sxc151355 uint_t mt_nativetype; 1332311Sseb size_t mt_addr_length; 1342311Sseb uint8_t *mt_brdcst_addr; 1352311Sseb mactype_ops_t mt_ops; 1362311Sseb mac_stat_info_t *mt_stats; /* array of mac_stat_info_t elements */ 1372311Sseb size_t mt_statcount; /* number of elements in mt_stats */ 1386512Ssowmini mac_ndd_mapping_t *mt_mapping; 1396512Ssowmini size_t mt_mappingcount; 1402311Sseb } mactype_t; 1410Sstevel@tonic-gate 1428275SEric Cheng /* 1438275SEric Cheng * Multiple rings implementation. 1448275SEric Cheng */ 1458275SEric Cheng typedef enum { 1468275SEric Cheng MAC_GROUP_STATE_UNINIT = 0, /* initial state of data structure */ 1478275SEric Cheng MAC_GROUP_STATE_REGISTERED, /* hooked with h/w group */ 1488275SEric Cheng MAC_GROUP_STATE_RESERVED, /* group is reserved and opened */ 1498275SEric Cheng MAC_GROUP_STATE_SHARED /* default group shared among */ 1508275SEric Cheng /* multiple mac clients */ 1518275SEric Cheng } mac_group_state_t; 1525084Sjohnlev 1538275SEric Cheng typedef struct mac_ring_s mac_ring_t; 1548275SEric Cheng typedef struct mac_group_s mac_group_t; 1558275SEric Cheng 1568275SEric Cheng /* 1578275SEric Cheng * Ring data structure for ring control and management. 1588275SEric Cheng */ 1598275SEric Cheng typedef enum { 1608275SEric Cheng MR_FREE, /* Available for assignment to flows */ 1618275SEric Cheng MR_NEWLY_ADDED, /* Just assigned to another group */ 1628275SEric Cheng MR_INUSE /* Assigned to an SRS */ 1638275SEric Cheng } mac_ring_state_t; 1648275SEric Cheng 1658275SEric Cheng /* mr_flag values */ 1668275SEric Cheng #define MR_INCIPIENT 0x1 1678275SEric Cheng #define MR_CONDEMNED 0x2 1688275SEric Cheng #define MR_QUIESCE 0x4 1698275SEric Cheng 1708275SEric Cheng struct mac_ring_s { 1718275SEric Cheng int mr_index; /* index in the original list */ 1728275SEric Cheng mac_ring_type_t mr_type; /* ring type */ 1738275SEric Cheng mac_ring_t *mr_next; /* next ring in the chain */ 1748275SEric Cheng mac_group_handle_t mr_gh; /* reference to group */ 1758275SEric Cheng 1768275SEric Cheng mac_classify_type_t mr_classify_type; /* HW vs SW */ 1778275SEric Cheng struct mac_soft_ring_set_s *mr_srs; /* associated SRS */ 1788275SEric Cheng uint_t mr_refcnt; /* Ring references */ 1798275SEric Cheng /* ring generation no. to guard against drivers using stale rings */ 1808275SEric Cheng uint64_t mr_gen_num; 1818275SEric Cheng 1828275SEric Cheng kmutex_t mr_lock; 1838275SEric Cheng kcondvar_t mr_cv; /* mr_lock */ 1848275SEric Cheng mac_ring_state_t mr_state; /* mr_lock */ 1858275SEric Cheng uint_t mr_flag; /* mr_lock */ 1868275SEric Cheng 1878275SEric Cheng mac_ring_info_t mr_info; /* driver supplied info */ 1888275SEric Cheng }; 1898275SEric Cheng #define mr_driver mr_info.mri_driver 1908275SEric Cheng #define mr_start mr_info.mri_start 1918275SEric Cheng #define mr_stop mr_info.mri_stop 1928275SEric Cheng 1938275SEric Cheng #define MAC_RING_MARK(mr, flag) \ 1948275SEric Cheng (mr)->mr_flag |= flag; 1958275SEric Cheng 1968275SEric Cheng #define MAC_RING_UNMARK(mr, flag) \ 1978275SEric Cheng (mr)->mr_flag &= ~flag; 1988275SEric Cheng 1998275SEric Cheng /* 2008275SEric Cheng * Reference hold and release on mac_ring_t 'mr' 2018275SEric Cheng */ 2028275SEric Cheng #define MR_REFHOLD_LOCKED(mr) { \ 2038275SEric Cheng ASSERT(MUTEX_HELD(&mr->mr_lock)); \ 2048275SEric Cheng (mr)->mr_refcnt++; \ 2055084Sjohnlev } 2065084Sjohnlev 2078275SEric Cheng #define MR_REFRELE(mr) { \ 2088275SEric Cheng mutex_enter(&(mr)->mr_lock); \ 2098275SEric Cheng ASSERT((mr)->mr_refcnt != 0); \ 2108275SEric Cheng (mr)->mr_refcnt--; \ 2118275SEric Cheng if ((mr)->mr_refcnt == 0 && \ 2128275SEric Cheng ((mr)->mr_flag & (MR_CONDEMNED | MR_QUIESCE))) \ 2138275SEric Cheng cv_signal(&(mr)->mr_cv); \ 2148275SEric Cheng mutex_exit(&(mr)->mr_lock); \ 2155084Sjohnlev } 2165084Sjohnlev 2178275SEric Cheng /* 2188275SEric Cheng * Per mac client flow information associated with a RX group. 2198275SEric Cheng * The entire structure is SL protected. 2208275SEric Cheng */ 2218275SEric Cheng typedef struct mac_grp_client { 2228275SEric Cheng struct mac_grp_client *mgc_next; 2238275SEric Cheng struct mac_client_impl_s *mgc_client; 2248275SEric Cheng } mac_grp_client_t; 2255084Sjohnlev 2268275SEric Cheng #define MAC_RX_GROUP_NO_CLIENT(g) ((g)->mrg_clients == NULL) 2278275SEric Cheng 2288275SEric Cheng #define MAC_RX_GROUP_ONLY_CLIENT(g) \ 2298275SEric Cheng ((((g)->mrg_clients != NULL) && \ 2308275SEric Cheng ((g)->mrg_clients->mgc_next == NULL)) ? \ 2318275SEric Cheng (g)->mrg_clients->mgc_client : NULL) 2326512Ssowmini 2332311Sseb /* 2348275SEric Cheng * Common ring group data structure for ring control and management. 2358275SEric Cheng * The entire structure is SL protected 2362311Sseb */ 2378275SEric Cheng struct mac_group_s { 2388275SEric Cheng int mrg_index; /* index in the list */ 2398275SEric Cheng mac_ring_type_t mrg_type; /* ring type */ 2408275SEric Cheng mac_group_state_t mrg_state; /* state of the group */ 2418275SEric Cheng mac_group_t *mrg_next; /* next ring in the chain */ 2428275SEric Cheng mac_handle_t mrg_mh; /* reference to MAC */ 2438275SEric Cheng mac_ring_t *mrg_rings; /* grouped rings */ 2448275SEric Cheng uint_t mrg_cur_count; /* actual size of group */ 2458275SEric Cheng 2468275SEric Cheng mac_grp_client_t *mrg_clients; /* clients list */ 2478275SEric Cheng 2488275SEric Cheng struct mac_client_impl_s *mrg_tx_client; /* TX client pointer */ 2498275SEric Cheng mac_group_info_t mrg_info; /* driver supplied info */ 2508275SEric Cheng }; 2518275SEric Cheng 2528275SEric Cheng #define mrg_driver mrg_info.mgi_driver 2538275SEric Cheng #define mrg_start mrg_info.mgi_start 2548275SEric Cheng #define mrg_stop mrg_info.mgi_stop 2558275SEric Cheng 2568275SEric Cheng #define GROUP_INTR_HANDLE(g) (g)->mrg_info.mgi_intr.mi_handle 2578275SEric Cheng #define GROUP_INTR_ENABLE_FUNC(g) (g)->mrg_info.mgi_intr.mi_enable 2588275SEric Cheng #define GROUP_INTR_DISABLE_FUNC(g) (g)->mrg_info.mgi_intr.mi_disable 2598275SEric Cheng 2608275SEric Cheng #define MAC_DEFAULT_GROUP(mh) (((mac_impl_t *)mh)->mi_rx_groups) 2618275SEric Cheng 2628275SEric Cheng #define MAC_RING_TX_DEFAULT(mip, mp) \ 2638275SEric Cheng ((mip->mi_default_tx_ring == NULL) ? \ 2648275SEric Cheng mip->mi_tx(mip->mi_driver, mp) : \ 2658275SEric Cheng mac_ring_tx(mip->mi_default_tx_ring, mp)) 2665895Syz147064 2678275SEric Cheng #define MAC_TX(mip, ring, mp, mcip) { \ 2688275SEric Cheng /* \ 2698275SEric Cheng * If the MAC client has a bound Hybrid I/O share, \ 2708275SEric Cheng * send the packet through the default tx ring, since \ 2718275SEric Cheng * the tx rings of this client are now mapped in the \ 2728275SEric Cheng * guest domain and not accessible from this domain. \ 2738275SEric Cheng */ \ 2748400SNicolas.Droux@Sun.COM if ((mcip->mci_state_flags & MCIS_SHARE_BOUND) != 0 || \ 2758400SNicolas.Droux@Sun.COM (ring == NULL)) \ 2768275SEric Cheng mp = MAC_RING_TX_DEFAULT(mip, mp); \ 2778275SEric Cheng else \ 2788275SEric Cheng mp = mac_ring_tx(ring, mp); \ 2798275SEric Cheng } 2808275SEric Cheng 2818275SEric Cheng /* mci_tx_flag */ 2828275SEric Cheng #define MCI_TX_QUIESCE 0x1 2838275SEric Cheng 2848275SEric Cheng typedef struct mac_factory_addr_s { 2858275SEric Cheng boolean_t mfa_in_use; 2868275SEric Cheng uint8_t mfa_addr[MAXMACADDRLEN]; 2878275SEric Cheng struct mac_client_impl_s *mfa_client; 2888275SEric Cheng } mac_factory_addr_t; 2895895Syz147064 2908275SEric Cheng typedef struct mac_mcast_addrs_s { 2918275SEric Cheng struct mac_mcast_addrs_s *mma_next; 2928275SEric Cheng uint8_t mma_addr[MAXMACADDRLEN]; 2938275SEric Cheng int mma_ref; 2948275SEric Cheng } mac_mcast_addrs_t; 2958275SEric Cheng 2968275SEric Cheng typedef enum { 2978275SEric Cheng MAC_ADDRESS_TYPE_UNICAST_CLASSIFIED = 1, /* hardware steering */ 2988275SEric Cheng MAC_ADDRESS_TYPE_UNICAST_PROMISC /* promiscuous mode */ 2998275SEric Cheng } mac_address_type_t; 3008275SEric Cheng 3018275SEric Cheng typedef struct mac_impl_s mac_impl_t; 3028275SEric Cheng 3038275SEric Cheng typedef struct mac_address_s { 3048275SEric Cheng mac_address_type_t ma_type; /* address type */ 3058275SEric Cheng int ma_nusers; /* number of users */ 3068275SEric Cheng /* of that address */ 3078275SEric Cheng struct mac_address_s *ma_next; /* next address */ 3088275SEric Cheng uint8_t ma_addr[MAXMACADDRLEN]; /* address value */ 3098275SEric Cheng size_t ma_len; /* address length */ 3108275SEric Cheng mac_group_t *ma_group; /* asscociated group */ 3118275SEric Cheng mac_impl_t *ma_mip; /* MAC handle */ 3128275SEric Cheng } mac_address_t; 3138275SEric Cheng 3148275SEric Cheng extern krwlock_t i_mac_impl_lock; 3158275SEric Cheng extern mod_hash_t *i_mac_impl_hash; 3168275SEric Cheng extern kmem_cache_t *i_mac_impl_cachep; 3178275SEric Cheng extern uint_t i_mac_impl_count; 3185895Syz147064 3198275SEric Cheng /* 3208275SEric Cheng * Each registered MAC is associated with a mac_impl_t structure. The 3218275SEric Cheng * structure represents the undelying hardware, in terms of definition, 3228275SEric Cheng * resources (transmit, receive rings etc.), callback functions etc. It 3238275SEric Cheng * also holds the table of MAC clients that are configured on the device. 3248275SEric Cheng * The table is used for classifying incoming packets in software. 3258275SEric Cheng * 3268275SEric Cheng * The protection scheme uses 2 elements, a coarse serialization mechanism 3278275SEric Cheng * called perimeter and a finer traditional lock based scheme. More details 3288275SEric Cheng * can be found in the big block comment in mac.c. 3298275SEric Cheng * 3308275SEric Cheng * The protection scheme for each member of the mac_impl_t is described below. 3318275SEric Cheng * 3328275SEric Cheng * Write Once Only (WO): Typically these don't change for the lifetime of the 3338275SEric Cheng * data structure. For example something in mac_impl_t that stays the same 3348275SEric Cheng * from mac_register to mac_unregister, or something in a mac_client_impl_t 3358275SEric Cheng * that stays the same from mac_client_open to mac_client_close. 3368275SEric Cheng * 3378275SEric Cheng * Serializer (SL): Protected by the Serializer. All SLOP operations on a 3388275SEric Cheng * mac endpoint go through the serializer. MTOPs don't care about reading 3398275SEric Cheng * these fields atomically. 3408275SEric Cheng * 3418275SEric Cheng * Lock: Traditional mutex/rw lock. Modify operations still go through the 3428275SEric Cheng * mac serializer, the lock helps synchronize readers with writers. 3438275SEric Cheng */ 3448275SEric Cheng struct mac_impl_s { 3458275SEric Cheng krwlock_t mi_rw_lock; 3468275SEric Cheng char mi_name[LIFNAMSIZ]; /* WO */ 3478275SEric Cheng uint32_t mi_state_flags; 3488275SEric Cheng void *mi_driver; /* Driver private, WO */ 3498275SEric Cheng mac_info_t mi_info; /* WO */ 3508275SEric Cheng mactype_t *mi_type; /* WO */ 3518275SEric Cheng void *mi_pdata; /* WO */ 3528275SEric Cheng size_t mi_pdata_size; /* WO */ 3538275SEric Cheng mac_callbacks_t *mi_callbacks; /* WO */ 3548275SEric Cheng dev_info_t *mi_dip; /* WO */ 3558275SEric Cheng uint32_t mi_ref; /* i_mac_impl_lock */ 3568275SEric Cheng uint_t mi_active; /* SL */ 3578275SEric Cheng link_state_t mi_linkstate; /* none */ 3588275SEric Cheng link_state_t mi_lastlinkstate; /* none */ 3598275SEric Cheng uint_t mi_promisc; /* SL */ 3608275SEric Cheng uint_t mi_devpromisc; /* SL */ 3618275SEric Cheng kmutex_t mi_lock; 3628275SEric Cheng uint8_t mi_addr[MAXMACADDRLEN]; /* mi_rw_lock */ 3638275SEric Cheng uint8_t mi_dstaddr[MAXMACADDRLEN]; /* mi_rw_lock */ 3645895Syz147064 3658275SEric Cheng /* 3668275SEric Cheng * The mac perimeter. All client initiated create/modify operations 3678275SEric Cheng * on a mac end point go through this. 3688275SEric Cheng */ 3698275SEric Cheng kmutex_t mi_perim_lock; 3708275SEric Cheng kthread_t *mi_perim_owner; /* mi_perim_lock */ 3718275SEric Cheng uint_t mi_perim_ocnt; /* mi_perim_lock */ 3728275SEric Cheng kcondvar_t mi_perim_cv; /* mi_perim_lock */ 3735895Syz147064 3748275SEric Cheng /* mac notification callbacks */ 3758275SEric Cheng kmutex_t mi_notify_lock; 3768275SEric Cheng mac_cb_info_t mi_notify_cb_info; /* mi_notify_lock */ 3778275SEric Cheng mac_cb_t *mi_notify_cb_list; /* mi_notify_lock */ 3788275SEric Cheng kthread_t *mi_notify_thread; /* mi_notify_lock */ 3798275SEric Cheng uint_t mi_notify_bits; /* mi_notify_lock */ 3808275SEric Cheng 3818275SEric Cheng uint32_t mi_v12n_level; /* Virt'ion readiness */ 3828275SEric Cheng 3838275SEric Cheng /* 3848275SEric Cheng * RX groups, ring capability 3858275SEric Cheng * Fields of this block are SL protected. 3868275SEric Cheng */ 3878275SEric Cheng mac_group_type_t mi_rx_group_type; /* grouping type */ 3888275SEric Cheng uint_t mi_rx_group_count; 3898275SEric Cheng mac_group_t *mi_rx_groups; 3905895Syz147064 3918275SEric Cheng mac_capab_rings_t mi_rx_rings_cap; 3928275SEric Cheng 3938275SEric Cheng /* 3948275SEric Cheng * TX groups and ring capability, SL Protected. 3958275SEric Cheng */ 3968275SEric Cheng mac_group_type_t mi_tx_group_type; /* grouping type */ 3978275SEric Cheng uint_t mi_tx_group_count; 3988275SEric Cheng uint_t mi_tx_group_free; 3998275SEric Cheng mac_group_t *mi_tx_groups; 4008275SEric Cheng 4018275SEric Cheng mac_capab_rings_t mi_tx_rings_cap; 4028275SEric Cheng 4038275SEric Cheng mac_ring_handle_t mi_default_tx_ring; 4045895Syz147064 4058275SEric Cheng /* 4068275SEric Cheng * MAC address list. SL protected. 4078275SEric Cheng */ 4088275SEric Cheng mac_address_t *mi_addresses; 4098275SEric Cheng 4108275SEric Cheng /* 4118275SEric Cheng * This MAC's table of sub-flows 4128275SEric Cheng */ 4138275SEric Cheng flow_tab_t *mi_flow_tab; /* WO */ 4148275SEric Cheng 4158275SEric Cheng kstat_t *mi_ksp; /* WO */ 4168275SEric Cheng uint_t mi_kstat_count; /* WO */ 4178275SEric Cheng uint_t mi_nactiveclients; /* SL */ 4188275SEric Cheng 4198275SEric Cheng /* for broadcast and multicast support */ 4208275SEric Cheng struct mac_mcast_addrs_s *mi_mcast_addrs; /* mi_rw_lock */ 4218275SEric Cheng struct mac_bcast_grp_s *mi_bcast_grp; /* mi_rw_lock */ 4228275SEric Cheng uint_t mi_bcast_ngrps; /* mi_rw_lock */ 4235895Syz147064 4248275SEric Cheng /* list of MAC clients which opened this MAC */ 4258275SEric Cheng struct mac_client_impl_s *mi_clients_list; /* mi_rw_lock */ 4268275SEric Cheng uint_t mi_nclients; /* mi_rw_lock */ 427*8833SVenu.Iyer@Sun.COM struct mac_client_impl_s *mi_single_active_client; /* mi_rw_lock */ 4288275SEric Cheng 4298275SEric Cheng uint32_t mi_margin; /* mi_rw_lock */ 4308275SEric Cheng uint_t mi_sdu_min; /* mi_rw_lock */ 4318275SEric Cheng uint_t mi_sdu_max; /* mi_rw_lock */ 4328275SEric Cheng 4338275SEric Cheng /* 4348275SEric Cheng * Cache of factory MAC addresses provided by the driver. If 4358275SEric Cheng * the driver doesn't provide multiple factory MAC addresses, 4368275SEric Cheng * the mi_factory_addr is set to NULL, and mi_factory_addr_num 4378275SEric Cheng * is set to zero. 4388275SEric Cheng */ 4398275SEric Cheng mac_factory_addr_t *mi_factory_addr; /* mi_rw_lock */ 4408275SEric Cheng uint_t mi_factory_addr_num; /* mi_rw_lock */ 4415895Syz147064 4428275SEric Cheng /* for promiscuous mode support */ 4438275SEric Cheng kmutex_t mi_promisc_lock; 4448275SEric Cheng mac_cb_t *mi_promisc_list; /* mi_promisc_lock */ 4458275SEric Cheng mac_cb_info_t mi_promisc_cb_info; /* mi_promisc_lock */ 4468275SEric Cheng 4478275SEric Cheng /* cache of rings over this mac_impl */ 4488275SEric Cheng kmutex_t mi_ring_lock; 4498275SEric Cheng mac_ring_t *mi_ring_freelist; /* mi_ring_lock */ 4505895Syz147064 4515895Syz147064 /* 4528275SEric Cheng * These are used for caching the properties, if any, for the 4538275SEric Cheng * primary MAC client. If the MAC client is not yet in place 4548275SEric Cheng * when the properties are set then we cache them here to be 4558275SEric Cheng * applied to the MAC client when it is created. 4568275SEric Cheng */ 4578275SEric Cheng mac_resource_props_t mi_resource_props; /* SL */ 4588275SEric Cheng 4598275SEric Cheng minor_t mi_minor; /* WO */ 4608275SEric Cheng dev_t mi_phy_dev; /* WO */ 4618275SEric Cheng uint32_t mi_oref; /* SL */ 4628275SEric Cheng uint32_t mi_unsup_note; /* WO */ 4638275SEric Cheng /* 4645895Syz147064 * List of margin value requests added by mac clients. This list is 4655895Syz147064 * sorted: the first one has the greatest value. 4665895Syz147064 */ 4675895Syz147064 mac_margin_req_t *mi_mmrp; 4686512Ssowmini mac_priv_prop_t *mi_priv_prop; 4696512Ssowmini uint_t mi_priv_prop_count; 4708275SEric Cheng 4718275SEric Cheng /* 4728275SEric Cheng * Hybrid I/O related definitions. 4738275SEric Cheng */ 4748275SEric Cheng mac_capab_share_t mi_share_capab; 4758275SEric Cheng 4768275SEric Cheng /* This should be the last block in this structure */ 4778275SEric Cheng #ifdef DEBUG 4788275SEric Cheng #define MAC_PERIM_STACK_DEPTH 15 4798275SEric Cheng int mi_perim_stack_depth; 4808275SEric Cheng pc_t mi_perim_stack[MAC_PERIM_STACK_DEPTH]; 4818275SEric Cheng #endif 4828275SEric Cheng }; 4838275SEric Cheng 4848275SEric Cheng /* for mi_state_flags */ 4858275SEric Cheng #define MIS_DISABLED 0x0001 4868275SEric Cheng #define MIS_IS_VNIC 0x0002 4878275SEric Cheng #define MIS_IS_AGGR 0x0004 4888275SEric Cheng #define MIS_NOTIFY_DONE 0x0008 4898275SEric Cheng #define MIS_EXCLUSIVE 0x0010 4908275SEric Cheng #define MIS_EXCLUSIVE_HELD 0x0020 4918275SEric Cheng #define MIS_LEGACY 0x0040 4922311Sseb 4932311Sseb #define mi_getstat mi_callbacks->mc_getstat 4942311Sseb #define mi_start mi_callbacks->mc_start 4952311Sseb #define mi_stop mi_callbacks->mc_stop 4965895Syz147064 #define mi_open mi_callbacks->mc_open 4975895Syz147064 #define mi_close mi_callbacks->mc_close 4982311Sseb #define mi_setpromisc mi_callbacks->mc_setpromisc 4992311Sseb #define mi_multicst mi_callbacks->mc_multicst 5002311Sseb #define mi_unicst mi_callbacks->mc_unicst 5012311Sseb #define mi_tx mi_callbacks->mc_tx 5022311Sseb #define mi_ioctl mi_callbacks->mc_ioctl 5032311Sseb #define mi_getcapab mi_callbacks->mc_getcapab 5040Sstevel@tonic-gate 5058275SEric Cheng typedef struct mac_notify_task_arg { 5068275SEric Cheng mac_impl_t *mnt_mip; 5078275SEric Cheng mac_notify_type_t mnt_type; 5088275SEric Cheng mac_ring_t *mnt_ring; 5098275SEric Cheng } mac_notify_task_arg_t; 5108275SEric Cheng 5118275SEric Cheng typedef enum { 5128275SEric Cheng MAC_RX_NO_RESERVE, 5138275SEric Cheng MAC_RX_RESERVE_DEFAULT, 5148275SEric Cheng MAC_RX_RESERVE_NONDEFAULT 5158275SEric Cheng } mac_rx_group_reserve_type_t; 5168275SEric Cheng 5178275SEric Cheng /* 5188275SEric Cheng * XXX All MAC_DBG_PRTs must be replaced with call to dtrace probes. For now 5198275SEric Cheng * it may be easier to have these printfs for easier debugging 5208275SEric Cheng */ 5218275SEric Cheng #ifdef DEBUG 5228275SEric Cheng extern int mac_dbg; 5238275SEric Cheng #define MAC_DBG_PRT(a) if (mac_dbg > 0) {(void) printf a; } 5248275SEric Cheng #else 5258275SEric Cheng #define MAC_DBG_PRT(a) 5268275SEric Cheng #endif 5278275SEric Cheng 5288275SEric Cheng /* 5298275SEric Cheng * The mac_perim_handle_t is an opaque type that encodes the 'mip' pointer 5308275SEric Cheng * and whether internally a mac_open was done when acquiring the perimeter. 5318275SEric Cheng */ 5328275SEric Cheng #define MAC_ENCODE_MPH(mph, mh, need_close) \ 5338275SEric Cheng (mph) = (mac_perim_handle_t)((uintptr_t)(mh) | need_close) 5348275SEric Cheng 5358275SEric Cheng #define MAC_DECODE_MPH(mph, mip, need_close) { \ 5368275SEric Cheng mip = (mac_impl_t *)(((uintptr_t)mph) & ~0x1); \ 5378275SEric Cheng (need_close) = ((uintptr_t)mph & 0x1); \ 5388275SEric Cheng } 5398275SEric Cheng 5408275SEric Cheng typedef struct mac_client_impl_s mac_client_impl_t; 5418275SEric Cheng 5420Sstevel@tonic-gate extern void mac_init(void); 5430Sstevel@tonic-gate extern int mac_fini(void); 5440Sstevel@tonic-gate 5450Sstevel@tonic-gate extern void mac_stat_create(mac_impl_t *); 5460Sstevel@tonic-gate extern void mac_stat_destroy(mac_impl_t *); 5472311Sseb extern uint64_t mac_stat_default(mac_impl_t *, uint_t); 5488275SEric Cheng extern void mac_ndd_ioctl(mac_impl_t *, queue_t *, mblk_t *); 5498275SEric Cheng extern void mac_create_soft_ring_kstats(mac_impl_t *, int32_t); 5508275SEric Cheng extern boolean_t mac_ip_hdr_length_v6(mblk_t *, ip6_t *, uint16_t *, 5518275SEric Cheng uint8_t *); 5520Sstevel@tonic-gate 5538275SEric Cheng extern mblk_t *mac_copymsgchain_cksum(mblk_t *); 5548275SEric Cheng extern mblk_t *mac_fix_cksum(mblk_t *); 5558275SEric Cheng extern void mac_packet_print(mac_handle_t, mblk_t *); 5568275SEric Cheng extern void mac_rx_deliver(void *, mac_resource_handle_t, mblk_t *, 5578275SEric Cheng mac_header_info_t *); 5588275SEric Cheng extern void mac_tx_notify(mac_impl_t *); 5598275SEric Cheng 5608275SEric Cheng extern boolean_t mac_callback_find(mac_cb_info_t *, mac_cb_t **, mac_cb_t *); 5618275SEric Cheng extern void mac_callback_add(mac_cb_info_t *, mac_cb_t **, mac_cb_t *); 5628275SEric Cheng extern boolean_t mac_callback_remove(mac_cb_info_t *, mac_cb_t **, mac_cb_t *); 5638275SEric Cheng extern void mac_callback_remove_wait(mac_cb_info_t *); 5648275SEric Cheng extern void mac_callback_free(mac_cb_t *); 5658275SEric Cheng extern mac_cb_t *mac_callback_walker_cleanup(mac_cb_info_t *, mac_cb_t **); 5668275SEric Cheng 5678275SEric Cheng /* in mac_bcast.c */ 5688275SEric Cheng extern void mac_bcast_init(void); 5698275SEric Cheng extern void mac_bcast_fini(void); 5708275SEric Cheng extern mac_impl_t *mac_bcast_grp_mip(void *); 5718275SEric Cheng extern int mac_bcast_add(mac_client_impl_t *, const uint8_t *, uint16_t, 5728275SEric Cheng mac_addrtype_t); 5738275SEric Cheng extern void mac_bcast_delete(mac_client_impl_t *, const uint8_t *, uint16_t); 5748275SEric Cheng extern void mac_bcast_send(void *, void *, mblk_t *, boolean_t); 5758275SEric Cheng extern void mac_bcast_grp_free(void *); 5768275SEric Cheng extern void mac_bcast_refresh(mac_impl_t *, mac_multicst_t, void *, 5778275SEric Cheng boolean_t); 5788275SEric Cheng extern void mac_client_bcast_refresh(mac_client_impl_t *, mac_multicst_t, 5798275SEric Cheng void *, boolean_t); 5808275SEric Cheng 5818275SEric Cheng /* 5828275SEric Cheng * Grouping functions are used internally by MAC layer. 5838275SEric Cheng */ 5848275SEric Cheng extern int mac_group_addmac(mac_group_t *, const uint8_t *); 5858275SEric Cheng extern int mac_group_remmac(mac_group_t *, const uint8_t *); 5868275SEric Cheng extern int mac_rx_group_add_flow(mac_client_impl_t *, flow_entry_t *, 5878275SEric Cheng mac_group_t *); 5888275SEric Cheng extern mblk_t *mac_ring_tx(mac_ring_handle_t, mblk_t *); 5898275SEric Cheng extern mac_ring_t *mac_reserve_tx_ring(mac_impl_t *, mac_ring_t *); 5908275SEric Cheng extern void mac_release_tx_ring(mac_ring_handle_t); 5918275SEric Cheng extern mac_group_t *mac_reserve_tx_group(mac_impl_t *, mac_share_handle_t); 5928275SEric Cheng extern void mac_release_tx_group(mac_impl_t *, mac_group_t *); 5938275SEric Cheng 5948275SEric Cheng /* 5958275SEric Cheng * MAC address functions are used internally by MAC layer. 5968275SEric Cheng */ 5978275SEric Cheng extern mac_address_t *mac_find_macaddr(mac_impl_t *, uint8_t *); 5988275SEric Cheng extern boolean_t mac_check_macaddr_shared(mac_address_t *); 5998275SEric Cheng extern int mac_update_macaddr(mac_address_t *, uint8_t *); 6008275SEric Cheng extern void mac_freshen_macaddr(mac_address_t *, uint8_t *); 6018275SEric Cheng extern void mac_retrieve_macaddr(mac_address_t *, uint8_t *); 6028275SEric Cheng extern void mac_init_macaddr(mac_impl_t *); 6038275SEric Cheng extern void mac_fini_macaddr(mac_impl_t *); 6048275SEric Cheng 6058275SEric Cheng /* 6068275SEric Cheng * Flow construction/destruction routines. 6078275SEric Cheng * Not meant to be used by mac clients. 6088275SEric Cheng */ 6098275SEric Cheng extern int mac_link_flow_init(mac_client_handle_t, flow_entry_t *); 6108275SEric Cheng extern void mac_link_flow_clean(mac_client_handle_t, flow_entry_t *); 6118275SEric Cheng 6128275SEric Cheng /* 6138400SNicolas.Droux@Sun.COM * Fanout update routines called when the link speed of the NIC changes 6148400SNicolas.Droux@Sun.COM * or when a MAC client's share is unbound. 6158275SEric Cheng */ 6168400SNicolas.Droux@Sun.COM extern void mac_fanout_recompute_client(mac_client_impl_t *); 6178275SEric Cheng extern void mac_fanout_recompute(mac_impl_t *); 6188275SEric Cheng 6198275SEric Cheng /* 6208275SEric Cheng * The following functions are used internally by the MAC layer to 6218275SEric Cheng * add/remove/update flows associated with a mac_impl_t. They should 6228275SEric Cheng * never be used directly by MAC clients. 6238275SEric Cheng */ 6248275SEric Cheng extern int mac_datapath_setup(mac_client_impl_t *, flow_entry_t *, uint32_t); 6258275SEric Cheng extern void mac_datapath_teardown(mac_client_impl_t *, flow_entry_t *, 6268275SEric Cheng uint32_t); 6278275SEric Cheng extern void mac_srs_group_setup(mac_client_impl_t *, flow_entry_t *, 6288275SEric Cheng mac_group_t *, uint32_t); 6298275SEric Cheng extern void mac_srs_group_teardown(mac_client_impl_t *, flow_entry_t *, 6308275SEric Cheng uint32_t); 6318275SEric Cheng extern int mac_rx_classify_flow_quiesce(flow_entry_t *, void *); 6328275SEric Cheng extern int mac_rx_classify_flow_restart(flow_entry_t *, void *); 6338275SEric Cheng extern void mac_tx_client_quiesce(mac_client_impl_t *, uint_t); 6348275SEric Cheng extern void mac_tx_client_restart(mac_client_impl_t *); 6358275SEric Cheng extern void mac_client_quiesce(mac_client_impl_t *); 6368275SEric Cheng extern void mac_client_restart(mac_client_impl_t *); 6378275SEric Cheng 6388275SEric Cheng extern void mac_flow_update_priority(mac_client_impl_t *, flow_entry_t *); 6398275SEric Cheng 6408275SEric Cheng extern void mac_flow_rem_subflow(flow_entry_t *); 6418275SEric Cheng extern void mac_rename_flow(flow_entry_t *, const char *); 6428275SEric Cheng extern void mac_flow_set_name(flow_entry_t *, const char *); 6438275SEric Cheng 6448275SEric Cheng extern mblk_t *mac_add_vlan_tag(mblk_t *, uint_t, uint16_t); 6458275SEric Cheng extern mblk_t *mac_add_vlan_tag_chain(mblk_t *, uint_t, uint16_t); 6468275SEric Cheng extern mblk_t *mac_strip_vlan_tag_chain(mblk_t *); 6478275SEric Cheng extern void mac_pkt_drop(void *, mac_resource_handle_t, mblk_t *, boolean_t); 6488275SEric Cheng extern mblk_t *mac_rx_flow(mac_handle_t, mac_resource_handle_t, mblk_t *); 6498275SEric Cheng 6508275SEric Cheng extern void i_mac_share_alloc(mac_client_impl_t *); 6518275SEric Cheng extern void i_mac_share_free(mac_client_impl_t *); 6528275SEric Cheng extern void i_mac_perim_enter(mac_impl_t *); 6538275SEric Cheng extern void i_mac_perim_exit(mac_impl_t *); 6548275SEric Cheng extern int i_mac_perim_enter_nowait(mac_impl_t *); 6558275SEric Cheng extern void i_mac_tx_srs_notify(mac_impl_t *, mac_ring_handle_t); 6568275SEric Cheng extern int mac_hold(const char *, mac_impl_t **); 6578275SEric Cheng extern void mac_rele(mac_impl_t *); 6588275SEric Cheng extern int i_mac_disable(mac_impl_t *); 6598275SEric Cheng extern void i_mac_notify(mac_impl_t *, mac_notify_type_t); 6608275SEric Cheng extern void i_mac_notify_exit(mac_impl_t *); 6618275SEric Cheng extern int mac_start(mac_impl_t *); 6628275SEric Cheng extern void mac_stop(mac_impl_t *); 6638275SEric Cheng extern void mac_rx_group_unmark(mac_group_t *, uint_t); 6648275SEric Cheng extern void mac_tx_client_flush(mac_client_impl_t *); 6658275SEric Cheng extern void mac_tx_client_block(mac_client_impl_t *); 6668275SEric Cheng extern void mac_tx_client_unblock(mac_client_impl_t *); 6678275SEric Cheng extern int i_mac_promisc_set(mac_impl_t *, boolean_t, mac_promisc_type_t); 6688275SEric Cheng extern void i_mac_promisc_walker_cleanup(mac_impl_t *); 6698275SEric Cheng extern mactype_t *mactype_getplugin(const char *); 6708275SEric Cheng extern void mac_addr_factory_init(mac_impl_t *); 6718275SEric Cheng extern void mac_addr_factory_fini(mac_impl_t *); 6728275SEric Cheng extern void mac_register_priv_prop(mac_impl_t *, mac_priv_prop_t *, uint_t); 6738275SEric Cheng extern void mac_unregister_priv_prop(mac_impl_t *); 6748275SEric Cheng extern int mac_init_rings(mac_impl_t *, mac_ring_type_t); 6758275SEric Cheng extern void mac_free_rings(mac_impl_t *, mac_ring_type_t); 6768275SEric Cheng 6778275SEric Cheng extern int mac_start_group(mac_group_t *); 6788275SEric Cheng extern void mac_stop_group(mac_group_t *); 6798275SEric Cheng extern int mac_start_ring(mac_ring_t *); 6808275SEric Cheng extern void mac_stop_ring(mac_ring_t *); 6818400SNicolas.Droux@Sun.COM extern int mac_add_macaddr(mac_impl_t *, mac_group_t *, uint8_t *, boolean_t); 6828275SEric Cheng extern int mac_remove_macaddr(mac_address_t *); 6838275SEric Cheng 6848275SEric Cheng extern void mac_set_rx_group_state(mac_group_t *, mac_group_state_t); 6858275SEric Cheng extern void mac_rx_group_add_client(mac_group_t *, mac_client_impl_t *); 6868275SEric Cheng extern void mac_rx_group_remove_client(mac_group_t *, mac_client_impl_t *) 6878275SEric Cheng ; 6888275SEric Cheng extern int i_mac_group_add_ring(mac_group_t *, mac_ring_t *, int); 6898275SEric Cheng extern void i_mac_group_rem_ring(mac_group_t *, mac_ring_t *, boolean_t); 6906512Ssowmini 6910Sstevel@tonic-gate #ifdef __cplusplus 6920Sstevel@tonic-gate } 6930Sstevel@tonic-gate #endif 6940Sstevel@tonic-gate 6950Sstevel@tonic-gate #endif /* _SYS_MAC_IMPL_H */ 696