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_MAC_H 27 #define _SYS_MAC_H 28 29 #pragma ident "%Z%%M% %I% %E% SMI" 30 31 #include <sys/types.h> 32 #include <sys/ddi.h> 33 #include <sys/sunddi.h> 34 #include <sys/stream.h> 35 #include <sys/dld.h> 36 37 /* 38 * MAC Services Module 39 */ 40 41 #ifdef __cplusplus 42 extern "C" { 43 #endif 44 45 /* 46 * MAC Information (text emitted by modinfo(1m)) 47 */ 48 #define MAC_INFO "MAC Services v%I%" 49 50 /* 51 * MAC version identifier. This is used by mac_alloc() mac_register() to 52 * verify that incompatible drivers don't register. 53 */ 54 #define MAC_VERSION 0x1 55 56 /* 57 * MAC-Type version identifier. This is used by mactype_alloc() and 58 * mactype_register() to verify that incompatible MAC-Type plugins don't 59 * register. 60 */ 61 #define MACTYPE_VERSION 0x1 62 63 /* 64 * Statistics 65 */ 66 67 #define XCVR_UNDEFINED 0 68 #define XCVR_NONE 1 69 #define XCVR_10 2 70 #define XCVR_100T4 3 71 #define XCVR_100X 4 72 #define XCVR_100T2 5 73 #define XCVR_1000X 6 74 #define XCVR_1000T 7 75 76 typedef enum { 77 LINK_STATE_UNKNOWN = -1, 78 LINK_STATE_DOWN, 79 LINK_STATE_UP 80 } link_state_t; 81 82 typedef enum { 83 LINK_DUPLEX_UNKNOWN = 0, 84 LINK_DUPLEX_HALF, 85 LINK_DUPLEX_FULL 86 } link_duplex_t; 87 88 #define DATALINK_INVALID_LINKID 0 89 #define DATALINK_ALL_LINKID 0 90 #define DATALINK_MAX_LINKID 0xffffffff 91 92 typedef enum { 93 LINK_FLOWCTRL_NONE = 0, 94 LINK_FLOWCTRL_RX, 95 LINK_FLOWCTRL_TX, 96 LINK_FLOWCTRL_BI 97 } link_flowctrl_t; 98 99 /* 100 * Maximum MAC address length 101 */ 102 #define MAXMACADDRLEN 20 103 104 #ifdef _KERNEL 105 106 typedef struct mac_stat_info_s { 107 uint_t msi_stat; 108 char *msi_name; 109 uint_t msi_type; /* as defined in kstat_named_init(9F) */ 110 uint64_t msi_default; 111 } mac_stat_info_t; 112 113 /* 114 * There are three ranges of statistics values. 0 to 1 - MAC_STAT_MIN are 115 * interface statistics maintained by the mac module. MAC_STAT_MIN to 1 - 116 * MACTYPE_STAT_MIN are common MAC statistics defined by the mac module and 117 * maintained by each driver. MACTYPE_STAT_MIN and above are statistics 118 * defined by MAC-Type plugins and maintained by each driver. 119 */ 120 #define MAC_STAT_MIN 1000 121 #define MACTYPE_STAT_MIN 2000 122 123 #define IS_MAC_STAT(stat) \ 124 (stat >= MAC_STAT_MIN && stat < MACTYPE_STAT_MIN) 125 #define IS_MACTYPE_STAT(stat) (stat >= MACTYPE_STAT_MIN) 126 127 /* 128 * Statistics maintained by the mac module, and possibly populated as link 129 * statistics. 130 */ 131 enum mac_mod_stat { 132 MAC_STAT_LINK_STATE, 133 MAC_STAT_LINK_UP, 134 MAC_STAT_PROMISC 135 }; 136 137 /* 138 * Do not reorder, and add only to the end of this list. 139 */ 140 enum mac_driver_stat { 141 /* MIB-II stats (RFC 1213 and RFC 1573) */ 142 MAC_STAT_IFSPEED = MAC_STAT_MIN, 143 MAC_STAT_MULTIRCV, 144 MAC_STAT_BRDCSTRCV, 145 MAC_STAT_MULTIXMT, 146 MAC_STAT_BRDCSTXMT, 147 MAC_STAT_NORCVBUF, 148 MAC_STAT_IERRORS, 149 MAC_STAT_UNKNOWNS, 150 MAC_STAT_NOXMTBUF, 151 MAC_STAT_OERRORS, 152 MAC_STAT_COLLISIONS, 153 MAC_STAT_RBYTES, 154 MAC_STAT_IPACKETS, 155 MAC_STAT_OBYTES, 156 MAC_STAT_OPACKETS, 157 MAC_STAT_UNDERFLOWS, 158 MAC_STAT_OVERFLOWS 159 }; 160 161 #define MAC_NSTAT (MAC_STAT_OVERFLOWS - MAC_STAT_IFSPEED + 1) 162 163 #define MAC_STAT_ISACOUNTER(_stat) ( \ 164 (_stat) == MAC_STAT_MULTIRCV || \ 165 (_stat) == MAC_STAT_BRDCSTRCV || \ 166 (_stat) == MAC_STAT_MULTIXMT || \ 167 (_stat) == MAC_STAT_BRDCSTXMT || \ 168 (_stat) == MAC_STAT_NORCVBUF || \ 169 (_stat) == MAC_STAT_IERRORS || \ 170 (_stat) == MAC_STAT_UNKNOWNS || \ 171 (_stat) == MAC_STAT_NOXMTBUF || \ 172 (_stat) == MAC_STAT_OERRORS || \ 173 (_stat) == MAC_STAT_COLLISIONS || \ 174 (_stat) == MAC_STAT_RBYTES || \ 175 (_stat) == MAC_STAT_IPACKETS || \ 176 (_stat) == MAC_STAT_OBYTES || \ 177 (_stat) == MAC_STAT_OPACKETS || \ 178 (_stat) == MAC_STAT_UNDERFLOWS || \ 179 (_stat) == MAC_STAT_OVERFLOWS) 180 181 /* 182 * Immutable information. (This may not be modified after registration). 183 */ 184 typedef struct mac_info_s { 185 uint_t mi_media; 186 uint_t mi_nativemedia; 187 uint_t mi_addr_length; 188 uint8_t *mi_unicst_addr; 189 uint8_t *mi_brdcst_addr; 190 } mac_info_t; 191 192 /* 193 * LSO capability 194 */ 195 typedef struct lso_basic_tcp_ipv4_s { 196 t_uscalar_t lso_max; /* maximum payload */ 197 } lso_basic_tcp_ipv4_t; 198 199 /* 200 * Future LSO capabilities can be added at the end of the mac_capab_lso_t. 201 * When such capability is added to the GLDv3 framework, the size of the 202 * mac_capab_lso_t it allocates and passes to the drivers increases. Older 203 * drivers wil access only the (upper) sections of that structure, that is the 204 * sections carrying the capabilities they understand. This ensures the 205 * interface can be safely extended in a binary compatible way. 206 */ 207 typedef struct mac_capab_lso_s { 208 t_uscalar_t lso_flags; 209 lso_basic_tcp_ipv4_t lso_basic_tcp_ipv4; 210 /* Add future lso capabilities here */ 211 } mac_capab_lso_t; 212 213 /* 214 * Information for legacy devices. 215 */ 216 typedef struct mac_capab_legacy_s { 217 /* 218 * Notifications that the legacy device does not support. 219 */ 220 uint32_t ml_unsup_note; 221 /* 222 * dev_t of the legacy device; can be held to force attach. 223 */ 224 dev_t ml_dev; 225 } mac_capab_legacy_t; 226 227 /* 228 * MAC layer capabilities. These capabilities are handled by the drivers' 229 * mc_capab_get() callbacks. Some capabilities require the driver to fill 230 * in a given data structure, and others are simply boolean capabilities. 231 * Note that capability values must be powers of 2 so that consumers and 232 * providers of this interface can keep track of which capabilities they 233 * care about by keeping a bitfield of these things around somewhere. 234 */ 235 typedef enum { 236 MAC_CAPAB_HCKSUM = 0x01, /* data is a uint32_t for the txflags */ 237 MAC_CAPAB_POLL = 0x02, /* boolean only, no data */ 238 MAC_CAPAB_MULTIADDRESS = 0x04, /* data is multiaddress_capab_t */ 239 MAC_CAPAB_LSO = 0x08, /* data is mac_capab_lso_t */ 240 MAC_CAPAB_NO_NATIVEVLAN = 0x10, /* boolean only, no data */ 241 MAC_CAPAB_NO_ZCOPY = 0x20, /* boolean only, no data */ 242 /* add new capabilities here */ 243 MAC_CAPAB_RINGS = 0x100, /* data is mac_capab_rings_t */ 244 MAC_CAPAB_SHARES = 0x200, /* data is mac_capab_share_t */ 245 246 /* The following capabilities are specific to softmac. */ 247 MAC_CAPAB_LEGACY = 0x8001, /* data is mac_capab_legacy_t */ 248 } mac_capab_t; 249 250 typedef int mac_addr_slot_t; 251 252 /* mma_flags values */ 253 #define MMAC_SLOT_USED 0x1 /* address slot used */ 254 #define MMAC_SLOT_UNUSED 0x2 /* free address slot */ 255 #define MMAC_VENDOR_ADDR 0x4 /* address returned is vendor supplied */ 256 257 typedef struct mac_multi_address_s { 258 mac_addr_slot_t mma_slot; /* slot for add/remove/get/set */ 259 uint_t mma_addrlen; 260 uint8_t mma_addr[MAXMACADDRLEN]; 261 uint_t mma_flags; 262 } mac_multi_addr_t; 263 264 typedef int (*maddr_reserve_t)(void *, mac_multi_addr_t *); 265 typedef int (*maddr_add_t)(void *, mac_multi_addr_t *); 266 typedef int (*maddr_remove_t)(void *, mac_addr_slot_t); 267 typedef int (*maddr_modify_t)(void *, mac_multi_addr_t *); 268 typedef int (*maddr_get_t)(void *, mac_multi_addr_t *); 269 270 /* maddr_flag values */ 271 #define MADDR_VENDOR_ADDR 0x01 /* addr returned is vendor supplied */ 272 273 /* multiple mac address: add/remove/set/get mac address */ 274 typedef struct multiaddress_capab_s { 275 int maddr_naddr; /* total addresses */ 276 int maddr_naddrfree; /* free address slots */ 277 uint_t maddr_flag; /* MADDR_VENDOR_ADDR bit can be set */ 278 /* driver entry points */ 279 void *maddr_handle; /* cookie to be used for the calls */ 280 maddr_reserve_t maddr_reserve; /* reserve a factory address */ 281 maddr_add_t maddr_add; /* add a new unicst address */ 282 maddr_remove_t maddr_remove; /* remove an added address */ 283 maddr_modify_t maddr_modify; /* modify an added address */ 284 maddr_get_t maddr_get; /* get address from specified slot */ 285 } multiaddress_capab_t; 286 287 /* 288 * MAC driver entry point types. 289 */ 290 typedef int (*mac_getstat_t)(void *, uint_t, uint64_t *); 291 typedef int (*mac_start_t)(void *); 292 typedef void (*mac_stop_t)(void *); 293 typedef int (*mac_setpromisc_t)(void *, boolean_t); 294 typedef int (*mac_multicst_t)(void *, boolean_t, const uint8_t *); 295 typedef int (*mac_unicst_t)(void *, const uint8_t *); 296 typedef void (*mac_ioctl_t)(void *, queue_t *, mblk_t *); 297 typedef void (*mac_resources_t)(void *); 298 typedef mblk_t *(*mac_tx_t)(void *, mblk_t *); 299 typedef boolean_t (*mac_getcapab_t)(void *, mac_capab_t, void *); 300 typedef int (*mac_open_t)(void *); 301 typedef void (*mac_close_t)(void *); 302 typedef int (*mac_set_prop_t)(void *, const char *, mac_prop_id_t, 303 uint_t, const void *); 304 typedef int (*mac_get_prop_t)(void *, const char *, mac_prop_id_t, 305 uint_t, void *); 306 307 /* 308 * Drivers must set all of these callbacks except for mc_resources, 309 * mc_ioctl, and mc_getcapab, which are optional. If any of these optional 310 * callbacks are set, their appropriate flags must be set in mc_callbacks. 311 * Any future additions to this list must also be accompanied by an 312 * associated mc_callbacks flag so that the framework can grow without 313 * affecting the binary compatibility of the interface. 314 */ 315 typedef struct mac_callbacks_s { 316 uint_t mc_callbacks; /* Denotes which callbacks are set */ 317 mac_getstat_t mc_getstat; /* Get the value of a statistic */ 318 mac_start_t mc_start; /* Start the device */ 319 mac_stop_t mc_stop; /* Stop the device */ 320 mac_setpromisc_t mc_setpromisc; /* Enable or disable promiscuous mode */ 321 mac_multicst_t mc_multicst; /* Enable or disable a multicast addr */ 322 mac_unicst_t mc_unicst; /* Set the unicast MAC address */ 323 mac_tx_t mc_tx; /* Transmit a packet */ 324 mac_resources_t mc_resources; /* Get the device resources */ 325 mac_ioctl_t mc_ioctl; /* Process an unknown ioctl */ 326 mac_getcapab_t mc_getcapab; /* Get capability information */ 327 mac_open_t mc_open; /* Open the device */ 328 mac_close_t mc_close; /* Close the device */ 329 mac_set_prop_t mc_setprop; 330 mac_get_prop_t mc_getprop; 331 } mac_callbacks_t; 332 333 /* 334 * Multiple Rings capability 335 */ 336 typedef enum { 337 MAC_RING_TYPE_RX = 1, /* Receive ring */ 338 MAC_RING_TYPE_TX = 2 /* Transmit ring */ 339 } mac_ring_type_t; 340 341 /* 342 * Grouping type of a ring group 343 * 344 * MAC_GROUP_TYPE_STATIC: The ring group can not be re-grouped. 345 * MAC_GROUP_TYPE_DYNAMIC: The ring group support dynamic re-grouping 346 */ 347 typedef enum { 348 MAC_GROUP_TYPE_STATIC = 1, /* Static ring group */ 349 MAC_GROUP_TYPE_DYNAMIC = 2 /* Dynamic ring group */ 350 } mac_group_type_t; 351 352 typedef struct __mac_ring_driver *mac_ring_driver_t; 353 typedef struct __mac_ring_handle *mac_ring_handle_t; 354 typedef struct __mac_group_driver *mac_group_driver_t; 355 typedef struct __mac_group_handle *mac_group_handle_t; 356 typedef struct __mac_intr_handle *mac_intr_handle_t; 357 358 typedef struct mac_ring_info_s mac_ring_info_t; 359 typedef struct mac_group_info_s mac_group_info_t; 360 361 typedef int (*mac_intr_enable_t)(mac_intr_handle_t); 362 typedef int (*mac_intr_disable_t)(mac_intr_handle_t); 363 364 typedef struct mac_intr_s { 365 mac_intr_handle_t mi_handle; 366 mac_intr_enable_t mi_enable; 367 mac_intr_disable_t mi_disable; 368 } mac_intr_t; 369 370 typedef void (*mac_get_ring_t)(void *, mac_ring_type_t, const int, const int, 371 mac_ring_info_t *, mac_ring_handle_t); 372 typedef void (*mac_get_group_t)(void *, mac_ring_type_t, const int, 373 mac_group_info_t *, mac_group_handle_t); 374 375 typedef void (*mac_group_add_ring_t)(mac_group_driver_t, 376 mac_ring_driver_t, mac_ring_type_t); 377 typedef void (*mac_group_rem_ring_t)(mac_group_driver_t, 378 mac_ring_driver_t, mac_ring_type_t); 379 380 /* 381 * Multiple Rings Capability 382 */ 383 typedef struct mac_capab_rings_s { 384 mac_ring_type_t mr_type; /* Ring type */ 385 mac_group_type_t mr_group_type; /* Grouping type */ 386 void *mr_handle; /* Group Driver Handle. */ 387 uint_t mr_rnum; /* Number of rings */ 388 uint_t mr_gnum; /* Number of ring groups */ 389 mac_get_ring_t mr_rget; /* Get ring from driver */ 390 mac_get_group_t mr_gget; /* Get ring group from driver */ 391 mac_group_add_ring_t mr_gadd_ring; /* Add ring into a group */ 392 mac_group_rem_ring_t mr_grem_ring; /* Remove ring from a group */ 393 } mac_capab_rings_t; 394 395 /* 396 * Common ring functions and driver interfaces 397 */ 398 typedef int (*mac_ring_start_t)(mac_ring_driver_t); 399 typedef void (*mac_ring_stop_t)(mac_ring_driver_t); 400 401 typedef mblk_t *(*mac_ring_send_t)(void *, mblk_t *); 402 typedef mblk_t *(*mac_ring_poll_t)(void *, int); 403 404 typedef struct mac_ring_info_s { 405 mac_ring_driver_t mr_driver; 406 mac_ring_start_t mr_start; 407 mac_ring_stop_t mr_stop; 408 mac_intr_t mr_intr; 409 union { 410 mac_ring_send_t send; 411 mac_ring_poll_t poll; 412 } mrfunion; 413 } mac_ring_info_s; 414 415 #define mr_send mrfunion.send 416 #define mr_poll mrfunion.poll 417 418 typedef int (*mac_group_start_t)(mac_group_driver_t); 419 typedef void (*mac_group_stop_t)(mac_group_driver_t); 420 typedef int (*mac_add_mac_addr_t)(void *, const uint8_t *); 421 typedef int (*mac_rem_mac_addr_t)(void *, const uint8_t *); 422 423 struct mac_group_info_s { 424 mac_group_driver_t mrg_driver; /* Driver reference */ 425 mac_group_start_t mrg_start; /* Start the group */ 426 mac_group_stop_t mrg_stop; /* Stop the group */ 427 uint_t mrg_count; /* Count of rings */ 428 mac_intr_t mrg_intr; /* Optional per-group intr */ 429 430 /* Only used for rx groups */ 431 mac_add_mac_addr_t mrg_addmac; /* Add a MAC address */ 432 mac_rem_mac_addr_t mrg_remmac; /* Remove a MAC address */ 433 }; 434 435 /* 436 * Share management functions. 437 */ 438 typedef uint64_t mac_share_handle_t; 439 440 /* 441 * Returns a Share handle to the client calling from above. 442 */ 443 typedef int (*mac_alloc_share_t)(void *, uint64_t cookie, 444 uint64_t *rcookie, mac_share_handle_t *); 445 446 /* 447 * Destroys the share previously allocated and unallocates 448 * all share resources (e.g. DMA's assigned to the share). 449 */ 450 typedef void (*mac_free_share_t)(mac_share_handle_t); 451 452 typedef void (*mac_share_query_t)(mac_share_handle_t shdl, 453 mac_ring_type_t type, uint32_t *rmin, uint32_t *rmax, 454 uint64_t *rmap, uint64_t *gnum); 455 456 /* 457 * Basic idea, bind previously created ring groups to shares 458 * for them to be exported (or shared) by another domain. 459 * These interfaces bind/unbind the ring group to a share. The 460 * of doing such causes the resources to be shared with the guest. 461 */ 462 typedef int (*mac_share_add_group_t)(mac_share_handle_t, 463 mac_group_handle_t); 464 typedef int (*mac_share_rem_group_t)(mac_share_handle_t, 465 mac_group_handle_t); 466 467 typedef struct mac_capab_share_s { 468 uint_t ms_snum; /* Number of shares (vr's) */ 469 void *ms_handle; /* Handle to driver. */ 470 mac_alloc_share_t ms_salloc; /* Get a share from driver. */ 471 mac_free_share_t ms_sfree; /* Return a share to driver. */ 472 mac_share_add_group_t ms_sadd; /* Add a group to the share. */ 473 mac_share_rem_group_t ms_sremove; /* Remove group from share. */ 474 mac_share_query_t ms_squery; /* Query share constraints */ 475 } mac_capab_share_t; 476 477 /* 478 * Flags for mc_callbacks. Requiring drivers to set the flags associated 479 * with optional callbacks initialized in the structure allows the mac 480 * module to add optional callbacks in the future without requiring drivers 481 * to recompile. 482 */ 483 #define MC_RESOURCES 0x001 484 #define MC_IOCTL 0x002 485 #define MC_GETCAPAB 0x004 486 #define MC_OPEN 0x008 487 #define MC_CLOSE 0x010 488 #define MC_SETPROP 0x020 489 #define MC_GETPROP 0x040 490 491 #define MAC_MAX_MINOR 1000 492 493 typedef struct mac_register_s { 494 uint_t m_version; /* set by mac_alloc() */ 495 const char *m_type_ident; 496 void *m_driver; /* Driver private data */ 497 dev_info_t *m_dip; 498 uint_t m_instance; 499 uint8_t *m_src_addr; 500 uint8_t *m_dst_addr; 501 mac_callbacks_t *m_callbacks; 502 uint_t m_min_sdu; 503 uint_t m_max_sdu; 504 void *m_pdata; 505 size_t m_pdata_size; 506 uint32_t m_margin; 507 } mac_register_t; 508 509 /* 510 * Opaque handle types. 511 */ 512 typedef struct mac_t *mac_handle_t; 513 typedef struct __mac_notify_handle *mac_notify_handle_t; 514 typedef struct __mac_rx_handle *mac_rx_handle_t; 515 typedef struct __mac_txloop_handle *mac_txloop_handle_t; 516 typedef struct __mac_resource_handle *mac_resource_handle_t; 517 518 /* 519 * MAC interface callback types. 520 */ 521 typedef enum { 522 MAC_NOTE_LINK, 523 MAC_NOTE_PROMISC, 524 MAC_NOTE_UNICST, 525 MAC_NOTE_TX, 526 MAC_NOTE_RESOURCE, 527 MAC_NOTE_DEVPROMISC, 528 MAC_NOTE_FASTPATH_FLUSH, 529 MAC_NOTE_SDU_SIZE, 530 MAC_NOTE_VNIC, 531 MAC_NOTE_MARGIN, 532 MAC_NNOTE /* must be the last entry */ 533 } mac_notify_type_t; 534 535 typedef void (*mac_notify_t)(void *, mac_notify_type_t); 536 typedef void (*mac_rx_t)(void *, mac_resource_handle_t, mblk_t *); 537 typedef void (*mac_txloop_t)(void *, mblk_t *); 538 typedef void (*mac_blank_t)(void *, time_t, uint_t); 539 540 /* 541 * MAC promiscuous types 542 */ 543 typedef enum { 544 MAC_PROMISC = 0x01, /* MAC instance is promiscuous */ 545 MAC_DEVPROMISC = 0x02 /* Device is promiscuous */ 546 } mac_promisc_type_t; 547 548 /* 549 * MAC resource types 550 */ 551 typedef enum { 552 MAC_RX_FIFO = 1 553 } mac_resource_type_t; 554 555 typedef struct mac_rx_fifo_s { 556 mac_resource_type_t mrf_type; /* MAC_RX_FIFO */ 557 mac_blank_t mrf_blank; 558 void *mrf_arg; 559 time_t mrf_normal_blank_time; 560 uint_t mrf_normal_pkt_count; 561 } mac_rx_fifo_t; 562 563 typedef struct mac_txinfo_s { 564 mac_tx_t mt_fn; 565 void *mt_arg; 566 } mac_txinfo_t; 567 568 typedef union mac_resource_u { 569 mac_resource_type_t mr_type; 570 mac_rx_fifo_t mr_fifo; 571 } mac_resource_t; 572 573 typedef mac_resource_handle_t (*mac_resource_add_t)(void *, mac_resource_t *); 574 575 typedef enum { 576 MAC_ADDRTYPE_UNICAST, 577 MAC_ADDRTYPE_MULTICAST, 578 MAC_ADDRTYPE_BROADCAST 579 } mac_addrtype_t; 580 581 typedef struct mac_header_info_s { 582 size_t mhi_hdrsize; 583 size_t mhi_pktsize; 584 const uint8_t *mhi_daddr; 585 const uint8_t *mhi_saddr; 586 uint32_t mhi_origsap; 587 uint32_t mhi_bindsap; 588 mac_addrtype_t mhi_dsttype; 589 uint16_t mhi_tci; 590 uint_t mhi_istagged:1, 591 mhi_prom_looped:1; 592 } mac_header_info_t; 593 594 /* 595 * MAC-Type plugin interfaces 596 */ 597 598 typedef int (*mtops_addr_verify_t)(const void *, void *); 599 typedef boolean_t (*mtops_sap_verify_t)(uint32_t, uint32_t *, void *); 600 typedef mblk_t *(*mtops_header_t)(const void *, const void *, 601 uint32_t, void *, mblk_t *, size_t); 602 typedef int (*mtops_header_info_t)(mblk_t *, void *, 603 mac_header_info_t *); 604 typedef boolean_t (*mtops_pdata_verify_t)(void *, size_t); 605 typedef mblk_t *(*mtops_header_modify_t)(mblk_t *, void *); 606 typedef void (*mtops_link_details_t)(char *, size_t, mac_handle_t, 607 void *); 608 609 typedef struct mactype_ops_s { 610 uint_t mtops_ops; 611 /* 612 * mtops_unicst_verify() returns 0 if the given address is a valid 613 * unicast address, or a non-zero errno otherwise. 614 */ 615 mtops_addr_verify_t mtops_unicst_verify; 616 /* 617 * mtops_multicst_verify() returns 0 if the given address is a 618 * valid multicast address, or a non-zero errno otherwise. If the 619 * media doesn't support multicast, ENOTSUP should be returned (for 620 * example). 621 */ 622 mtops_addr_verify_t mtops_multicst_verify; 623 /* 624 * mtops_sap_verify() returns B_TRUE if the given SAP is a valid 625 * SAP value, or B_FALSE otherwise. 626 */ 627 mtops_sap_verify_t mtops_sap_verify; 628 /* 629 * mtops_header() is used to allocate and construct a MAC header. 630 */ 631 mtops_header_t mtops_header; 632 /* 633 * mtops_header_info() is used to gather information on a given MAC 634 * header. 635 */ 636 mtops_header_info_t mtops_header_info; 637 /* 638 * mtops_pdata_verify() is used to verify the validity of MAC 639 * plugin data. It is called by mac_register() if the driver has 640 * supplied MAC plugin data, and also by mac_pdata_update() when 641 * drivers update the data. 642 */ 643 mtops_pdata_verify_t mtops_pdata_verify; 644 /* 645 * mtops_header_cook() is an optional callback that converts (or 646 * "cooks") the given raw header (as sent by a raw DLPI consumer) 647 * into one that is appropriate to send down to the MAC driver. 648 * Following the example above, an Ethernet header sent down by a 649 * DLPI consumer would be converted to whatever header the MAC 650 * driver expects. 651 */ 652 mtops_header_modify_t mtops_header_cook; 653 /* 654 * mtops_header_uncook() is an optional callback that does the 655 * opposite of mtops_header_cook(). It "uncooks" a given MAC 656 * header (as received from the driver) for consumption by raw DLPI 657 * consumers. For example, for a non-Ethernet plugin that wants 658 * raw DLPI consumers to be fooled into thinking that the device 659 * provides Ethernet access, this callback would modify the given 660 * mblk_t such that the MAC header is converted to an Ethernet 661 * header. 662 */ 663 mtops_header_modify_t mtops_header_uncook; 664 /* 665 * mtops_link_details() is an optional callback that provides 666 * extended information about the link state. Its primary purpose 667 * is to provide type-specific support for syslog contents on 668 * link up events. If no implementation is provided, then a default 669 * implementation will be used. 670 */ 671 mtops_link_details_t mtops_link_details; 672 } mactype_ops_t; 673 674 /* 675 * mtops_ops exists for the plugin to enumerate the optional callback 676 * entrypoints it has defined. This allows the mac module to define 677 * additional plugin entrypoints in mactype_ops_t without breaking backward 678 * compatibility with old plugins. 679 */ 680 #define MTOPS_PDATA_VERIFY 0x001 681 #define MTOPS_HEADER_COOK 0x002 682 #define MTOPS_HEADER_UNCOOK 0x004 683 #define MTOPS_LINK_DETAILS 0x008 684 685 typedef struct mactype_register_s { 686 uint_t mtr_version; /* set by mactype_alloc() */ 687 const char *mtr_ident; 688 mactype_ops_t *mtr_ops; 689 uint_t mtr_mactype; 690 uint_t mtr_nativetype; 691 uint_t mtr_addrlen; 692 uint8_t *mtr_brdcst_addr; 693 mac_stat_info_t *mtr_stats; 694 size_t mtr_statcount; 695 } mactype_register_t; 696 697 typedef struct mac_prop_s { 698 mac_prop_id_t mp_id; 699 char *mp_name; 700 } mac_prop_t; 701 702 /* 703 * Client interface functions. 704 */ 705 extern int mac_open(const char *, mac_handle_t *); 706 extern int mac_open_by_linkid(datalink_id_t, 707 mac_handle_t *); 708 extern int mac_open_by_linkname(const char *, 709 mac_handle_t *); 710 extern void mac_close(mac_handle_t); 711 extern const mac_info_t *mac_info(mac_handle_t); 712 extern boolean_t mac_info_get(const char *, mac_info_t *); 713 extern uint64_t mac_stat_get(mac_handle_t, uint_t); 714 extern int mac_start(mac_handle_t); 715 extern void mac_stop(mac_handle_t); 716 extern int mac_promisc_set(mac_handle_t, boolean_t, 717 mac_promisc_type_t); 718 extern boolean_t mac_promisc_get(mac_handle_t, 719 mac_promisc_type_t); 720 extern int mac_multicst_add(mac_handle_t, const uint8_t *); 721 extern int mac_multicst_remove(mac_handle_t, 722 const uint8_t *); 723 extern boolean_t mac_unicst_verify(mac_handle_t, 724 const uint8_t *, uint_t); 725 extern int mac_unicst_set(mac_handle_t, const uint8_t *); 726 extern void mac_unicst_get(mac_handle_t, uint8_t *); 727 extern void mac_dest_get(mac_handle_t, uint8_t *); 728 extern void mac_sdu_get(mac_handle_t, uint_t *, uint_t *); 729 extern void mac_resources(mac_handle_t); 730 extern void mac_ioctl(mac_handle_t, queue_t *, mblk_t *); 731 extern const mac_txinfo_t *mac_tx_get(mac_handle_t); 732 extern const mac_txinfo_t *mac_vnic_tx_get(mac_handle_t); 733 extern link_state_t mac_link_get(mac_handle_t); 734 extern mac_notify_handle_t mac_notify_add(mac_handle_t, mac_notify_t, 735 void *); 736 extern void mac_notify_remove(mac_handle_t, 737 mac_notify_handle_t); 738 extern void mac_notify(mac_handle_t); 739 extern mac_rx_handle_t mac_rx_add(mac_handle_t, mac_rx_t, void *); 740 extern mac_rx_handle_t mac_active_rx_add(mac_handle_t, mac_rx_t, 741 void *); 742 extern void mac_rx_remove(mac_handle_t, mac_rx_handle_t, 743 boolean_t); 744 extern void mac_rx_remove_wait(mac_handle_t); 745 extern mblk_t *mac_txloop(void *, mblk_t *); 746 extern mac_txloop_handle_t mac_txloop_add(mac_handle_t, mac_txloop_t, 747 void *); 748 extern void mac_txloop_remove(mac_handle_t, 749 mac_txloop_handle_t); 750 extern boolean_t mac_active_set(mac_handle_t); 751 extern boolean_t mac_active_shareable_set(mac_handle_t); 752 extern void mac_active_clear(mac_handle_t); 753 extern void mac_active_rx(void *, mac_resource_handle_t, 754 mblk_t *); 755 extern boolean_t mac_vnic_set(mac_handle_t, mac_txinfo_t *, 756 mac_getcapab_t, void *); 757 extern void mac_vnic_clear(mac_handle_t); 758 extern void mac_resource_set(mac_handle_t, 759 mac_resource_add_t, void *); 760 extern dev_info_t *mac_devinfo_get(mac_handle_t); 761 extern const char *mac_name(mac_handle_t); 762 extern minor_t mac_minor(mac_handle_t); 763 extern boolean_t mac_capab_get(mac_handle_t, mac_capab_t, 764 void *); 765 extern boolean_t mac_vnic_capab_get(mac_handle_t, mac_capab_t, 766 void *); 767 extern boolean_t mac_sap_verify(mac_handle_t, uint32_t, 768 uint32_t *); 769 extern mblk_t *mac_header(mac_handle_t, const uint8_t *, 770 uint32_t, mblk_t *, size_t); 771 extern int mac_header_info(mac_handle_t, mblk_t *, 772 mac_header_info_t *); 773 extern mblk_t *mac_header_cook(mac_handle_t, mblk_t *); 774 extern mblk_t *mac_header_uncook(mac_handle_t, mblk_t *); 775 extern minor_t mac_minor_hold(boolean_t); 776 extern void mac_minor_rele(minor_t); 777 778 /* 779 * Driver interface functions. 780 */ 781 extern mac_register_t *mac_alloc(uint_t); 782 extern void mac_free(mac_register_t *); 783 extern int mac_register(mac_register_t *, mac_handle_t *); 784 extern int mac_disable(mac_handle_t); 785 extern int mac_unregister(mac_handle_t); 786 extern void mac_rx(mac_handle_t, mac_resource_handle_t, 787 mblk_t *); 788 extern void mac_link_update(mac_handle_t, link_state_t); 789 extern void mac_unicst_update(mac_handle_t, 790 const uint8_t *); 791 extern void mac_tx_update(mac_handle_t); 792 extern void mac_resource_update(mac_handle_t); 793 extern mac_resource_handle_t mac_resource_add(mac_handle_t, 794 mac_resource_t *); 795 extern int mac_maxsdu_update(mac_handle_t, uint_t); 796 extern int mac_pdata_update(mac_handle_t, void *, 797 size_t); 798 extern void mac_multicst_refresh(mac_handle_t, 799 mac_multicst_t, void *, boolean_t); 800 extern void mac_unicst_refresh(mac_handle_t, mac_unicst_t, 801 void *); 802 extern void mac_promisc_refresh(mac_handle_t, 803 mac_setpromisc_t, void *); 804 extern boolean_t mac_margin_update(mac_handle_t, uint32_t); 805 extern void mac_margin_get(mac_handle_t, uint32_t *); 806 extern int mac_margin_remove(mac_handle_t, uint32_t); 807 extern int mac_margin_add(mac_handle_t, uint32_t *, 808 boolean_t); 809 extern void mac_init_ops(struct dev_ops *, const char *); 810 extern void mac_fini_ops(struct dev_ops *); 811 extern uint32_t mac_no_notification(mac_handle_t); 812 extern boolean_t mac_is_legacy(mac_handle_t); 813 extern int mac_hold_exclusive(mac_handle_t); 814 extern void mac_rele_exclusive(mac_handle_t); 815 816 extern mactype_register_t *mactype_alloc(uint_t); 817 extern void mactype_free(mactype_register_t *); 818 extern int mactype_register(mactype_register_t *); 819 extern int mactype_unregister(const char *); 820 extern int mac_set_prop(mac_handle_t, mac_prop_t *, 821 void *, uint_t); 822 extern int mac_get_prop(mac_handle_t, mac_prop_t *, 823 void *, uint_t); 824 825 #endif /* _KERNEL */ 826 827 #ifdef __cplusplus 828 } 829 #endif 830 831 #endif /* _SYS_MAC_H */ 832