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 /* 23 * Copyright 2008 Sun Microsystems, Inc. All rights reserved. 24 * Use is subject to license terms. 25 */ 26 27 #ifndef _SYS_MAC_PROVIDER_H 28 #define _SYS_MAC_PROVIDER_H 29 30 #include <sys/types.h> 31 #include <sys/ddi.h> 32 #include <sys/sunddi.h> 33 #include <sys/stream.h> 34 #include <sys/mac_flow.h> 35 #include <sys/mac.h> 36 37 /* 38 * MAC Provider Interface 39 */ 40 41 #ifdef __cplusplus 42 extern "C" { 43 #endif 44 45 /* 46 * MAC version identifier. This is used by mac_alloc() mac_register() to 47 * verify that incompatible drivers don't register. 48 */ 49 #define MAC_VERSION 0x1 50 51 /* 52 * Opaque handle types 53 */ 54 typedef struct __mac_rule_handle *mac_rule_handle_t; 55 56 /* 57 * Statistics 58 */ 59 60 #define XCVR_UNDEFINED 0 61 #define XCVR_NONE 1 62 #define XCVR_10 2 63 #define XCVR_100T4 3 64 #define XCVR_100X 4 65 #define XCVR_100T2 5 66 #define XCVR_1000X 6 67 #define XCVR_1000T 7 68 69 #ifdef _KERNEL 70 71 /* 72 * Definitions for MAC Drivers Capabilities 73 */ 74 /* 75 * MAC layer capabilities. These capabilities are handled by the drivers' 76 * mc_capab_get() callbacks. Some capabilities require the driver to fill 77 * in a given data structure, and others are simply boolean capabilities. 78 * Note that capability values must be powers of 2 so that consumers and 79 * providers of this interface can keep track of which capabilities they 80 * care about by keeping a bitfield of these things around somewhere. 81 */ 82 typedef enum { 83 /* 84 * Capabilities reserved for internal use only 85 */ 86 MAC_CAPAB_VNIC = 0x0001, /* data is mac_capab_vnic_t */ 87 MAC_CAPAB_ANCHOR_VNIC = 0x0002, /* boolean only, no data */ 88 MAC_CAPAB_AGGR = 0x0004, /* data is mac_capab_aggr_t */ 89 MAC_CAPAB_NO_NATIVEVLAN = 0x0008, /* boolean only, no data */ 90 MAC_CAPAB_NO_ZCOPY = 0x0010, /* boolean only, no data */ 91 MAC_CAPAB_LEGACY = 0x0020, /* data is mac_capab_legacy_t */ 92 93 /* 94 * Public Capabilities 95 */ 96 MAC_CAPAB_HCKSUM = 0x0100, /* data is a uint32_t */ 97 MAC_CAPAB_LSO = 0x0200, /* data is mac_capab_lso_t */ 98 MAC_CAPAB_RINGS = 0x0400, /* data is mac_capab_rings_t */ 99 MAC_CAPAB_MULTIFACTADDR = 0x0800, /* mac_data_multifactaddr_t */ 100 MAC_CAPAB_SHARES = 0x1000 /* data is mac_capab_share_t */ 101 102 /* add new capabilities here */ 103 } mac_capab_t; 104 105 106 /* 107 * LSO capability 108 */ 109 typedef struct lso_basic_tcp_ipv4_s { 110 t_uscalar_t lso_max; /* maximum payload */ 111 } lso_basic_tcp_ipv4_t; 112 113 /* 114 * Currently supported flags for LSO. 115 */ 116 #define LSO_TX_BASIC_TCP_IPV4 0x01 /* TCP LSO capability */ 117 118 /* 119 * Future LSO capabilities can be added at the end of the mac_capab_lso_t. 120 * When such capability is added to the GLDv3 framework, the size of the 121 * mac_capab_lso_t it allocates and passes to the drivers increases. Older 122 * drivers wil access only the (upper) sections of that structure, that is the 123 * sections carrying the capabilities they understand. This ensures the 124 * interface can be safely extended in a binary compatible way. 125 */ 126 typedef struct mac_capab_lso_s { 127 t_uscalar_t lso_flags; 128 lso_basic_tcp_ipv4_t lso_basic_tcp_ipv4; 129 /* Add future lso capabilities here */ 130 } mac_capab_lso_t; 131 132 /* 133 * Multiple Factory MAC Addresses Capability 134 */ 135 typedef struct mac_capab_multifactaddr_s { 136 /* 137 * Number of factory addresses 138 */ 139 uint_t mcm_naddr; 140 141 /* 142 * Callbacks to query all the factory addresses. 143 */ 144 void (*mcm_getaddr)(void *, uint_t, uint8_t *); 145 } mac_capab_multifactaddr_t; 146 147 /* 148 * MAC driver entry point types. 149 */ 150 typedef int (*mac_getstat_t)(void *, uint_t, uint64_t *); 151 typedef int (*mac_start_t)(void *); 152 typedef void (*mac_stop_t)(void *); 153 typedef int (*mac_setpromisc_t)(void *, boolean_t); 154 typedef int (*mac_multicst_t)(void *, boolean_t, const uint8_t *); 155 typedef int (*mac_unicst_t)(void *, const uint8_t *); 156 typedef void (*mac_ioctl_t)(void *, queue_t *, mblk_t *); 157 typedef void (*mac_resources_t)(void *); 158 typedef mblk_t *(*mac_tx_t)(void *, mblk_t *); 159 typedef boolean_t (*mac_getcapab_t)(void *, mac_capab_t, void *); 160 typedef int (*mac_open_t)(void *); 161 typedef void (*mac_close_t)(void *); 162 typedef int (*mac_set_prop_t)(void *, const char *, mac_prop_id_t, 163 uint_t, const void *); 164 typedef int (*mac_get_prop_t)(void *, const char *, mac_prop_id_t, 165 uint_t, uint_t, void *, uint_t *); 166 167 /* 168 * Drivers must set all of these callbacks except for mc_resources, 169 * mc_ioctl, and mc_getcapab, which are optional. If any of these optional 170 * callbacks are set, their appropriate flags must be set in mc_callbacks. 171 * Any future additions to this list must also be accompanied by an 172 * associated mc_callbacks flag so that the framework can grow without 173 * affecting the binary compatibility of the interface. 174 */ 175 typedef struct mac_callbacks_s { 176 uint_t mc_callbacks; /* Denotes which callbacks are set */ 177 mac_getstat_t mc_getstat; /* Get the value of a statistic */ 178 mac_start_t mc_start; /* Start the device */ 179 mac_stop_t mc_stop; /* Stop the device */ 180 mac_setpromisc_t mc_setpromisc; /* Enable or disable promiscuous mode */ 181 mac_multicst_t mc_multicst; /* Enable or disable a multicast addr */ 182 mac_unicst_t mc_unicst; /* Set the unicast MAC address */ 183 mac_tx_t mc_tx; /* Transmit a packet */ 184 mac_ioctl_t mc_ioctl; /* Process an unknown ioctl */ 185 mac_getcapab_t mc_getcapab; /* Get capability information */ 186 mac_open_t mc_open; /* Open the device */ 187 mac_close_t mc_close; /* Close the device */ 188 mac_set_prop_t mc_setprop; 189 mac_get_prop_t mc_getprop; 190 } mac_callbacks_t; 191 192 typedef struct mac_priv_prop_s { 193 char mpp_name[MAXLINKPROPNAME]; 194 uint_t mpp_flags; 195 } mac_priv_prop_t; 196 197 /* 198 * Virtualization Capabilities 199 */ 200 /* 201 * The ordering of entries below is important. MAC_HW_CLASSIFIER 202 * is the cutoff below which are entries which don't depend on 203 * H/W. MAC_HW_CLASSIFIER and entries after that are cases where 204 * H/W has been updated through add/modify/delete APIs. 205 */ 206 typedef enum { 207 MAC_NO_CLASSIFIER = 0, 208 MAC_SW_CLASSIFIER, 209 MAC_HW_CLASSIFIER 210 } mac_classify_type_t; 211 212 typedef void (*mac_rx_func_t)(void *, mac_resource_handle_t, mblk_t *, 213 boolean_t); 214 215 /* 216 * The virtualization level conveys the extent of the NIC hardware assistance 217 * for traffic steering employed for virtualization: 218 * 219 * MAC_VIRT_NONE: No assist for v12n. 220 * 221 * MAC_VIRT_LEVEL1: Multiple Rx rings with MAC address level 222 * classification between groups of rings. 223 * Requires the support of the MAC_CAPAB_RINGS 224 * capability. 225 * 226 * MAC_VIRT_HIO: Hybrid I/O capable MAC. Require the support 227 * of the MAC_CAPAB_SHARES capability. 228 * 229 * MAC_VIRT_SERIALIZE: Temporary flag *ONLY* for nxge. Mac layer 230 * uses this to enable mac Tx serializer on 231 * outbound traffic and to always enqueue 232 * incoming traffic on Rx soft rings in mac. 233 */ 234 #define MAC_VIRT_NONE 0x0 235 #define MAC_VIRT_LEVEL1 0x1 236 #define MAC_VIRT_HIO 0x2 237 #define MAC_VIRT_SERIALIZE 0x4 238 239 typedef enum { 240 MAC_RING_TYPE_RX = 1, /* Receive ring */ 241 MAC_RING_TYPE_TX /* Transmit ring */ 242 } mac_ring_type_t; 243 244 #define MAX_RINGS_PER_GROUP 32 245 246 /* 247 * Grouping type of a ring group 248 * 249 * MAC_GROUP_TYPE_STATIC: The ring group can not be re-grouped. 250 * MAC_GROUP_TYPE_DYNAMIC: The ring group support dynamic re-grouping 251 */ 252 typedef enum { 253 MAC_GROUP_TYPE_STATIC = 1, /* Static ring group */ 254 MAC_GROUP_TYPE_DYNAMIC /* Dynamic ring group */ 255 } mac_group_type_t; 256 257 typedef struct __mac_ring_driver *mac_ring_driver_t; 258 typedef struct __mac_group_driver *mac_group_driver_t; 259 260 typedef struct mac_ring_info_s mac_ring_info_t; 261 typedef struct mac_group_info_s mac_group_info_t; 262 263 typedef void (*mac_get_ring_t)(void *, mac_ring_type_t, const int, const int, 264 mac_ring_info_t *, mac_ring_handle_t); 265 typedef void (*mac_get_group_t)(void *, mac_ring_type_t, const int, 266 mac_group_info_t *, mac_group_handle_t); 267 268 typedef void (*mac_group_add_ring_t)(mac_group_driver_t, 269 mac_ring_driver_t, mac_ring_type_t); 270 typedef void (*mac_group_rem_ring_t)(mac_group_driver_t, 271 mac_ring_driver_t, mac_ring_type_t); 272 273 /* 274 * Multiple Rings Capability 275 */ 276 typedef struct mac_capab_rings_s { 277 mac_ring_type_t mr_type; /* Ring type: Rx vs Tx */ 278 mac_group_type_t mr_group_type; /* Dynamic vs static grouping */ 279 uint_t mr_rnum; /* Number of rings */ 280 uint_t mr_gnum; /* Number of ring groups */ 281 mac_get_ring_t mr_rget; /* Get ring from driver */ 282 mac_get_group_t mr_gget; /* Get ring group from driver */ 283 mac_group_add_ring_t mr_gaddring; /* Add ring into a group */ 284 mac_group_rem_ring_t mr_gremring; /* Remove ring from a group */ 285 } mac_capab_rings_t; 286 287 /* 288 * Common ring functions and driver interfaces 289 */ 290 typedef int (*mac_ring_start_t)(mac_ring_driver_t, uint64_t); 291 typedef void (*mac_ring_stop_t)(mac_ring_driver_t); 292 293 typedef mblk_t *(*mac_ring_send_t)(void *, mblk_t *); 294 typedef mblk_t *(*mac_ring_poll_t)(void *, int); 295 296 typedef struct mac_ring_info_s { 297 mac_ring_driver_t mri_driver; 298 mac_ring_start_t mri_start; 299 mac_ring_stop_t mri_stop; 300 mac_intr_t mri_intr; 301 union { 302 mac_ring_send_t send; 303 mac_ring_poll_t poll; 304 } mrfunion; 305 } mac_ring_info_s; 306 307 #define mri_tx mrfunion.send 308 #define mri_poll mrfunion.poll 309 310 typedef int (*mac_group_start_t)(mac_group_driver_t); 311 typedef void (*mac_group_stop_t)(mac_group_driver_t); 312 typedef int (*mac_add_mac_addr_t)(void *, const uint8_t *); 313 typedef int (*mac_rem_mac_addr_t)(void *, const uint8_t *); 314 315 struct mac_group_info_s { 316 mac_group_driver_t mgi_driver; /* Driver reference */ 317 mac_group_start_t mgi_start; /* Start the group */ 318 mac_group_stop_t mgi_stop; /* Stop the group */ 319 uint_t mgi_count; /* Count of rings */ 320 mac_intr_t mgi_intr; /* Optional per-group intr */ 321 322 /* Only used for rx groups */ 323 mac_add_mac_addr_t mgi_addmac; /* Add a MAC address */ 324 mac_rem_mac_addr_t mgi_remmac; /* Remove a MAC address */ 325 }; 326 327 /* 328 * Share management functions. 329 */ 330 typedef uint64_t mac_share_handle_t; 331 332 /* 333 * Allocate and free a share. Returns ENOSPC if all shares have been 334 * previously allocated. 335 */ 336 typedef int (*mac_alloc_share_t)(void *, mac_share_handle_t *); 337 typedef void (*mac_free_share_t)(mac_share_handle_t); 338 339 /* 340 * Bind and unbind a share. Binding a share allows a domain 341 * to have direct access to the groups and rings associated with 342 * that share. 343 */ 344 typedef int (*mac_bind_share_t)(mac_share_handle_t, uint64_t, uint64_t *); 345 typedef void (*mac_unbind_share_t)(mac_share_handle_t); 346 347 /* 348 * Return information on about a share. 349 */ 350 typedef void (*mac_share_query_t)(mac_share_handle_t, mac_ring_type_t, 351 mac_ring_handle_t *, uint_t *); 352 353 /* 354 * Basic idea, bind previously created ring groups to shares 355 * for them to be exported (or shared) by another domain. 356 * These interfaces bind/unbind the ring group to a share. 357 * The groups and their rings will be shared with the guest 358 * as soon as the share is bound. 359 */ 360 typedef int (*mac_share_add_group_t)(mac_share_handle_t, 361 mac_group_driver_t); 362 typedef int (*mac_share_rem_group_t)(mac_share_handle_t, 363 mac_group_driver_t); 364 365 typedef struct mac_capab_share_s { 366 uint_t ms_snum; /* Number of shares (vr's) */ 367 void *ms_handle; /* Handle to driver. */ 368 mac_alloc_share_t ms_salloc; /* Get a share from driver. */ 369 mac_free_share_t ms_sfree; /* Return a share to driver. */ 370 mac_share_add_group_t ms_sadd; /* Add a group to the share. */ 371 mac_share_rem_group_t ms_sremove; /* Remove group from share. */ 372 mac_share_query_t ms_squery; /* Query share constraints */ 373 mac_bind_share_t ms_sbind; /* Bind a share */ 374 mac_unbind_share_t ms_sunbind; /* Unbind a share */ 375 } mac_capab_share_t; 376 377 /* 378 * MAC registration interface 379 */ 380 typedef struct mac_register_s { 381 uint_t m_version; /* set by mac_alloc() */ 382 const char *m_type_ident; 383 void *m_driver; /* Driver private data */ 384 dev_info_t *m_dip; 385 uint_t m_instance; 386 uint8_t *m_src_addr; 387 uint8_t *m_dst_addr; 388 mac_callbacks_t *m_callbacks; 389 uint_t m_min_sdu; 390 uint_t m_max_sdu; 391 void *m_pdata; 392 size_t m_pdata_size; 393 uint32_t m_margin; 394 mac_priv_prop_t *m_priv_props; 395 size_t m_priv_prop_count; 396 uint32_t m_v12n; /* Virtualization level */ 397 } mac_register_t; 398 399 /* 400 * Flags for mc_callbacks. Requiring drivers to set the flags associated 401 * with optional callbacks initialized in the structure allows the mac 402 * module to add optional callbacks in the future without requiring drivers 403 * to recompile. 404 */ 405 #define MC_IOCTL 0x001 406 #define MC_GETCAPAB 0x002 407 #define MC_OPEN 0x004 408 #define MC_CLOSE 0x008 409 #define MC_SETPROP 0x010 410 #define MC_GETPROP 0x020 411 412 /* 413 * Driver interface functions. 414 */ 415 extern void mac_sdu_get(mac_handle_t, uint_t *, uint_t *); 416 extern int mac_maxsdu_update(mac_handle_t, uint_t); 417 extern int mac_set_prop(mac_handle_t, mac_prop_t *, 418 void *, uint_t); 419 extern int mac_get_prop(mac_handle_t, mac_prop_t *, 420 void *, uint_t, uint_t *); 421 422 extern mac_register_t *mac_alloc(uint_t); 423 extern void mac_free(mac_register_t *); 424 extern int mac_register(mac_register_t *, mac_handle_t *); 425 extern int mac_disable_nowait(mac_handle_t); 426 extern int mac_disable(mac_handle_t); 427 extern int mac_unregister(mac_handle_t); 428 extern void mac_rx(mac_handle_t, mac_resource_handle_t, 429 mblk_t *); 430 extern void mac_rx_ring(mac_handle_t, mac_ring_handle_t, 431 mblk_t *, uint64_t); 432 extern void mac_link_update(mac_handle_t, link_state_t); 433 extern void mac_unicst_update(mac_handle_t, 434 const uint8_t *); 435 extern void mac_tx_update(mac_handle_t); 436 extern void mac_tx_ring_update(mac_handle_t, 437 mac_ring_handle_t); 438 extern void mac_resource_update(mac_handle_t); 439 extern void mac_capab_update(mac_handle_t); 440 extern int mac_pdata_update(mac_handle_t, void *, 441 size_t); 442 extern void mac_multicast_refresh(mac_handle_t, 443 mac_multicst_t, void *, boolean_t); 444 extern void mac_unicst_refresh(mac_handle_t, mac_unicst_t, 445 void *); 446 extern void mac_promisc_refresh(mac_handle_t, 447 mac_setpromisc_t, void *); 448 extern boolean_t mac_margin_update(mac_handle_t, uint32_t); 449 extern void mac_margin_get(mac_handle_t, uint32_t *); 450 extern int mac_margin_remove(mac_handle_t, uint32_t); 451 extern int mac_margin_add(mac_handle_t, uint32_t *, 452 boolean_t); 453 extern void mac_init_ops(struct dev_ops *, const char *); 454 extern void mac_fini_ops(struct dev_ops *); 455 extern uint32_t mac_no_notification(mac_handle_t); 456 457 extern mactype_register_t *mactype_alloc(uint_t); 458 extern void mactype_free(mactype_register_t *); 459 extern int mactype_register(mactype_register_t *); 460 extern int mactype_unregister(const char *); 461 extern void mac_set_ring(void *, void *); 462 463 extern boolean_t mac_unicst_verify(mac_handle_t, 464 const uint8_t *, uint_t); 465 466 extern boolean_t mac_is_vnic(mac_handle_t); 467 468 extern int mac_group_add_ring(mac_group_handle_t, int); 469 extern void mac_group_rem_ring(mac_group_handle_t, 470 mac_ring_handle_t); 471 472 #endif /* _KERNEL */ 473 474 #ifdef __cplusplus 475 } 476 #endif 477 478 #endif /* _SYS_MAC_PROVIDER_H */ 479