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 (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved. 24 * Copyright (c) 2017, Joyent, Inc. 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/mkdev.h> 35 #include <sys/mac.h> 36 #include <sys/mac_flow.h> 37 38 /* 39 * MAC Provider Interface 40 */ 41 42 #ifdef __cplusplus 43 extern "C" { 44 #endif 45 46 /* 47 * MAC version identifiers. Drivers compiled against the stable V1 version 48 * of the API should register with MAC_VERSION_V1. ON drivers should use 49 * MAC_VERSION. This is used by mac_alloc() mac_register() to 50 * verify that incompatible drivers don't register. 51 */ 52 #define MAC_VERSION_V1 0x1 53 #define MAC_VERSION MAC_VERSION_V1 54 55 /* 56 * Possible values for ETHER_STAT_XCVR_INUSE statistic. 57 */ 58 59 #define XCVR_UNDEFINED 0 60 #define XCVR_NONE 1 61 #define XCVR_10 2 62 #define XCVR_100T4 3 63 #define XCVR_100X 4 64 #define XCVR_100T2 5 65 #define XCVR_1000X 6 66 #define XCVR_1000T 7 67 68 #ifdef _KERNEL 69 70 /* 71 * Definitions for MAC Drivers Capabilities 72 */ 73 /* 74 * MAC layer capabilities. These capabilities are handled by the drivers' 75 * mc_capab_get() callbacks. Some capabilities require the driver to fill 76 * in a given data structure, and others are simply boolean capabilities. 77 * Note that capability values must be powers of 2 so that consumers and 78 * providers of this interface can keep track of which capabilities they 79 * care about by keeping a bitfield of these things around somewhere. 80 */ 81 typedef enum { 82 /* 83 * Public Capabilities (MAC_VERSION_V1) 84 */ 85 MAC_CAPAB_HCKSUM = 0x00000001, /* data is a uint32_t */ 86 MAC_CAPAB_LSO = 0x00000008, /* data is mac_capab_lso_t */ 87 88 /* 89 * Reserved capabilities, do not use 90 */ 91 MAC_CAPAB_RESERVED1 = 0x00000002, 92 MAC_CAPAB_RESERVED2 = 0x00000004, 93 94 /* 95 * Private driver capabilities 96 */ 97 MAC_CAPAB_RINGS = 0x00000010, /* data is mac_capab_rings_t */ 98 MAC_CAPAB_SHARES = 0x00000020, /* data is mac_capab_share_t */ 99 MAC_CAPAB_MULTIFACTADDR = 0x00000040, /* mac_data_multifactaddr_t */ 100 101 /* 102 * Private driver capabilities for use by the GLDv3 framework only 103 */ 104 MAC_CAPAB_VNIC = 0x00010000, /* data is mac_capab_vnic_t */ 105 MAC_CAPAB_ANCHOR_VNIC = 0x00020000, /* boolean only, no data */ 106 MAC_CAPAB_AGGR = 0x00040000, /* data is mac_capab_aggr_t */ 107 MAC_CAPAB_NO_NATIVEVLAN = 0x00080000, /* boolean only, no data */ 108 MAC_CAPAB_NO_ZCOPY = 0x00100000, /* boolean only, no data */ 109 MAC_CAPAB_LEGACY = 0x00200000, /* data is mac_capab_legacy_t */ 110 MAC_CAPAB_VRRP = 0x00400000, /* data is mac_capab_vrrp_t */ 111 MAC_CAPAB_TRANSCEIVER = 0x01000000 /* mac_capab_transciever_t */ 112 } mac_capab_t; 113 114 /* 115 * LSO capability 116 */ 117 typedef struct lso_basic_tcp_ipv4_s { 118 t_uscalar_t lso_max; /* maximum payload */ 119 } lso_basic_tcp_ipv4_t; 120 121 /* 122 * Currently supported flags for LSO. 123 */ 124 #define LSO_TX_BASIC_TCP_IPV4 0x01 /* TCP LSO capability */ 125 126 /* 127 * Future LSO capabilities can be added at the end of the mac_capab_lso_t. 128 * When such capability is added to the GLDv3 framework, the size of the 129 * mac_capab_lso_t it allocates and passes to the drivers increases. Older 130 * drivers wil access only the (upper) sections of that structure, that is the 131 * sections carrying the capabilities they understand. This ensures the 132 * interface can be safely extended in a binary compatible way. 133 */ 134 typedef struct mac_capab_lso_s { 135 t_uscalar_t lso_flags; 136 lso_basic_tcp_ipv4_t lso_basic_tcp_ipv4; 137 /* Add future lso capabilities here */ 138 } mac_capab_lso_t; 139 140 /* 141 * Multiple Factory MAC Addresses Capability 142 */ 143 typedef struct mac_capab_multifactaddr_s { 144 /* 145 * Number of factory addresses 146 */ 147 uint_t mcm_naddr; 148 149 /* 150 * Callbacks to query all the factory addresses. 151 */ 152 void (*mcm_getaddr)(void *, uint_t, uint8_t *); 153 } mac_capab_multifactaddr_t; 154 155 /* 156 * Info and callbacks of legacy devices. 157 */ 158 typedef struct mac_capab_legacy_s { 159 /* 160 * Notifications that the legacy device does not support. 161 */ 162 uint32_t ml_unsup_note; 163 /* 164 * dev_t of the legacy device; can be held to force attach. 165 */ 166 dev_t ml_dev; 167 boolean_t (*ml_active_set)(void *); 168 void (*ml_active_clear)(void *); 169 int (*ml_fastpath_disable)(void *); 170 void (*ml_fastpath_enable)(void *); 171 } mac_capab_legacy_t; 172 173 typedef struct __mac_prop_info_handle *mac_prop_info_handle_t; 174 175 /* 176 * MAC driver entry point types. 177 */ 178 typedef int (*mac_getstat_t)(void *, uint_t, uint64_t *); 179 typedef int (*mac_start_t)(void *); 180 typedef void (*mac_stop_t)(void *); 181 typedef int (*mac_setpromisc_t)(void *, boolean_t); 182 typedef int (*mac_multicst_t)(void *, boolean_t, const uint8_t *); 183 typedef int (*mac_unicst_t)(void *, const uint8_t *); 184 typedef void (*mac_ioctl_t)(void *, queue_t *, mblk_t *); 185 typedef void (*mac_resources_t)(void *); 186 typedef mblk_t *(*mac_tx_t)(void *, mblk_t *); 187 typedef boolean_t (*mac_getcapab_t)(void *, mac_capab_t, void *); 188 typedef int (*mac_open_t)(void *); 189 typedef void (*mac_close_t)(void *); 190 typedef int (*mac_set_prop_t)(void *, const char *, mac_prop_id_t, 191 uint_t, const void *); 192 typedef int (*mac_get_prop_t)(void *, const char *, mac_prop_id_t, 193 uint_t, void *); 194 typedef void (*mac_prop_info_t)(void *, const char *, mac_prop_id_t, 195 mac_prop_info_handle_t); 196 197 /* 198 * Driver callbacks. The following capabilities are optional, and if 199 * implemented by the driver, must have a corresponding MC_ flag set 200 * in the mc_callbacks field. 201 * 202 * Any future additions to this list must also be accompanied by an 203 * associated mc_callbacks flag so that the framework can grow without 204 * affecting the binary compatibility of the interface. 205 */ 206 typedef struct mac_callbacks_s { 207 uint_t mc_callbacks; /* Denotes which callbacks are set */ 208 mac_getstat_t mc_getstat; /* Get the value of a statistic */ 209 mac_start_t mc_start; /* Start the device */ 210 mac_stop_t mc_stop; /* Stop the device */ 211 mac_setpromisc_t mc_setpromisc; /* Enable or disable promiscuous mode */ 212 mac_multicst_t mc_multicst; /* Enable or disable a multicast addr */ 213 mac_unicst_t mc_unicst; /* Set the unicast MAC address */ 214 mac_tx_t mc_tx; /* Transmit a packet */ 215 void *mc_reserved; /* Reserved, do not use */ 216 mac_ioctl_t mc_ioctl; /* Process an unknown ioctl */ 217 mac_getcapab_t mc_getcapab; /* Get capability information */ 218 mac_open_t mc_open; /* Open the device */ 219 mac_close_t mc_close; /* Close the device */ 220 mac_set_prop_t mc_setprop; 221 mac_get_prop_t mc_getprop; 222 mac_prop_info_t mc_propinfo; 223 } mac_callbacks_t; 224 225 /* 226 * Flags for mc_callbacks. Requiring drivers to set the flags associated 227 * with optional callbacks initialized in the structure allows the mac 228 * module to add optional callbacks in the future without requiring drivers 229 * to recompile. 230 */ 231 #define MC_RESERVED 0x0001 232 #define MC_IOCTL 0x0002 233 #define MC_GETCAPAB 0x0004 234 #define MC_OPEN 0x0008 235 #define MC_CLOSE 0x0010 236 #define MC_SETPROP 0x0020 237 #define MC_GETPROP 0x0040 238 #define MC_PROPINFO 0x0080 239 #define MC_PROPERTIES (MC_SETPROP | MC_GETPROP | MC_PROPINFO) 240 241 /* 242 * Virtualization Capabilities 243 */ 244 /* 245 * The ordering of entries below is important. MAC_HW_CLASSIFIER 246 * is the cutoff below which are entries which don't depend on 247 * H/W. MAC_HW_CLASSIFIER and entries after that are cases where 248 * H/W has been updated through add/modify/delete APIs. 249 */ 250 typedef enum { 251 MAC_NO_CLASSIFIER = 0, 252 MAC_SW_CLASSIFIER, 253 MAC_HW_CLASSIFIER 254 } mac_classify_type_t; 255 256 typedef void (*mac_rx_func_t)(void *, mac_resource_handle_t, mblk_t *, 257 boolean_t); 258 259 /* 260 * The virtualization level conveys the extent of the NIC hardware assistance 261 * for traffic steering employed for virtualization: 262 * 263 * MAC_VIRT_NONE: No assist for v12n. 264 * 265 * MAC_VIRT_LEVEL1: Multiple Rx rings with MAC address level 266 * classification between groups of rings. 267 * Requires the support of the MAC_CAPAB_RINGS 268 * capability. 269 * 270 * MAC_VIRT_HIO: Hybrid I/O capable MAC. Require the support 271 * of the MAC_CAPAB_SHARES capability. 272 */ 273 #define MAC_VIRT_NONE 0x0 274 #define MAC_VIRT_LEVEL1 0x1 275 #define MAC_VIRT_HIO 0x2 276 277 typedef enum { 278 MAC_RING_TYPE_RX = 1, /* Receive ring */ 279 MAC_RING_TYPE_TX /* Transmit ring */ 280 } mac_ring_type_t; 281 282 /* 283 * Grouping type of a ring group 284 * 285 * MAC_GROUP_TYPE_STATIC: The ring group can not be re-grouped. 286 * MAC_GROUP_TYPE_DYNAMIC: The ring group support dynamic re-grouping 287 */ 288 typedef enum { 289 MAC_GROUP_TYPE_STATIC = 1, /* Static ring group */ 290 MAC_GROUP_TYPE_DYNAMIC /* Dynamic ring group */ 291 } mac_group_type_t; 292 293 typedef struct __mac_ring_driver *mac_ring_driver_t; 294 typedef struct __mac_group_driver *mac_group_driver_t; 295 296 typedef struct mac_ring_info_s mac_ring_info_t; 297 typedef struct mac_group_info_s mac_group_info_t; 298 299 typedef void (*mac_get_ring_t)(void *, mac_ring_type_t, const int, const int, 300 mac_ring_info_t *, mac_ring_handle_t); 301 typedef void (*mac_get_group_t)(void *, mac_ring_type_t, const int, 302 mac_group_info_t *, mac_group_handle_t); 303 304 typedef void (*mac_group_add_ring_t)(mac_group_driver_t, 305 mac_ring_driver_t, mac_ring_type_t); 306 typedef void (*mac_group_rem_ring_t)(mac_group_driver_t, 307 mac_ring_driver_t, mac_ring_type_t); 308 309 /* 310 * Multiple Rings Capability 311 */ 312 typedef struct mac_capab_rings_s { 313 mac_ring_type_t mr_type; /* Ring type: Rx vs Tx */ 314 mac_group_type_t mr_group_type; /* Dynamic vs static grouping */ 315 uint_t mr_rnum; /* Number of rings */ 316 uint_t mr_gnum; /* Number of ring groups */ 317 mac_get_ring_t mr_rget; /* Get ring from driver */ 318 mac_get_group_t mr_gget; /* Get ring group from driver */ 319 mac_group_add_ring_t mr_gaddring; /* Add ring into a group */ 320 mac_group_rem_ring_t mr_gremring; /* Remove ring from a group */ 321 } mac_capab_rings_t; 322 323 /* 324 * Common ring functions and driver interfaces 325 */ 326 typedef int (*mac_ring_start_t)(mac_ring_driver_t, uint64_t); 327 typedef void (*mac_ring_stop_t)(mac_ring_driver_t); 328 329 typedef mblk_t *(*mac_ring_send_t)(void *, mblk_t *); 330 typedef mblk_t *(*mac_ring_poll_t)(void *, int); 331 332 typedef int (*mac_ring_stat_t)(mac_ring_driver_t, uint_t, uint64_t *); 333 334 typedef struct mac_ring_info_s { 335 mac_ring_driver_t mri_driver; 336 mac_ring_start_t mri_start; 337 mac_ring_stop_t mri_stop; 338 mac_intr_t mri_intr; 339 union { 340 mac_ring_send_t send; 341 mac_ring_poll_t poll; 342 } mrfunion; 343 mac_ring_stat_t mri_stat; 344 /* 345 * mri_flags will have some bits set to indicate some special 346 * property/feature of a ring like serialization needed for a 347 * Tx ring or packets should always need enqueuing on Rx side, 348 * etc. 349 */ 350 uint_t mri_flags; 351 } mac_ring_info_s; 352 353 #define mri_tx mrfunion.send 354 #define mri_poll mrfunion.poll 355 356 /* 357 * #defines for mri_flags. The flags are temporary flags that are provided 358 * only to workaround issues in specific drivers, and they will be 359 * removed in the future. 360 */ 361 #define MAC_RING_TX_SERIALIZE 0x1 362 #define MAC_RING_RX_ENQUEUE 0x2 363 364 typedef int (*mac_group_start_t)(mac_group_driver_t); 365 typedef void (*mac_group_stop_t)(mac_group_driver_t); 366 typedef int (*mac_add_mac_addr_t)(void *, const uint8_t *); 367 typedef int (*mac_rem_mac_addr_t)(void *, const uint8_t *); 368 369 struct mac_group_info_s { 370 mac_group_driver_t mgi_driver; /* Driver reference */ 371 mac_group_start_t mgi_start; /* Start the group */ 372 mac_group_stop_t mgi_stop; /* Stop the group */ 373 uint_t mgi_count; /* Count of rings */ 374 mac_intr_t mgi_intr; /* Optional per-group intr */ 375 376 /* Only used for rx groups */ 377 mac_add_mac_addr_t mgi_addmac; /* Add a MAC address */ 378 mac_rem_mac_addr_t mgi_remmac; /* Remove a MAC address */ 379 }; 380 381 /* 382 * Share management functions. 383 */ 384 typedef uint64_t mac_share_handle_t; 385 386 /* 387 * Allocate and free a share. Returns ENOSPC if all shares have been 388 * previously allocated. 389 */ 390 typedef int (*mac_alloc_share_t)(void *, mac_share_handle_t *); 391 typedef void (*mac_free_share_t)(mac_share_handle_t); 392 393 /* 394 * Bind and unbind a share. Binding a share allows a domain 395 * to have direct access to the groups and rings associated with 396 * that share. 397 */ 398 typedef int (*mac_bind_share_t)(mac_share_handle_t, uint64_t, uint64_t *); 399 typedef void (*mac_unbind_share_t)(mac_share_handle_t); 400 401 /* 402 * Return information on about a share. 403 */ 404 typedef void (*mac_share_query_t)(mac_share_handle_t, mac_ring_type_t, 405 mac_ring_handle_t *, uint_t *); 406 407 /* 408 * Basic idea, bind previously created ring groups to shares 409 * for them to be exported (or shared) by another domain. 410 * These interfaces bind/unbind the ring group to a share. 411 * The groups and their rings will be shared with the guest 412 * as soon as the share is bound. 413 */ 414 typedef int (*mac_share_add_group_t)(mac_share_handle_t, 415 mac_group_driver_t); 416 typedef int (*mac_share_rem_group_t)(mac_share_handle_t, 417 mac_group_driver_t); 418 419 typedef struct mac_capab_share_s { 420 uint_t ms_snum; /* Number of shares (vr's) */ 421 void *ms_handle; /* Handle to driver. */ 422 mac_alloc_share_t ms_salloc; /* Get a share from driver. */ 423 mac_free_share_t ms_sfree; /* Return a share to driver. */ 424 mac_share_add_group_t ms_sadd; /* Add a group to the share. */ 425 mac_share_rem_group_t ms_sremove; /* Remove group from share. */ 426 mac_share_query_t ms_squery; /* Query share constraints */ 427 mac_bind_share_t ms_sbind; /* Bind a share */ 428 mac_unbind_share_t ms_sunbind; /* Unbind a share */ 429 } mac_capab_share_t; 430 431 typedef struct mac_capab_vrrp_s { 432 /* IPv6 or IPv4? */ 433 int mcv_af; 434 } mac_capab_vrrp_t; 435 436 /* 437 * Transceiver capability 438 */ 439 typedef struct mac_transceiver_info mac_transceiver_info_t; 440 441 typedef struct mac_capab_transceiver { 442 uint_t mct_flags; 443 uint_t mct_ntransceivers; 444 int (*mct_info)(void *, uint_t, mac_transceiver_info_t *); 445 int (*mct_read)(void *, uint_t, uint_t, void *, size_t, off_t, 446 size_t *); 447 } mac_capab_transceiver_t; 448 449 /* 450 * MAC registration interface 451 */ 452 typedef struct mac_register_s { 453 uint_t m_version; /* set by mac_alloc() */ 454 const char *m_type_ident; 455 void *m_driver; /* Driver private data */ 456 dev_info_t *m_dip; 457 uint_t m_instance; 458 uint8_t *m_src_addr; 459 uint8_t *m_dst_addr; 460 mac_callbacks_t *m_callbacks; 461 uint_t m_min_sdu; 462 uint_t m_max_sdu; 463 void *m_pdata; 464 size_t m_pdata_size; 465 char **m_priv_props; 466 uint32_t m_margin; 467 uint32_t m_v12n; /* Virtualization level */ 468 uint_t m_multicast_sdu; 469 } mac_register_t; 470 471 /* 472 * Driver interface functions. 473 */ 474 extern mac_protect_t *mac_protect_get(mac_handle_t); 475 extern void mac_sdu_get(mac_handle_t, uint_t *, uint_t *); 476 extern void mac_sdu_get2(mac_handle_t, uint_t *, uint_t *, 477 uint_t *); 478 extern int mac_maxsdu_update(mac_handle_t, uint_t); 479 extern int mac_maxsdu_update2(mac_handle_t, uint_t, 480 uint_t); 481 482 extern mac_register_t *mac_alloc(uint_t); 483 extern void mac_free(mac_register_t *); 484 extern int mac_register(mac_register_t *, mac_handle_t *); 485 extern int mac_disable_nowait(mac_handle_t); 486 extern int mac_disable(mac_handle_t); 487 extern int mac_unregister(mac_handle_t); 488 extern void mac_rx(mac_handle_t, mac_resource_handle_t, 489 mblk_t *); 490 extern void mac_rx_ring(mac_handle_t, mac_ring_handle_t, 491 mblk_t *, uint64_t); 492 extern void mac_link_update(mac_handle_t, link_state_t); 493 extern void mac_link_redo(mac_handle_t, link_state_t); 494 extern void mac_unicst_update(mac_handle_t, 495 const uint8_t *); 496 extern void mac_dst_update(mac_handle_t, const uint8_t *); 497 extern void mac_tx_update(mac_handle_t); 498 extern void mac_tx_ring_update(mac_handle_t, 499 mac_ring_handle_t); 500 extern void mac_capab_update(mac_handle_t); 501 extern int mac_pdata_update(mac_handle_t, void *, 502 size_t); 503 extern void mac_multicast_refresh(mac_handle_t, 504 mac_multicst_t, void *, boolean_t); 505 extern void mac_unicst_refresh(mac_handle_t, mac_unicst_t, 506 void *); 507 extern void mac_promisc_refresh(mac_handle_t, 508 mac_setpromisc_t, void *); 509 extern boolean_t mac_margin_update(mac_handle_t, uint32_t); 510 extern void mac_margin_get(mac_handle_t, uint32_t *); 511 extern int mac_margin_remove(mac_handle_t, uint32_t); 512 extern int mac_margin_add(mac_handle_t, uint32_t *, 513 boolean_t); 514 extern void mac_init_ops(struct dev_ops *, const char *); 515 extern void mac_fini_ops(struct dev_ops *); 516 extern int mac_devt_to_instance(dev_t); 517 extern minor_t mac_private_minor(void); 518 extern void mac_ring_intr_set(mac_ring_handle_t, 519 ddi_intr_handle_t); 520 521 522 extern mactype_register_t *mactype_alloc(uint_t); 523 extern void mactype_free(mactype_register_t *); 524 extern int mactype_register(mactype_register_t *); 525 extern int mactype_unregister(const char *); 526 527 extern boolean_t mac_unicst_verify(mac_handle_t, 528 const uint8_t *, uint_t); 529 530 extern int mac_group_add_ring(mac_group_handle_t, int); 531 extern void mac_group_rem_ring(mac_group_handle_t, 532 mac_ring_handle_t); 533 extern mac_ring_handle_t mac_find_ring(mac_group_handle_t, int); 534 535 extern void mac_prop_info_set_default_uint8( 536 mac_prop_info_handle_t, uint8_t); 537 extern void mac_prop_info_set_default_str( 538 mac_prop_info_handle_t, const char *); 539 extern void mac_prop_info_set_default_uint64( 540 mac_prop_info_handle_t, uint64_t); 541 extern void mac_prop_info_set_default_uint32( 542 mac_prop_info_handle_t, uint32_t); 543 extern void mac_prop_info_set_default_link_flowctrl( 544 mac_prop_info_handle_t, link_flowctrl_t); 545 extern void mac_prop_info_set_range_uint32( 546 mac_prop_info_handle_t, 547 uint32_t, uint32_t); 548 extern void mac_prop_info_set_perm(mac_prop_info_handle_t, 549 uint8_t); 550 551 extern void mac_hcksum_get(mblk_t *, uint32_t *, 552 uint32_t *, uint32_t *, uint32_t *, 553 uint32_t *); 554 extern void mac_hcksum_set(mblk_t *, uint32_t, uint32_t, 555 uint32_t, uint32_t, uint32_t); 556 557 extern void mac_lso_get(mblk_t *, uint32_t *, uint32_t *); 558 559 extern void mac_transceiver_info_set_present( 560 mac_transceiver_info_t *, 561 boolean_t); 562 extern void mac_transceiver_info_set_usable( 563 mac_transceiver_info_t *, 564 boolean_t); 565 566 #endif /* _KERNEL */ 567 568 #ifdef __cplusplus 569 } 570 #endif 571 572 #endif /* _SYS_MAC_PROVIDER_H */ 573