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 2009 Sun Microsystems, Inc. All rights reserved. 24 * Use is subject to license terms. 25 */ 26 27 #ifndef _SYS_MAC_H 28 #define _SYS_MAC_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 36 /* 37 * MAC Services Module 38 */ 39 40 #ifdef __cplusplus 41 extern "C" { 42 #endif 43 44 /* 45 * MAC Information (text emitted by modinfo(1m)) 46 */ 47 #define MAC_INFO "MAC Services v1.20" 48 49 /* 50 * MAC-Type version identifier. This is used by mactype_alloc() and 51 * mactype_register() to verify that incompatible MAC-Type plugins don't 52 * register. 53 */ 54 #define MACTYPE_VERSION 0x1 55 56 /* 57 * Opaque handle types 58 */ 59 typedef struct __mac_handle *mac_handle_t; 60 typedef struct __mac_resource_handle *mac_resource_handle_t; 61 typedef struct __mac_notify_handle *mac_notify_handle_t; 62 typedef struct __mac_tx_notify_handle *mac_tx_notify_handle_t; 63 typedef struct __mac_intr_handle *mac_intr_handle_t; 64 typedef struct __mac_ring_handle *mac_ring_handle_t; 65 typedef struct __mac_group_handle *mac_group_handle_t; 66 67 #define DATALINK_INVALID_LINKID 0 68 #define DATALINK_ALL_LINKID 0 69 #define DATALINK_MAX_LINKID 0xffffffff 70 71 #define MAC_MAX_MINOR 1000 72 73 typedef enum { 74 LINK_STATE_UNKNOWN = -1, 75 LINK_STATE_DOWN, 76 LINK_STATE_UP 77 } link_state_t; 78 79 typedef enum { 80 LINK_DUPLEX_UNKNOWN = 0, 81 LINK_DUPLEX_HALF, 82 LINK_DUPLEX_FULL 83 } link_duplex_t; 84 85 typedef enum { 86 LINK_FLOWCTRL_NONE = 0, 87 LINK_FLOWCTRL_RX, 88 LINK_FLOWCTRL_TX, 89 LINK_FLOWCTRL_BI 90 } link_flowctrl_t; 91 92 typedef enum { 93 LINK_TAGMODE_VLANONLY = 0, 94 LINK_TAGMODE_NORMAL 95 } link_tagmode_t; 96 97 /* 98 * Maximum MAC address length 99 */ 100 #define MAXMACADDRLEN 20 101 102 typedef enum { 103 MAC_LOGTYPE_LINK = 1, 104 MAC_LOGTYPE_FLOW 105 } mac_logtype_t; 106 107 /* 108 * Encodings for public properties. 109 * A most significant bit value of 1 indicates private property, intended 110 * to allow private property implementations to use internal encodings 111 * if desired. 112 * 113 * Note that there are 2 sets of parameters: the *_EN_* 114 * values are those that the Administrator configures for autonegotiation. 115 * The _ADV_* values are those that are currently exposed over the wire. 116 */ 117 #define MAXLINKPROPNAME 256 118 #define MAC_PROP_DEFAULT 0x0001 119 typedef enum { 120 MAC_PROP_DUPLEX = 0x00000001, 121 MAC_PROP_SPEED, 122 MAC_PROP_STATUS, 123 MAC_PROP_AUTONEG, 124 MAC_PROP_EN_AUTONEG, 125 MAC_PROP_MTU, 126 MAC_PROP_ZONE, 127 MAC_PROP_AUTOPUSH, 128 MAC_PROP_FLOWCTRL, 129 MAC_PROP_ADV_1000FDX_CAP, 130 MAC_PROP_EN_1000FDX_CAP, 131 MAC_PROP_ADV_1000HDX_CAP, 132 MAC_PROP_EN_1000HDX_CAP, 133 MAC_PROP_ADV_100FDX_CAP, 134 MAC_PROP_EN_100FDX_CAP, 135 MAC_PROP_ADV_100HDX_CAP, 136 MAC_PROP_EN_100HDX_CAP, 137 MAC_PROP_ADV_10FDX_CAP, 138 MAC_PROP_EN_10FDX_CAP, 139 MAC_PROP_ADV_10HDX_CAP, 140 MAC_PROP_EN_10HDX_CAP, 141 MAC_PROP_ADV_100T4_CAP, 142 MAC_PROP_EN_100T4_CAP, 143 MAC_PROP_WL_ESSID, 144 MAC_PROP_WL_BSSID, 145 MAC_PROP_WL_BSSTYPE, 146 MAC_PROP_WL_LINKSTATUS, 147 MAC_PROP_WL_DESIRED_RATES, 148 MAC_PROP_WL_SUPPORTED_RATES, 149 MAC_PROP_WL_AUTH_MODE, 150 MAC_PROP_WL_ENCRYPTION, 151 MAC_PROP_WL_RSSI, 152 MAC_PROP_WL_PHY_CONFIG, 153 MAC_PROP_WL_CAPABILITY, 154 MAC_PROP_WL_WPA, 155 MAC_PROP_WL_SCANRESULTS, 156 MAC_PROP_WL_POWER_MODE, 157 MAC_PROP_WL_RADIO, 158 MAC_PROP_WL_ESS_LIST, 159 MAC_PROP_WL_KEY_TAB, 160 MAC_PROP_WL_CREATE_IBSS, 161 MAC_PROP_WL_SETOPTIE, 162 MAC_PROP_WL_DELKEY, 163 MAC_PROP_WL_KEY, 164 MAC_PROP_WL_MLME, 165 MAC_PROP_MAXBW, 166 MAC_PROP_PRIO, 167 MAC_PROP_BIND_CPU, 168 MAC_PROP_TAGMODE, 169 MAC_PROP_PRIVATE = -1 170 } mac_prop_id_t; 171 172 /* 173 * Flags to figure out r/w status of legacy ndd props. 174 */ 175 #define MAC_PROP_PERM_READ 0x0001 176 #define MAC_PROP_PERM_WRITE 0x0010 177 #define MAC_PROP_MAP_KSTAT 0x0100 178 #define MAC_PROP_PERM_RW (MAC_PROP_PERM_READ|MAC_PROP_PERM_WRITE) 179 #define MAC_PROP_FLAGS_RK (MAC_PROP_PERM_READ|MAC_PROP_MAP_KSTAT) 180 181 #ifdef _KERNEL 182 183 /* 184 * There are three ranges of statistics values. 0 to 1 - MAC_STAT_MIN are 185 * interface statistics maintained by the mac module. MAC_STAT_MIN to 1 - 186 * MACTYPE_STAT_MIN are common MAC statistics defined by the mac module and 187 * maintained by each driver. MACTYPE_STAT_MIN and above are statistics 188 * defined by MAC-Type plugins and maintained by each driver. 189 */ 190 #define MAC_STAT_MIN 1000 191 #define MACTYPE_STAT_MIN 2000 192 193 #define IS_MAC_STAT(stat) \ 194 (stat >= MAC_STAT_MIN && stat < MACTYPE_STAT_MIN) 195 #define IS_MACTYPE_STAT(stat) (stat >= MACTYPE_STAT_MIN) 196 197 /* 198 * Statistics maintained by the mac module, and possibly populated as link 199 * statistics. 200 */ 201 enum mac_mod_stat { 202 MAC_STAT_LINK_STATE, 203 MAC_STAT_LINK_UP, 204 MAC_STAT_PROMISC 205 }; 206 207 /* 208 * Do not reorder, and add only to the end of this list. 209 */ 210 enum mac_driver_stat { 211 /* MIB-II stats (RFC 1213 and RFC 1573) */ 212 MAC_STAT_IFSPEED = MAC_STAT_MIN, 213 MAC_STAT_MULTIRCV, 214 MAC_STAT_BRDCSTRCV, 215 MAC_STAT_MULTIXMT, 216 MAC_STAT_BRDCSTXMT, 217 MAC_STAT_NORCVBUF, 218 MAC_STAT_IERRORS, 219 MAC_STAT_UNKNOWNS, 220 MAC_STAT_NOXMTBUF, 221 MAC_STAT_OERRORS, 222 MAC_STAT_COLLISIONS, 223 MAC_STAT_RBYTES, 224 MAC_STAT_IPACKETS, 225 MAC_STAT_OBYTES, 226 MAC_STAT_OPACKETS, 227 MAC_STAT_UNDERFLOWS, 228 MAC_STAT_OVERFLOWS 229 }; 230 231 #define MAC_NSTAT (MAC_STAT_OVERFLOWS - MAC_STAT_IFSPEED + 1) 232 233 #define MAC_STAT_ISACOUNTER(_stat) ( \ 234 (_stat) == MAC_STAT_MULTIRCV || \ 235 (_stat) == MAC_STAT_BRDCSTRCV || \ 236 (_stat) == MAC_STAT_MULTIXMT || \ 237 (_stat) == MAC_STAT_BRDCSTXMT || \ 238 (_stat) == MAC_STAT_NORCVBUF || \ 239 (_stat) == MAC_STAT_IERRORS || \ 240 (_stat) == MAC_STAT_UNKNOWNS || \ 241 (_stat) == MAC_STAT_NOXMTBUF || \ 242 (_stat) == MAC_STAT_OERRORS || \ 243 (_stat) == MAC_STAT_COLLISIONS || \ 244 (_stat) == MAC_STAT_RBYTES || \ 245 (_stat) == MAC_STAT_IPACKETS || \ 246 (_stat) == MAC_STAT_OBYTES || \ 247 (_stat) == MAC_STAT_OPACKETS || \ 248 (_stat) == MAC_STAT_UNDERFLOWS || \ 249 (_stat) == MAC_STAT_OVERFLOWS) 250 251 /* 252 * Immutable information. (This may not be modified after registration). 253 */ 254 typedef struct mac_info_s { 255 uint_t mi_media; 256 uint_t mi_nativemedia; 257 uint_t mi_addr_length; 258 uint8_t *mi_unicst_addr; 259 uint8_t *mi_brdcst_addr; 260 } mac_info_t; 261 262 /* 263 * Information for legacy devices. 264 */ 265 typedef struct mac_capab_legacy_s { 266 /* 267 * Notifications that the legacy device does not support. 268 */ 269 uint32_t ml_unsup_note; 270 /* 271 * dev_t of the legacy device; can be held to force attach. 272 */ 273 dev_t ml_dev; 274 } mac_capab_legacy_t; 275 276 /* 277 * When VNICs are created on top of the NIC, there are two levels 278 * of MAC layer, a lower MAC, which is the MAC layer at the level of the 279 * physical NIC, and an upper MAC, which is the MAC layer at the level 280 * of the VNIC. Each VNIC maps to a MAC client at the lower MAC, and 281 * the SRS and classification is done at the lower MAC level. The upper 282 * MAC is therefore for the most part pass-through, and therefore 283 * special processing needs to be done at the upper MAC layer when 284 * dealing with a VNIC. 285 * 286 * This capability allows the MAC layer to detect when a VNIC is being 287 * access, and implement the required shortcuts. 288 */ 289 290 typedef void *(*mac_client_handle_fn_t)(void *); 291 292 typedef struct mac_capab_vnic_s { 293 void *mcv_arg; 294 mac_client_handle_fn_t mcv_mac_client_handle; 295 } mac_capab_vnic_t; 296 297 typedef void (*mac_rename_fn_t)(const char *, void *); 298 typedef struct mac_capab_aggr_s { 299 mac_rename_fn_t mca_rename_fn; 300 int (*mca_unicst)(void *, const uint8_t *); 301 } mac_capab_aggr_t; 302 303 typedef enum { 304 MAC_NOTE_LINK, 305 MAC_NOTE_PROMISC, 306 MAC_NOTE_UNICST, 307 MAC_NOTE_TX, 308 MAC_NOTE_RESOURCE, 309 MAC_NOTE_DEVPROMISC, 310 MAC_NOTE_FASTPATH_FLUSH, 311 MAC_NOTE_SDU_SIZE, 312 MAC_NOTE_MARGIN, 313 MAC_NOTE_CAPAB_CHG, 314 MAC_NNOTE /* must be the last entry */ 315 } mac_notify_type_t; 316 317 typedef void (*mac_notify_t)(void *, mac_notify_type_t); 318 typedef void (*mac_rx_t)(void *, mac_resource_handle_t, mblk_t *, 319 boolean_t); 320 typedef mblk_t *(*mac_receive_t)(void *, int); 321 322 /* 323 * MAC promiscuous types 324 */ 325 typedef enum { 326 MAC_PROMISC = 0x01, /* MAC instance is promiscuous */ 327 MAC_DEVPROMISC = 0x02 /* Device is promiscuous */ 328 } mac_promisc_type_t; 329 330 /* 331 * MAC resource types 332 */ 333 typedef enum { 334 MAC_RX_FIFO = 1 335 } mac_resource_type_t; 336 337 typedef int (*mac_intr_enable_t)(mac_intr_handle_t); 338 typedef int (*mac_intr_disable_t)(mac_intr_handle_t); 339 340 typedef struct mac_intr_s { 341 mac_intr_handle_t mi_handle; 342 mac_intr_enable_t mi_enable; 343 mac_intr_disable_t mi_disable; 344 } mac_intr_t; 345 346 typedef struct mac_rx_fifo_s { 347 mac_resource_type_t mrf_type; /* MAC_RX_FIFO */ 348 mac_intr_t mrf_intr; 349 mac_receive_t mrf_receive; 350 void *mrf_rx_arg; 351 uint32_t mrf_flow_priority; 352 /* 353 * The CPU this flow is to be processed on. With intrd and future 354 * things, we should know which CPU the flow needs to be processed 355 * and get a squeue assigned on that CPU. 356 */ 357 uint_t mrf_cpu_id; 358 } mac_rx_fifo_t; 359 360 #define mrf_intr_handle mrf_intr.mi_handle 361 #define mrf_intr_enable mrf_intr.mi_enable 362 #define mrf_intr_disable mrf_intr.mi_disable 363 364 typedef union mac_resource_u { 365 mac_resource_type_t mr_type; 366 mac_rx_fifo_t mr_fifo; 367 } mac_resource_t; 368 369 typedef enum { 370 MAC_ADDRTYPE_UNICAST, 371 MAC_ADDRTYPE_MULTICAST, 372 MAC_ADDRTYPE_BROADCAST 373 } mac_addrtype_t; 374 375 typedef struct mac_header_info_s { 376 size_t mhi_hdrsize; 377 size_t mhi_pktsize; 378 const uint8_t *mhi_daddr; 379 const uint8_t *mhi_saddr; 380 uint32_t mhi_origsap; 381 uint32_t mhi_bindsap; 382 mac_addrtype_t mhi_dsttype; 383 uint16_t mhi_tci; 384 boolean_t mhi_istagged; 385 } mac_header_info_t; 386 387 /* 388 * Function pointer to match dls client signature. Should be same as 389 * dls_rx_t to allow a soft ring to bypass DLS layer and call a DLS 390 * client directly. 391 */ 392 typedef void (*mac_direct_rx_t)(void *, mac_resource_handle_t, 393 mblk_t *, mac_header_info_t *); 394 395 typedef mac_resource_handle_t (*mac_resource_add_t)(void *, mac_resource_t *); 396 typedef int (*mac_resource_bind_t)(void *, 397 mac_resource_handle_t, processorid_t); 398 typedef void (*mac_resource_remove_t)(void *, void *); 399 typedef void (*mac_resource_quiesce_t)(void *, void *); 400 typedef void (*mac_resource_restart_t)(void *, void *); 401 typedef int (*mac_resource_modify_t)(void *, void *, 402 mac_resource_t *); 403 typedef void (*mac_change_upcall_t)(void *, mac_direct_rx_t, 404 void *); 405 406 /* 407 * MAC-Type plugin interfaces 408 */ 409 410 typedef int (*mtops_addr_verify_t)(const void *, void *); 411 typedef boolean_t (*mtops_sap_verify_t)(uint32_t, uint32_t *, void *); 412 typedef mblk_t *(*mtops_header_t)(const void *, const void *, 413 uint32_t, void *, mblk_t *, size_t); 414 typedef int (*mtops_header_info_t)(mblk_t *, void *, 415 mac_header_info_t *); 416 typedef boolean_t (*mtops_pdata_verify_t)(void *, size_t); 417 typedef mblk_t *(*mtops_header_modify_t)(mblk_t *, void *); 418 typedef void (*mtops_link_details_t)(char *, size_t, mac_handle_t, 419 void *); 420 421 typedef struct mactype_ops_s { 422 uint_t mtops_ops; 423 /* 424 * mtops_unicst_verify() returns 0 if the given address is a valid 425 * unicast address, or a non-zero errno otherwise. 426 */ 427 mtops_addr_verify_t mtops_unicst_verify; 428 /* 429 * mtops_multicst_verify() returns 0 if the given address is a 430 * valid multicast address, or a non-zero errno otherwise. If the 431 * media doesn't support multicast, ENOTSUP should be returned (for 432 * example). 433 */ 434 mtops_addr_verify_t mtops_multicst_verify; 435 /* 436 * mtops_sap_verify() returns B_TRUE if the given SAP is a valid 437 * SAP value, or B_FALSE otherwise. 438 */ 439 mtops_sap_verify_t mtops_sap_verify; 440 /* 441 * mtops_header() is used to allocate and construct a MAC header. 442 */ 443 mtops_header_t mtops_header; 444 /* 445 * mtops_header_info() is used to gather information on a given MAC 446 * header. 447 */ 448 mtops_header_info_t mtops_header_info; 449 /* 450 * mtops_pdata_verify() is used to verify the validity of MAC 451 * plugin data. It is called by mac_register() if the driver has 452 * supplied MAC plugin data, and also by mac_pdata_update() when 453 * drivers update the data. 454 */ 455 mtops_pdata_verify_t mtops_pdata_verify; 456 /* 457 * mtops_header_cook() is an optional callback that converts (or 458 * "cooks") the given raw header (as sent by a raw DLPI consumer) 459 * into one that is appropriate to send down to the MAC driver. 460 * Following the example above, an Ethernet header sent down by a 461 * DLPI consumer would be converted to whatever header the MAC 462 * driver expects. 463 */ 464 mtops_header_modify_t mtops_header_cook; 465 /* 466 * mtops_header_uncook() is an optional callback that does the 467 * opposite of mtops_header_cook(). It "uncooks" a given MAC 468 * header (as received from the driver) for consumption by raw DLPI 469 * consumers. For example, for a non-Ethernet plugin that wants 470 * raw DLPI consumers to be fooled into thinking that the device 471 * provides Ethernet access, this callback would modify the given 472 * mblk_t such that the MAC header is converted to an Ethernet 473 * header. 474 */ 475 mtops_header_modify_t mtops_header_uncook; 476 /* 477 * mtops_link_details() is an optional callback that provides 478 * extended information about the link state. Its primary purpose 479 * is to provide type-specific support for syslog contents on 480 * link up events. If no implementation is provided, then a default 481 * implementation will be used. 482 */ 483 mtops_link_details_t mtops_link_details; 484 } mactype_ops_t; 485 486 /* 487 * mtops_ops exists for the plugin to enumerate the optional callback 488 * entrypoints it has defined. This allows the mac module to define 489 * additional plugin entrypoints in mactype_ops_t without breaking backward 490 * compatibility with old plugins. 491 */ 492 #define MTOPS_PDATA_VERIFY 0x001 493 #define MTOPS_HEADER_COOK 0x002 494 #define MTOPS_HEADER_UNCOOK 0x004 495 #define MTOPS_LINK_DETAILS 0x008 496 497 /* 498 * Provide mapping for legacy ndd ioctls relevant to that mactype. 499 * Note that the ndd ioctls are obsolete, and may be removed in a future 500 * release of Solaris. The ndd ioctls are not typically used in legacy 501 * ethernet drivers. New datalink drivers of all link-types should use 502 * dladm(1m) interfaces for administering tunables and not have to provide 503 * a mapping. 504 */ 505 typedef struct mac_ndd_mapping_s { 506 char *mp_name; 507 union { 508 mac_prop_id_t u_id; 509 uint_t u_kstat; 510 } u_mp_id; 511 long mp_minval; 512 long mp_maxval; 513 size_t mp_valsize; 514 int mp_flags; 515 } mac_ndd_mapping_t; 516 517 #define mp_prop_id u_mp_id.u_id 518 #define mp_kstat u_mp_id.u_kstat 519 520 typedef struct mac_stat_info_s { 521 uint_t msi_stat; 522 char *msi_name; 523 uint_t msi_type; /* as defined in kstat_named_init(9F) */ 524 uint64_t msi_default; 525 } mac_stat_info_t; 526 527 typedef struct mactype_register_s { 528 uint_t mtr_version; /* set by mactype_alloc() */ 529 const char *mtr_ident; 530 mactype_ops_t *mtr_ops; 531 uint_t mtr_mactype; 532 uint_t mtr_nativetype; 533 uint_t mtr_addrlen; 534 uint8_t *mtr_brdcst_addr; 535 mac_stat_info_t *mtr_stats; 536 size_t mtr_statcount; 537 mac_ndd_mapping_t *mtr_mapping; 538 size_t mtr_mappingcount; 539 } mactype_register_t; 540 541 typedef struct mac_prop_s { 542 mac_prop_id_t mp_id; 543 char *mp_name; 544 uint_t mp_flags; 545 } mac_prop_t; 546 547 /* 548 * Driver interface functions. 549 */ 550 extern int mac_open_by_linkid(datalink_id_t, 551 mac_handle_t *); 552 extern int mac_open_by_linkname(const char *, 553 mac_handle_t *); 554 extern const char *mac_name(mac_handle_t); 555 extern minor_t mac_minor(mac_handle_t); 556 extern minor_t mac_minor_hold(boolean_t); 557 extern void mac_minor_rele(minor_t); 558 extern void mac_sdu_get(mac_handle_t, uint_t *, uint_t *); 559 extern int mac_maxsdu_update(mac_handle_t, uint_t); 560 561 extern void mac_unicst_update(mac_handle_t, 562 const uint8_t *); 563 extern void mac_resource_update(mac_handle_t); 564 extern void mac_capab_update(mac_handle_t); 565 extern int mac_pdata_update(mac_handle_t, void *, 566 size_t); 567 extern boolean_t mac_margin_update(mac_handle_t, uint32_t); 568 extern void mac_margin_get(mac_handle_t, uint32_t *); 569 extern int mac_margin_remove(mac_handle_t, uint32_t); 570 extern int mac_margin_add(mac_handle_t, uint32_t *, 571 boolean_t); 572 573 extern mactype_register_t *mactype_alloc(uint_t); 574 extern void mactype_free(mactype_register_t *); 575 extern int mactype_register(mactype_register_t *); 576 extern int mactype_unregister(const char *); 577 578 extern void mac_start_logusage(mac_logtype_t, uint_t); 579 extern void mac_stop_logusage(mac_logtype_t); 580 581 extern mac_handle_t mac_get_lower_mac_handle(mac_handle_t); 582 583 /* 584 * Packet hashing for distribution to multiple ports and rings. 585 */ 586 587 #define MAC_PKT_HASH_L2 0x01 588 #define MAC_PKT_HASH_L3 0x02 589 #define MAC_PKT_HASH_L4 0x04 590 591 extern uint64_t mac_pkt_hash(uint_t, mblk_t *, uint8_t, 592 boolean_t); 593 594 #endif /* _KERNEL */ 595 596 #ifdef __cplusplus 597 } 598 #endif 599 600 #endif /* _SYS_MAC_H */ 601