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