mac_impl.h revision ae6aa22afeb444ae208c287e7227a4a7c877f17a
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2009 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#ifndef _SYS_MAC_IMPL_H
#define _SYS_MAC_IMPL_H
#include <sys/mac_client.h>
#include <sys/mac_provider.h>
#include <sys/mac_flow_impl.h>
#ifdef __cplusplus
extern "C" {
#endif
typedef struct mac_margin_req_s mac_margin_req_t;
struct mac_margin_req_s {
};
/* Generic linked chain type */
typedef struct mac_chain_s {
struct mac_chain_s *next;
void *item;
} mac_chain_t;
/*
* Generic mac callback list manipulation structures and macros. The mac_cb_t
* represents a general callback list element embedded in a particular
* data structure such as a mac_notify_cb_t or a mac_promisc_impl_t.
* The mac_cb_info_t represents general information about list walkers.
* Please see the comments above mac_callback_add for more information.
*/
/* mcb_flags */
#define MCB_NOTIFY_CB_T 0x2
#define MCB_TX_NOTIFY_CB_T 0x4
typedef struct mac_cb_s {
void *mcb_objp; /* Ptr to enclosing object */
} mac_cb_t;
typedef struct mac_cb_info_s {
typedef struct mac_notify_cb_s {
void *mncb_arg; /* callback argument */
struct mac_impl_s *mncb_mip;
/*
* mac_callback_add(listinfo, listhead, listelement)
* mac_callback_remove(listinfo, listhead, listelement)
*/
#define MAC_CALLBACK_WALKER_INC(mcbi) { \
(mcbi)->mcbi_walker_cnt++; \
}
\
} \
}
#define MAC_PROMISC_WALKER_INC(mip) \
#define MAC_PROMISC_WALKER_DCR(mip) { \
mac_cb_info_t *mcbi; \
\
} \
}
typedef struct mactype_s {
const char *mt_ident;
} mactype_t;
/*
* Multiple rings implementation.
*/
typedef enum {
MAC_GROUP_STATE_UNINIT = 0, /* initial state of data structure */
MAC_GROUP_STATE_REGISTERED, /* hooked with h/w group */
MAC_GROUP_STATE_RESERVED, /* group is reserved and opened */
MAC_GROUP_STATE_SHARED /* default group shared among */
/* multiple mac clients */
typedef struct mac_ring_s mac_ring_t;
typedef struct mac_group_s mac_group_t;
/*
* Ring data structure for ring control and management.
*/
typedef enum {
MR_FREE, /* Available for assignment to flows */
MR_NEWLY_ADDED, /* Just assigned to another group */
MR_INUSE /* Assigned to an SRS */
/* mr_flag values */
#define MR_INCIPIENT 0x1
#define MR_CONDEMNED 0x2
#define MR_QUIESCE 0x4
struct mac_ring_s {
int mr_index; /* index in the original list */
/* ring generation no. to guard against drivers using stale rings */
};
/*
* Reference hold and release on mac_ring_t 'mr'
*/
#define MR_REFHOLD_LOCKED(mr) { \
}
#define MR_REFRELE(mr) { \
}
/*
* Per mac client flow information associated with a RX group.
* The entire structure is SL protected.
*/
typedef struct mac_grp_client {
struct mac_grp_client *mgc_next;
struct mac_client_impl_s *mgc_client;
#define MAC_RX_GROUP_ONLY_CLIENT(g) \
((((g)->mrg_clients != NULL) && \
/*
* Common ring group data structure for ring control and management.
* The entire structure is SL protected
*/
struct mac_group_s {
int mrg_index; /* index in the list */
};
/* \
* If the MAC client has a bound Hybrid I/O share, \
* send the packet through the default tx ring, since \
* the tx rings of this client are now mapped in the \
* guest domain and not accessible from this domain. \
*/ \
else \
}
/* mci_tx_flag */
#define MCI_TX_QUIESCE 0x1
typedef struct mac_factory_addr_s {
struct mac_client_impl_s *mfa_client;
typedef struct mac_mcast_addrs_s {
struct mac_mcast_addrs_s *mma_next;
int mma_ref;
typedef enum {
MAC_ADDRESS_TYPE_UNICAST_PROMISC /* promiscuous mode */
typedef struct mac_impl_s mac_impl_t;
typedef struct mac_address_s {
int ma_nusers; /* number of users */
/* of that address */
extern krwlock_t i_mac_impl_lock;
extern mod_hash_t *i_mac_impl_hash;
extern kmem_cache_t *i_mac_impl_cachep;
extern uint_t i_mac_impl_count;
/*
* Each registered MAC is associated with a mac_impl_t structure. The
* structure represents the undelying hardware, in terms of definition,
* resources (transmit, receive rings etc.), callback functions etc. It
* also holds the table of MAC clients that are configured on the device.
* The table is used for classifying incoming packets in software.
*
* The protection scheme uses 2 elements, a coarse serialization mechanism
* called perimeter and a finer traditional lock based scheme. More details
* can be found in the big block comment in mac.c.
*
* The protection scheme for each member of the mac_impl_t is described below.
*
* Write Once Only (WO): Typically these don't change for the lifetime of the
* data structure. For example something in mac_impl_t that stays the same
* from mac_register to mac_unregister, or something in a mac_client_impl_t
* that stays the same from mac_client_open to mac_client_close.
*
* Serializer (SL): Protected by the Serializer. All SLOP operations on a
* mac endpoint go through the serializer. MTOPs don't care about reading
* these fields atomically.
*
* mac serializer, the lock helps synchronize readers with writers.
*/
struct mac_impl_s {
void *mi_driver; /* Driver private, WO */
void *mi_pdata; /* WO */
/*
* on a mac end point go through this.
*/
/* mac notification callbacks */
/*
* RX groups, ring capability
* Fields of this block are SL protected.
*/
/*
* TX groups and ring capability, SL Protected.
*/
/*
* MAC address list. SL protected.
*/
/*
* This MAC's table of sub-flows
*/
/* for broadcast and multicast support */
/* list of MAC clients which opened this MAC */
/*
* Cache of factory MAC addresses provided by the driver. If
* the driver doesn't provide multiple factory MAC addresses,
* the mi_factory_addr is set to NULL, and mi_factory_addr_num
* is set to zero.
*/
/* for promiscuous mode support */
/* cache of rings over this mac_impl */
/*
* These are used for caching the properties, if any, for the
* primary MAC client. If the MAC client is not yet in place
* when the properties are set then we cache them here to be
* applied to the MAC client when it is created.
*/
/*
* List of margin value requests added by mac clients. This list is
* sorted: the first one has the greatest value.
*/
/*
* Hybrid I/O related definitions.
*/
/* This should be the last block in this structure */
#ifdef DEBUG
#define MAC_PERIM_STACK_DEPTH 15
int mi_perim_stack_depth;
#endif
};
/* for mi_state_flags */
#define MIS_DISABLED 0x0001
#define MIS_IS_VNIC 0x0002
#define MIS_IS_AGGR 0x0004
#define MIS_NOTIFY_DONE 0x0008
#define MIS_EXCLUSIVE 0x0010
#define MIS_EXCLUSIVE_HELD 0x0020
#define MIS_LEGACY 0x0040
typedef struct mac_notify_task_arg {
typedef enum {
/*
* XXX All MAC_DBG_PRTs must be replaced with call to dtrace probes. For now
* it may be easier to have these printfs for easier debugging
*/
#ifdef DEBUG
extern int mac_dbg;
#else
#define MAC_DBG_PRT(a)
#endif
/*
* The mac_perim_handle_t is an opaque type that encodes the 'mip' pointer
* and whether internally a mac_open was done when acquiring the perimeter.
*/
}
typedef struct mac_client_impl_s mac_client_impl_t;
extern void mac_init(void);
extern int mac_fini(void);
extern void mac_stat_create(mac_impl_t *);
extern void mac_stat_destroy(mac_impl_t *);
uint8_t *);
extern void mac_tx_notify(mac_impl_t *);
extern void mac_callback_remove_wait(mac_cb_info_t *);
extern void mac_callback_free(mac_cb_t *);
/* in mac_bcast.c */
extern void mac_bcast_init(void);
extern void mac_bcast_fini(void);
extern mac_impl_t *mac_bcast_grp_mip(void *);
extern void mac_bcast_grp_free(void *);
void *, boolean_t);
/*
* Grouping functions are used internally by MAC layer.
*/
mac_group_t *);
extern void mac_release_tx_ring(mac_ring_handle_t);
/*
* MAC address functions are used internally by MAC layer.
*/
extern void mac_init_macaddr(mac_impl_t *);
extern void mac_fini_macaddr(mac_impl_t *);
/*
* Flow construction/destruction routines.
* Not meant to be used by mac clients.
*/
/*
* Fanout update routines called when the link speed of the NIC changes
* or when a MAC client's share is unbound.
*/
extern void mac_fanout_recompute_client(mac_client_impl_t *);
extern void mac_fanout_recompute(mac_impl_t *);
/*
* The following functions are used internally by the MAC layer to
* never be used directly by MAC clients.
*/
uint32_t);
mac_group_t *, uint32_t);
uint32_t);
extern int mac_rx_classify_flow_quiesce(flow_entry_t *, void *);
extern int mac_rx_classify_flow_restart(flow_entry_t *, void *);
extern void mac_tx_client_restart(mac_client_impl_t *);
extern void mac_client_quiesce(mac_client_impl_t *);
extern void mac_client_restart(mac_client_impl_t *);
extern void mac_flow_rem_subflow(flow_entry_t *);
extern void mac_rename_flow(flow_entry_t *, const char *);
extern void mac_flow_set_name(flow_entry_t *, const char *);
extern void i_mac_share_alloc(mac_client_impl_t *);
extern void i_mac_share_free(mac_client_impl_t *);
extern void i_mac_perim_enter(mac_impl_t *);
extern void i_mac_perim_exit(mac_impl_t *);
extern int i_mac_perim_enter_nowait(mac_impl_t *);
extern int mac_hold(const char *, mac_impl_t **);
extern void mac_rele(mac_impl_t *);
extern int i_mac_disable(mac_impl_t *);
extern void i_mac_notify_exit(mac_impl_t *);
extern int mac_start(mac_impl_t *);
extern void mac_stop(mac_impl_t *);
extern void mac_tx_client_flush(mac_client_impl_t *);
extern void mac_tx_client_block(mac_client_impl_t *);
extern void mac_tx_client_unblock(mac_client_impl_t *);
extern void i_mac_promisc_walker_cleanup(mac_impl_t *);
extern mactype_t *mactype_getplugin(const char *);
extern void mac_addr_factory_init(mac_impl_t *);
extern void mac_addr_factory_fini(mac_impl_t *);
extern void mac_unregister_priv_prop(mac_impl_t *);
extern int mac_start_group(mac_group_t *);
extern void mac_stop_group(mac_group_t *);
extern int mac_start_ring(mac_ring_t *);
extern void mac_stop_ring(mac_ring_t *);
extern int mac_remove_macaddr(mac_address_t *);
;
#ifdef __cplusplus
}
#endif
#endif /* _SYS_MAC_IMPL_H */