1 /* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License (the "License"). 6 * You may not use this file except in compliance with the License. 7 * 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9 * or http://www.opensolaris.org/os/licensing. 10 * See the License for the specific language governing permissions 11 * and limitations under the License. 12 * 13 * When distributing Covered Code, include this CDDL HEADER in each 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15 * If applicable, add the following below this CDDL HEADER, with the 16 * fields enclosed by brackets "[]" replaced with your own identifying 17 * information: Portions Copyright [yyyy] [name of copyright owner] 18 * 19 * CDDL HEADER END 20 */ 21 /* 22 * Copyright 2008 Sun Microsystems, Inc. All rights reserved. 23 * Use is subject to license terms. 24 */ 25 26 #ifndef _SYS_DLD_IMPL_H 27 #define _SYS_DLD_IMPL_H 28 29 #pragma ident "%Z%%M% %I% %E% SMI" 30 31 #include <sys/types.h> 32 #include <sys/conf.h> 33 #include <sys/ethernet.h> 34 #include <sys/stream.h> 35 #include <sys/dlpi.h> 36 #include <sys/mac.h> 37 #include <sys/dls.h> 38 #include <sys/dld.h> 39 40 #ifdef __cplusplus 41 extern "C" { 42 #endif 43 44 #define DLD_CONTROL 0x00000001 45 #define DLD_DLPI 0x00000002 46 47 typedef enum { 48 DLD_UNITDATA, 49 DLD_FASTPATH, 50 DLD_RAW 51 } dld_str_mode_t; 52 53 typedef enum { 54 DLD_UNINITIALIZED, 55 DLD_PASSIVE, 56 DLD_ACTIVE 57 } dld_passivestate_t; 58 59 typedef struct dld_str dld_str_t; 60 typedef void (*dld_tx_t)(struct dld_str *, mblk_t *); 61 62 /* 63 * dld_str_t object definition. 64 */ 65 struct dld_str { 66 /* 67 * Major number of the device 68 */ 69 major_t ds_major; 70 71 /* 72 * Ephemeral minor number for the object. 73 */ 74 minor_t ds_minor; 75 76 /* 77 * Read/write queues for the stream which the object represents. 78 */ 79 queue_t *ds_rq; 80 queue_t *ds_wq; 81 82 /* 83 * Lock to protect this structure. 84 */ 85 krwlock_t ds_lock; 86 87 /* 88 * Stream is open to DLD_CONTROL (control node) or 89 * DLD_DLPI (DLS provider) node. 90 */ 91 uint_t ds_type; 92 93 /* 94 * The following fields are only used for DLD_DLPI type objects. 95 */ 96 97 /* 98 * Current DLPI state. 99 */ 100 t_uscalar_t ds_dlstate; 101 102 /* 103 * DLPI style 104 */ 105 t_uscalar_t ds_style; 106 107 /* 108 * Currently bound DLSAP. 109 */ 110 uint16_t ds_sap; 111 112 /* 113 * Handle of the data-link channel that is used by this object. 114 */ 115 dls_channel_t ds_dc; 116 117 /* 118 * Handle of the MAC that is used by the data-link interface. 119 */ 120 mac_handle_t ds_mh; 121 122 /* 123 * VLAN identifier of the data-link interface. 124 */ 125 uint16_t ds_vid; 126 127 /* 128 * Promiscuity level information. 129 */ 130 uint32_t ds_promisc; 131 132 /* 133 * Immutable information of the MAC which the channel is using. 134 */ 135 const mac_info_t *ds_mip; 136 137 /* 138 * Current packet priority. 139 */ 140 uint_t ds_pri; 141 142 /* 143 * Handle of our MAC notification callback. 144 */ 145 mac_notify_handle_t ds_mnh; 146 147 /* 148 * Set of enabled DL_NOTE... notifications. (See dlpi.h). 149 */ 150 uint32_t ds_notifications; 151 152 /* 153 * Cached MAC unicast addresses. 154 */ 155 uint8_t ds_fact_addr[MAXMACADDRLEN]; 156 uint8_t ds_curr_addr[MAXMACADDRLEN]; 157 158 /* 159 * Mode: unitdata, fast-path or raw. 160 */ 161 dld_str_mode_t ds_mode; 162 163 /* 164 * Native mode state. 165 */ 166 boolean_t ds_native; 167 168 /* 169 * IP polling is operational if this flag is set. 170 */ 171 boolean_t ds_polling; 172 boolean_t ds_soft_ring; 173 174 /* 175 * LSO is enabled if ds_lso is set. 176 */ 177 boolean_t ds_lso; 178 uint64_t ds_lso_max; 179 180 /* 181 * State of DLPI user: may be active (regular network layer), 182 * passive (snoop-like monitoring), or unknown (not yet 183 * determined). 184 */ 185 dld_passivestate_t ds_passivestate; 186 187 /* 188 * Dummy mblk used for flow-control. 189 */ 190 mblk_t *ds_tx_flow_mp; 191 192 /* 193 * Internal transmit queue and its parameters. 194 */ 195 kmutex_t ds_tx_list_lock; 196 mblk_t *ds_tx_list_head; 197 mblk_t *ds_tx_list_tail; 198 uint_t ds_tx_cnt; 199 uint_t ds_tx_msgcnt; 200 timeout_id_t ds_tx_qdepth_tid; 201 boolean_t ds_tx_qbusy; 202 203 dld_tx_t ds_tx; 204 dld_tx_t ds_unitdata_tx; 205 kmutex_t ds_tx_lock; 206 kcondvar_t ds_tx_cv; 207 uint32_t ds_intx_cnt; 208 boolean_t ds_detaching; 209 210 /* 211 * Pending control messages to be processed. 212 */ 213 mblk_t *ds_pending_head; 214 mblk_t *ds_pending_tail; 215 216 taskqid_t ds_tid; 217 kmutex_t ds_disp_lock; 218 kcondvar_t ds_disp_cv; 219 boolean_t ds_closing; 220 221 /* 222 * Used to process ioctl message for control node. See comments 223 * above dld_ioctl(). 224 */ 225 void (*ds_ioctl)(queue_t *, mblk_t *); 226 } dld_str; 227 228 #define DLD_TX_ENTER(dsp) { \ 229 mutex_enter(&(dsp)->ds_tx_lock); \ 230 (dsp)->ds_intx_cnt++; \ 231 mutex_exit(&(dsp)->ds_tx_lock); \ 232 } 233 234 #define DLD_TX_EXIT(dsp) { \ 235 mutex_enter(&(dsp)->ds_tx_lock); \ 236 if ((--(dsp)->ds_intx_cnt == 0) && (dsp)->ds_detaching) \ 237 cv_signal(&(dsp)->ds_tx_cv); \ 238 mutex_exit(&(dsp)->ds_tx_lock); \ 239 } 240 241 /* 242 * Quiesce the traffic. 243 */ 244 #define DLD_TX_QUIESCE(dsp) { \ 245 mutex_enter(&(dsp)->ds_tx_lock); \ 246 (dsp)->ds_tx = (dsp)->ds_unitdata_tx = NULL; \ 247 (dsp)->ds_detaching = B_TRUE; \ 248 while ((dsp)->ds_intx_cnt != 0) \ 249 cv_wait(&(dsp)->ds_tx_cv, &(dsp)->ds_tx_lock); \ 250 (dsp)->ds_detaching = B_FALSE; \ 251 mutex_exit(&(dsp)->ds_tx_lock); \ 252 } 253 254 /* 255 * dld_str.c module. 256 */ 257 258 extern void dld_str_init(void); 259 extern int dld_str_fini(void); 260 extern dld_str_t *dld_str_create(queue_t *, uint_t, major_t, 261 t_uscalar_t); 262 extern void dld_str_destroy(dld_str_t *); 263 extern int dld_str_attach(dld_str_t *, t_uscalar_t); 264 extern void dld_str_detach(dld_str_t *); 265 extern void dld_str_rx_raw(void *, mac_resource_handle_t, 266 mblk_t *, mac_header_info_t *); 267 extern void dld_str_rx_fastpath(void *, mac_resource_handle_t, 268 mblk_t *, mac_header_info_t *); 269 extern void dld_str_rx_unitdata(void *, mac_resource_handle_t, 270 mblk_t *, mac_header_info_t *); 271 272 extern void dld_tx_flush(dld_str_t *); 273 extern void dld_str_notify_ind(dld_str_t *); 274 extern void dld_tx_single(dld_str_t *, mblk_t *); 275 extern void str_mdata_fastpath_put(dld_str_t *, mblk_t *); 276 extern void str_mdata_raw_put(dld_str_t *, mblk_t *); 277 278 extern void dld_ioctl(queue_t *, mblk_t *); 279 extern void dld_finish_pending_task(dld_str_t *); 280 281 /* 282 * dld_proto.c 283 */ 284 extern void dld_wput_proto_nondata(dld_str_t *, mblk_t *); 285 extern void dld_wput_proto_data(dld_str_t *, mblk_t *); 286 extern void dld_capabilities_disable(dld_str_t *); 287 288 /* 289 * Options: there should be a separate bit defined here for each 290 * DLD_PROP... defined in dld.h. 291 */ 292 #define DLD_OPT_NO_FASTPATH 0x00000001 293 #define DLD_OPT_NO_POLL 0x00000002 294 #define DLD_OPT_NO_ZEROCOPY 0x00000004 295 #define DLD_OPT_NO_SOFTRING 0x00000008 296 297 extern uint32_t dld_opt; 298 299 /* 300 * autopush information 301 */ 302 typedef struct dld_ap { 303 datalink_id_t da_linkid; 304 struct dlautopush da_ap; 305 306 #define da_anchor da_ap.dap_anchor 307 #define da_npush da_ap.dap_npush 308 #define da_aplist da_ap.dap_aplist 309 310 } dld_ap_t; 311 312 /* 313 * Useful macros. 314 */ 315 316 #define IMPLY(p, c) (!(p) || (c)) 317 318 #ifdef DEBUG 319 #define DLD_DBG cmn_err 320 #else 321 #define DLD_DBG if (0) cmn_err 322 #endif 323 324 #ifdef __cplusplus 325 } 326 #endif 327 328 #endif /* _SYS_DLD_IMPL_H */ 329