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 50Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 60Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 70Sstevel@tonic-gate * with the License. 80Sstevel@tonic-gate * 90Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 100Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 110Sstevel@tonic-gate * See the License for the specific language governing permissions 120Sstevel@tonic-gate * and limitations under the License. 130Sstevel@tonic-gate * 140Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 150Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 160Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 170Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 180Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 190Sstevel@tonic-gate * 200Sstevel@tonic-gate * CDDL HEADER END 210Sstevel@tonic-gate */ 220Sstevel@tonic-gate /* 230Sstevel@tonic-gate * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 240Sstevel@tonic-gate * Use is subject to license terms. 250Sstevel@tonic-gate */ 260Sstevel@tonic-gate 270Sstevel@tonic-gate #ifndef _SYS_DLD_IMPL_H 280Sstevel@tonic-gate #define _SYS_DLD_IMPL_H 290Sstevel@tonic-gate 300Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 310Sstevel@tonic-gate 320Sstevel@tonic-gate #include <sys/types.h> 330Sstevel@tonic-gate #include <sys/ethernet.h> 340Sstevel@tonic-gate #include <sys/stream.h> 350Sstevel@tonic-gate #include <sys/dlpi.h> 360Sstevel@tonic-gate #include <sys/mac.h> 370Sstevel@tonic-gate #include <sys/dls.h> 380Sstevel@tonic-gate #include <sys/dld.h> 390Sstevel@tonic-gate 400Sstevel@tonic-gate #ifdef __cplusplus 410Sstevel@tonic-gate extern "C" { 420Sstevel@tonic-gate #endif 430Sstevel@tonic-gate 440Sstevel@tonic-gate #define DLD_CONTROL 0x00000001 450Sstevel@tonic-gate #define DLD_DLPI 0x00000002 460Sstevel@tonic-gate 470Sstevel@tonic-gate typedef enum { 480Sstevel@tonic-gate DLD_UNITDATA, 490Sstevel@tonic-gate DLD_FASTPATH, 500Sstevel@tonic-gate DLD_RAW 510Sstevel@tonic-gate } dld_str_mode_t; 520Sstevel@tonic-gate 530Sstevel@tonic-gate typedef enum { 540Sstevel@tonic-gate DLD_UNINITIALIZED, 550Sstevel@tonic-gate DLD_PASSIVE, 560Sstevel@tonic-gate DLD_ACTIVE 570Sstevel@tonic-gate } dld_passivestate_t; 580Sstevel@tonic-gate 590Sstevel@tonic-gate typedef struct dld_str dld_str_t; 600Sstevel@tonic-gate 610Sstevel@tonic-gate /* 620Sstevel@tonic-gate * dld_str_t object definition. 630Sstevel@tonic-gate */ 640Sstevel@tonic-gate struct dld_str { 650Sstevel@tonic-gate /* 66269Sericheng * Major number of the device 67269Sericheng */ 68269Sericheng major_t ds_major; 69269Sericheng 70269Sericheng /* 710Sstevel@tonic-gate * Ephemeral minor number for the object. 720Sstevel@tonic-gate */ 730Sstevel@tonic-gate minor_t ds_minor; 740Sstevel@tonic-gate 750Sstevel@tonic-gate /* 760Sstevel@tonic-gate * Read/write queues for the stream which the object represents. 770Sstevel@tonic-gate */ 780Sstevel@tonic-gate queue_t *ds_rq; 790Sstevel@tonic-gate queue_t *ds_wq; 800Sstevel@tonic-gate 810Sstevel@tonic-gate /* 82269Sericheng * Lock to protect this structure. 83269Sericheng */ 84269Sericheng krwlock_t ds_lock; 85269Sericheng 86269Sericheng /* 870Sstevel@tonic-gate * Stream is open to DLD_CONTROL (control node) or 880Sstevel@tonic-gate * DLD_DLPI (DLS provider) node. 890Sstevel@tonic-gate */ 900Sstevel@tonic-gate uint_t ds_type; 910Sstevel@tonic-gate 920Sstevel@tonic-gate /* 930Sstevel@tonic-gate * The following fields are only used for DLD_DLPI type objects. 940Sstevel@tonic-gate */ 950Sstevel@tonic-gate 960Sstevel@tonic-gate /* 970Sstevel@tonic-gate * Current DLPI state. 980Sstevel@tonic-gate */ 990Sstevel@tonic-gate t_uscalar_t ds_dlstate; 1000Sstevel@tonic-gate 1010Sstevel@tonic-gate /* 102269Sericheng * DLPI style 103269Sericheng */ 104269Sericheng t_uscalar_t ds_style; 105269Sericheng 106269Sericheng /* 1070Sstevel@tonic-gate * Currently bound DLSAP. 1080Sstevel@tonic-gate */ 1090Sstevel@tonic-gate uint16_t ds_sap; 1100Sstevel@tonic-gate 1110Sstevel@tonic-gate /* 1120Sstevel@tonic-gate * Handle of the data-link channel that is used by this object. 1130Sstevel@tonic-gate */ 1140Sstevel@tonic-gate dls_channel_t ds_dc; 1150Sstevel@tonic-gate 1160Sstevel@tonic-gate /* 1170Sstevel@tonic-gate * Handle of the MAC that is used by the data-link interface. 1180Sstevel@tonic-gate */ 1190Sstevel@tonic-gate mac_handle_t ds_mh; 1200Sstevel@tonic-gate 1210Sstevel@tonic-gate /* 1220Sstevel@tonic-gate * VLAN identifier of the data-link interface. 1230Sstevel@tonic-gate */ 1240Sstevel@tonic-gate uint16_t ds_vid; 1250Sstevel@tonic-gate 1260Sstevel@tonic-gate /* 1270Sstevel@tonic-gate * Promiscuity level information. 1280Sstevel@tonic-gate */ 1290Sstevel@tonic-gate uint32_t ds_promisc; 1300Sstevel@tonic-gate 1310Sstevel@tonic-gate /* 1320Sstevel@tonic-gate * Immutable information of the MAC which the channel is using. 1330Sstevel@tonic-gate */ 1340Sstevel@tonic-gate const mac_info_t *ds_mip; 1350Sstevel@tonic-gate 1360Sstevel@tonic-gate /* 1370Sstevel@tonic-gate * Current packet priority. 1380Sstevel@tonic-gate */ 1390Sstevel@tonic-gate uint_t ds_pri; 1400Sstevel@tonic-gate 1410Sstevel@tonic-gate /* 1420Sstevel@tonic-gate * Handle of our MAC notification callback. 1430Sstevel@tonic-gate */ 1440Sstevel@tonic-gate mac_notify_handle_t ds_mnh; 1450Sstevel@tonic-gate 1460Sstevel@tonic-gate /* 1470Sstevel@tonic-gate * Set of enabled DL_NOTE... notifications. (See dlpi.h). 1480Sstevel@tonic-gate */ 1490Sstevel@tonic-gate uint32_t ds_notifications; 1500Sstevel@tonic-gate 1510Sstevel@tonic-gate /* 1520Sstevel@tonic-gate * Cached MAC unicast addresses. 1530Sstevel@tonic-gate */ 1540Sstevel@tonic-gate uint8_t ds_fact_addr[MAXADDRLEN]; 1550Sstevel@tonic-gate uint8_t ds_curr_addr[MAXADDRLEN]; 1560Sstevel@tonic-gate 1570Sstevel@tonic-gate /* 1580Sstevel@tonic-gate * Mode: unitdata, fast-path or raw. 1590Sstevel@tonic-gate */ 1600Sstevel@tonic-gate dld_str_mode_t ds_mode; 1610Sstevel@tonic-gate 1620Sstevel@tonic-gate /* 1630Sstevel@tonic-gate * IP polling is operational if this flag is set. 1640Sstevel@tonic-gate */ 1650Sstevel@tonic-gate boolean_t ds_polling; 166*1184Skrgopi boolean_t ds_soft_ring; 1670Sstevel@tonic-gate 1680Sstevel@tonic-gate /* 1690Sstevel@tonic-gate * State of DLPI user: may be active (regular network layer), 1700Sstevel@tonic-gate * passive (snoop-like monitoring), or unknown (not yet 1710Sstevel@tonic-gate * determined). 1720Sstevel@tonic-gate */ 1730Sstevel@tonic-gate dld_passivestate_t ds_passivestate; 1740Sstevel@tonic-gate 1750Sstevel@tonic-gate /* 176269Sericheng * Dummy mblk used for flow-control. 177269Sericheng */ 178269Sericheng mblk_t *ds_tx_flow_mp; 179269Sericheng 180269Sericheng /* 181269Sericheng * Internal transmit queue and its parameters. 1820Sstevel@tonic-gate */ 183269Sericheng kmutex_t ds_tx_list_lock; 184269Sericheng mblk_t *ds_tx_list_head; 185269Sericheng mblk_t *ds_tx_list_tail; 186269Sericheng uint_t ds_tx_cnt; 187269Sericheng uint_t ds_tx_msgcnt; 188269Sericheng boolean_t ds_tx_qbusy; 189269Sericheng 190269Sericheng /* 191269Sericheng * Number of threads currently in dld. If there is a pending 192269Sericheng * DL_DETACH_REQ, the request is placed in the ds_detach_req 193269Sericheng * and the operation will be finished when the driver goes 194269Sericheng * single-threaded. 195269Sericheng */ 196269Sericheng kmutex_t ds_thr_lock; 197269Sericheng uint_t ds_thr; 198*1184Skrgopi taskqid_t ds_task_id; 199269Sericheng mblk_t *ds_detach_req; 200*1184Skrgopi mblk_t *ds_unbind_req; 2010Sstevel@tonic-gate } dld_str; 2020Sstevel@tonic-gate 2030Sstevel@tonic-gate /* 2040Sstevel@tonic-gate * dld_str.c module. 2050Sstevel@tonic-gate */ 2060Sstevel@tonic-gate 2070Sstevel@tonic-gate extern void dld_str_init(void); 2080Sstevel@tonic-gate extern int dld_str_fini(void); 209269Sericheng extern dld_str_t *dld_str_create(queue_t *, uint_t, major_t, 210269Sericheng t_uscalar_t); 2110Sstevel@tonic-gate extern void dld_str_destroy(dld_str_t *); 212269Sericheng extern int dld_str_attach(dld_str_t *, t_uscalar_t); 2130Sstevel@tonic-gate extern void dld_str_detach(dld_str_t *); 2140Sstevel@tonic-gate extern void dld_str_rx_raw(void *, mac_resource_handle_t, 2150Sstevel@tonic-gate mblk_t *, size_t); 2160Sstevel@tonic-gate extern void dld_str_rx_fastpath(void *, mac_resource_handle_t, 2170Sstevel@tonic-gate mblk_t *, size_t); 2180Sstevel@tonic-gate extern void dld_str_rx_unitdata(void *, mac_resource_handle_t, 2190Sstevel@tonic-gate mblk_t *, size_t); 220269Sericheng extern void dld_tx_flush(dld_str_t *); 221269Sericheng extern void dld_tx_enqueue(dld_str_t *, mblk_t *, boolean_t); 2220Sstevel@tonic-gate extern void dld_str_notify_ind(dld_str_t *); 2230Sstevel@tonic-gate 224269Sericheng extern void str_mdata_fastpath_put(dld_str_t *, mblk_t *); 225269Sericheng extern void str_mdata_raw_put(dld_str_t *, mblk_t *); 226269Sericheng 2270Sstevel@tonic-gate /* 2280Sstevel@tonic-gate * dld_proto.c 2290Sstevel@tonic-gate */ 2300Sstevel@tonic-gate extern void dld_proto(dld_str_t *, mblk_t *); 231269Sericheng extern void dld_finish_pending_ops(dld_str_t *); 2320Sstevel@tonic-gate 2330Sstevel@tonic-gate /* 2340Sstevel@tonic-gate * Options: there should be a separate bit defined here for each 2350Sstevel@tonic-gate * DLD_PROP... defined in dld.h. 2360Sstevel@tonic-gate */ 237269Sericheng #define DLD_OPT_NO_FASTPATH 0x00000001 238269Sericheng #define DLD_OPT_NO_POLL 0x00000002 239269Sericheng #define DLD_OPT_NO_ZEROCOPY 0x00000004 2400Sstevel@tonic-gate 2410Sstevel@tonic-gate extern uint32_t dld_opt; 2420Sstevel@tonic-gate 2430Sstevel@tonic-gate /* 2440Sstevel@tonic-gate * Useful macros. 2450Sstevel@tonic-gate */ 2460Sstevel@tonic-gate 2470Sstevel@tonic-gate #define IMPLY(p, c) (!(p) || (c)) 2480Sstevel@tonic-gate #define AGGR_DEV "aggr0" 2490Sstevel@tonic-gate 250269Sericheng #define DLD_ENTER(dsp) { \ 251269Sericheng mutex_enter(&dsp->ds_thr_lock); \ 252269Sericheng ++dsp->ds_thr; \ 253269Sericheng ASSERT(dsp->ds_thr != 0); \ 254269Sericheng mutex_exit(&dsp->ds_thr_lock); \ 255269Sericheng } 256269Sericheng 257269Sericheng #define DLD_EXIT(dsp) { \ 258269Sericheng mutex_enter(&dsp->ds_thr_lock); \ 259269Sericheng ASSERT(dsp->ds_thr > 0); \ 260269Sericheng if (--dsp->ds_thr == 0 && dsp->ds_detach_req != NULL) \ 261269Sericheng dld_finish_pending_ops(dsp); \ 262269Sericheng else \ 263269Sericheng mutex_exit(&dsp->ds_thr_lock); \ 264269Sericheng } 265269Sericheng 266269Sericheng #ifdef DEBUG 267269Sericheng #define DLD_DBG cmn_err 268269Sericheng #else 269269Sericheng #define DLD_DBG if (0) cmn_err 270269Sericheng #endif 271269Sericheng 2720Sstevel@tonic-gate #ifdef __cplusplus 2730Sstevel@tonic-gate } 2740Sstevel@tonic-gate #endif 2750Sstevel@tonic-gate 2760Sstevel@tonic-gate #endif /* _SYS_DLD_IMPL_H */ 277