06db247c678f0e3956535e8a6dec31d6c2108827raghuram * CDDL HEADER START
06db247c678f0e3956535e8a6dec31d6c2108827raghuram * The contents of this file are subject to the terms of the
06db247c678f0e3956535e8a6dec31d6c2108827raghuram * Common Development and Distribution License (the "License").
06db247c678f0e3956535e8a6dec31d6c2108827raghuram * You may not use this file except in compliance with the License.
06db247c678f0e3956535e8a6dec31d6c2108827raghuram * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
06db247c678f0e3956535e8a6dec31d6c2108827raghuram * See the License for the specific language governing permissions
06db247c678f0e3956535e8a6dec31d6c2108827raghuram * and limitations under the License.
06db247c678f0e3956535e8a6dec31d6c2108827raghuram * When distributing Covered Code, include this CDDL HEADER in each
06db247c678f0e3956535e8a6dec31d6c2108827raghuram * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
06db247c678f0e3956535e8a6dec31d6c2108827raghuram * If applicable, add the following below this CDDL HEADER, with the
06db247c678f0e3956535e8a6dec31d6c2108827raghuram * fields enclosed by brackets "[]" replaced with your own identifying
06db247c678f0e3956535e8a6dec31d6c2108827raghuram * information: Portions Copyright [yyyy] [name of copyright owner]
06db247c678f0e3956535e8a6dec31d6c2108827raghuram * CDDL HEADER END
0e26330710421d79f1fbb73c4f5f75086785b207WENTAO YANG * Copyright (c) 2006, 2010, Oracle and/or its affiliates. All rights reserved.
06db247c678f0e3956535e8a6dec31d6c2108827raghuram * This header file contains the basic data structures which the
06db247c678f0e3956535e8a6dec31d6c2108827raghuram * virtual switch (vsw) uses to communicate with vnet clients.
06db247c678f0e3956535e8a6dec31d6c2108827raghuram * The virtual switch reads the machine description (MD) to
06db247c678f0e3956535e8a6dec31d6c2108827raghuram * determine how many port_t structures to create (each port_t
06db247c678f0e3956535e8a6dec31d6c2108827raghuram * can support communications to a single network device). The
06db247c678f0e3956535e8a6dec31d6c2108827raghuram * port_t's are maintained in a linked list.
06db247c678f0e3956535e8a6dec31d6c2108827raghuram * Each port in turn contains a number of logical domain channels
06db247c678f0e3956535e8a6dec31d6c2108827raghuram * (ldc's) which are inter domain communications channels which
7bd3a2e26cc8569257b88c1691d559138e1d32d0Sriharsha Basavapatna * are used for passing small messages between the domains. There
7bd3a2e26cc8569257b88c1691d559138e1d32d0Sriharsha Basavapatna * may be any number of channels associated with each port, though
7bd3a2e26cc8569257b88c1691d559138e1d32d0Sriharsha Basavapatna * currently most devices only have a single channel. The current
7bd3a2e26cc8569257b88c1691d559138e1d32d0Sriharsha Basavapatna * implementation provides support for only one channel per port.
06db247c678f0e3956535e8a6dec31d6c2108827raghuram * The ldc is a bi-directional channel, which is divided up into
06db247c678f0e3956535e8a6dec31d6c2108827raghuram * two directional 'lanes', one outbound from the switch to the
06db247c678f0e3956535e8a6dec31d6c2108827raghuram * virtual network device, the other inbound to the switch.
06db247c678f0e3956535e8a6dec31d6c2108827raghuram * Depending on the type of device each lane may have seperate
06db247c678f0e3956535e8a6dec31d6c2108827raghuram * communication paramaters (such as mtu etc).
06db247c678f0e3956535e8a6dec31d6c2108827raghuram * For those network clients which use descriptor rings the
06db247c678f0e3956535e8a6dec31d6c2108827raghuram * rings are associated with the appropriate lane. I.e. rings
06db247c678f0e3956535e8a6dec31d6c2108827raghuram * which the switch exports are associated with the outbound lanes
06db247c678f0e3956535e8a6dec31d6c2108827raghuram * while those which the network clients are exporting to the switch
06db247c678f0e3956535e8a6dec31d6c2108827raghuram * are associated with the inbound lane.
06db247c678f0e3956535e8a6dec31d6c2108827raghuram * In diagram form the data structures look as follows:
06db247c678f0e3956535e8a6dec31d6c2108827raghuram * vsw instance
06db247c678f0e3956535e8a6dec31d6c2108827raghuram * +----->port_t----->port_t----->port_t----->
06db247c678f0e3956535e8a6dec31d6c2108827raghuram * +--->lane_t (inbound)
06db247c678f0e3956535e8a6dec31d6c2108827raghuram * +--->lane_t (outbound)
06db247c678f0e3956535e8a6dec31d6c2108827raghuramextern "C" {
7bd3a2e26cc8569257b88c1691d559138e1d32d0Sriharsha Basavapatna * LDC pkt tranfer MTU - largest msg size used
7bd3a2e26cc8569257b88c1691d559138e1d32d0Sriharsha Basavapatna (VNET_DRING_REG_EXT_MSG_SIZE_MAX / sizeof (uint64_t))
06db247c678f0e3956535e8a6dec31d6c2108827raghuram * Default message type.
06db247c678f0e3956535e8a6dec31d6c2108827raghuram * Currently only support one major/minor pair.
06db247c678f0e3956535e8a6dec31d6c2108827raghuram * Lane states.
06db247c678f0e3956535e8a6dec31d6c2108827raghuram#define VSW_LANE_INACTIV 0x0 /* No params set for lane */
06db247c678f0e3956535e8a6dec31d6c2108827raghuram#define VSW_VER_INFO_SENT 0x1 /* Version # sent to peer */
06db247c678f0e3956535e8a6dec31d6c2108827raghuram#define VSW_VER_INFO_RECV 0x2 /* Version # recv from peer */
06db247c678f0e3956535e8a6dec31d6c2108827raghuram#define VSW_ATTR_INFO_SENT 0x40 /* Attributes sent to peer */
06db247c678f0e3956535e8a6dec31d6c2108827raghuram#define VSW_ATTR_INFO_RECV 0x80 /* Peer attributes received */
06db247c678f0e3956535e8a6dec31d6c2108827raghuram#define VSW_DRING_INFO_SENT 0x1000 /* Dring info sent to peer */
06db247c678f0e3956535e8a6dec31d6c2108827raghuram#define VSW_DRING_INFO_RECV 0x2000 /* Dring info received */
06db247c678f0e3956535e8a6dec31d6c2108827raghuram#define VSW_RDX_INFO_SENT 0x40000 /* RDX sent to peer */
06db247c678f0e3956535e8a6dec31d6c2108827raghuram#define VSW_RDX_INFO_RECV 0x80000 /* RDX received from peer */
06db247c678f0e3956535e8a6dec31d6c2108827raghuram#define VSW_LANE_ACTIVE 0x40000000 /* Lane open to xmit data */
06db247c678f0e3956535e8a6dec31d6c2108827raghuram/* Handshake milestones */
06db247c678f0e3956535e8a6dec31d6c2108827raghuram#define VSW_MILESTONE1 0x2 /* attribute exchanged */
06db247c678f0e3956535e8a6dec31d6c2108827raghuram#define VSW_MILESTONE2 0x4 /* dring info exchanged */
06db247c678f0e3956535e8a6dec31d6c2108827raghuram#define VSW_MILESTONE4 0x10 /* handshake complete */
06db247c678f0e3956535e8a6dec31d6c2108827raghuram * Lane direction (relative to ourselves).
06db247c678f0e3956535e8a6dec31d6c2108827raghuram/* Peer session id received */
06db247c678f0e3956535e8a6dec31d6c2108827raghuram * Maximum number of consecutive reads of data from channel
06db247c678f0e3956535e8a6dec31d6c2108827raghuram * Currently only support one ldc per port.
06db247c678f0e3956535e8a6dec31d6c2108827raghuram#define VSW_PORT_MAX_LDCS 1 /* max # of ldcs per port */
06db247c678f0e3956535e8a6dec31d6c2108827raghuram * Used for port add/deletion.
06db247c678f0e3956535e8a6dec31d6c2108827raghuram#define LDC_TX_NORESOURCES 2 /* out of descriptors */
06db247c678f0e3956535e8a6dec31d6c2108827raghuram * Descriptor ring info
06db247c678f0e3956535e8a6dec31d6c2108827raghuram * Each descriptor element has a pre-allocated data buffer
06db247c678f0e3956535e8a6dec31d6c2108827raghuram * associated with it, into which data being transmitted is
06db247c678f0e3956535e8a6dec31d6c2108827raghuram * copied. By pre-allocating we speed up the copying process.
06db247c678f0e3956535e8a6dec31d6c2108827raghuram * The buffer is re-used once the peer has indicated that it is
06db247c678f0e3956535e8a6dec31d6c2108827raghuram * finished with the descriptor.
06db247c678f0e3956535e8a6dec31d6c2108827raghuram#define VSW_RING_EL_DATA_SZ 2048 /* Size of data section (bytes) */
06db247c678f0e3956535e8a6dec31d6c2108827raghuram#define VSW_MAX_COOKIES ((ETHERMTU >> MMU_PAGESHIFT) + 2)
06db247c678f0e3956535e8a6dec31d6c2108827raghuram * Size of the mblk in each mblk pool.
06db247c678f0e3956535e8a6dec31d6c2108827raghuram * Number of mblks in each mblk pool.
34f94fbc7a730740933e4776ade5f74009afe4ceWENTAO YANG * Number of rcv buffers in RxDringData mode
34f94fbc7a730740933e4776ade5f74009afe4ceWENTAO YANG#define VSW_RXDRING_NRBUFS (vsw_num_descriptors * vsw_nrbufs_factor)
7bd3a2e26cc8569257b88c1691d559138e1d32d0Sriharsha Basavapatna/* increment recv index */
7bd3a2e26cc8569257b88c1691d559138e1d32d0Sriharsha Basavapatna ((i) = (((i) + 1) & ((dp)->num_descriptors - 1)))
7bd3a2e26cc8569257b88c1691d559138e1d32d0Sriharsha Basavapatna/* decrement recv index */
7bd3a2e26cc8569257b88c1691d559138e1d32d0Sriharsha Basavapatna ((i) = (((i) - 1) & ((dp)->num_descriptors - 1)))
7bd3a2e26cc8569257b88c1691d559138e1d32d0Sriharsha Basavapatna/* bounds check rx index */
7bd3a2e26cc8569257b88c1691d559138e1d32d0Sriharsha Basavapatna (((i) >= 0) && ((i) < (dp)->num_descriptors))
06db247c678f0e3956535e8a6dec31d6c2108827raghuram * Private descriptor
06db247c678f0e3956535e8a6dec31d6c2108827raghuram * Below lock must be held when accessing the state of
06db247c678f0e3956535e8a6dec31d6c2108827raghuram * a descriptor on either the private or public sections
06db247c678f0e3956535e8a6dec31d6c2108827raghuram * of the ring.
06db247c678f0e3956535e8a6dec31d6c2108827raghuram * Descriptor ring structure
7bd3a2e26cc8569257b88c1691d559138e1d32d0Sriharsha Basavapatna uint32_t num_descriptors; /* # of descriptors */
7bd3a2e26cc8569257b88c1691d559138e1d32d0Sriharsha Basavapatna uint32_t descriptor_size; /* size of descriptor */
7bd3a2e26cc8569257b88c1691d559138e1d32d0Sriharsha Basavapatna uint32_t options; /* dring options (mode) */
7bd3a2e26cc8569257b88c1691d559138e1d32d0Sriharsha Basavapatna ldc_dring_handle_t dring_handle; /* dring LDC handle */
7bd3a2e26cc8569257b88c1691d559138e1d32d0Sriharsha Basavapatna uint32_t dring_ncookies; /* # of dring cookies */
7bd3a2e26cc8569257b88c1691d559138e1d32d0Sriharsha Basavapatna ldc_mem_cookie_t dring_cookie[1]; /* LDC cookie of dring */
7bd3a2e26cc8569257b88c1691d559138e1d32d0Sriharsha Basavapatna ldc_mem_handle_t data_handle; /* data area LDC handle */
7bd3a2e26cc8569257b88c1691d559138e1d32d0Sriharsha Basavapatna uint32_t data_ncookies; /* # of data area cookies */
7bd3a2e26cc8569257b88c1691d559138e1d32d0Sriharsha Basavapatna ldc_mem_cookie_t *data_cookie; /* data area LDC cookies */
7bd3a2e26cc8569257b88c1691d559138e1d32d0Sriharsha Basavapatna uint64_t ident; /* identifier sent to peer */
7bd3a2e26cc8569257b88c1691d559138e1d32d0Sriharsha Basavapatna int64_t last_ack_recv; /* last ack received */
7bd3a2e26cc8569257b88c1691d559138e1d32d0Sriharsha Basavapatna kmutex_t txlock; /* protect tx desc alloc */
7bd3a2e26cc8569257b88c1691d559138e1d32d0Sriharsha Basavapatna uint32_t next_txi; /* next tx descriptor index */
7bd3a2e26cc8569257b88c1691d559138e1d32d0Sriharsha Basavapatna uint32_t next_rxi; /* next expected recv index */
7bd3a2e26cc8569257b88c1691d559138e1d32d0Sriharsha Basavapatna kmutex_t restart_lock; /* protect restart_reqd */
0e26330710421d79f1fbb73c4f5f75086785b207WENTAO YANG uint32_t restart_peer_txi; /* index to restart peer */
7bd3a2e26cc8569257b88c1691d559138e1d32d0Sriharsha Basavapatna vio_mblk_pool_t *rx_vmp; /* rx mblk pool */
7bd3a2e26cc8569257b88c1691d559138e1d32d0Sriharsha Basavapatna vio_mblk_t **rxdp_to_vmp; /* descr to buf map tbl */
06db247c678f0e3956535e8a6dec31d6c2108827raghuram * Each ldc connection is comprised of two lanes, incoming
06db247c678f0e3956535e8a6dec31d6c2108827raghuram * from a peer, and outgoing to that peer. Each lane shares
06db247c678f0e3956535e8a6dec31d6c2108827raghuram * common ldc parameters and also has private lane-specific
06db247c678f0e3956535e8a6dec31d6c2108827raghuram * parameters.
06db247c678f0e3956535e8a6dec31d6c2108827raghuram uint8_t addr_type; /* Only MAC address at moment */
06db247c678f0e3956535e8a6dec31d6c2108827raghuram uint8_t ack_freq; /* Only non zero for Pkt based xfer */
1107ea9346159bcc8ea154084897667347c4e6d5Sriharsha Basavapatna uint32_t physlink_update; /* physlink updates */
7bd3a2e26cc8569257b88c1691d559138e1d32d0Sriharsha Basavapatna uint8_t dring_mode; /* Descriptor ring mode */
06db247c678f0e3956535e8a6dec31d6c2108827raghuram dring_info_t *dringp; /* List of drings for this lane */
06db247c678f0e3956535e8a6dec31d6c2108827raghuram/* channel drain states */
06db247c678f0e3956535e8a6dec31d6c2108827raghuram#define VSW_LDC_INIT 0x1 /* Initial non-drain state */
f0ca1d9a12d54d304791bc74525e2010ca924726sb * vnet-protocol-version dependent function prototypes.
f0ca1d9a12d54d304791bc74525e2010ca924726sbtypedef int (*vsw_ldctx_t) (void *, mblk_t *, mblk_t *, uint32_t);
f0ca1d9a12d54d304791bc74525e2010ca924726sbtypedef void (*vsw_ldcrx_pktdata_t) (void *, void *, uint32_t);
7bd3a2e26cc8569257b88c1691d559138e1d32d0Sriharsha Basavapatnatypedef void (*vsw_ldcrx_dringdata_t) (void *, void *);
06db247c678f0e3956535e8a6dec31d6c2108827raghuram/* ldc information associated with a vsw-port */
06db247c678f0e3956535e8a6dec31d6c2108827raghuram struct vsw_ldc *ldc_next; /* next ldc in the list */
06db247c678f0e3956535e8a6dec31d6c2108827raghuram kmutex_t ldc_cblock; /* sync callback processing */
06db247c678f0e3956535e8a6dec31d6c2108827raghuram uint64_t next_ident; /* Next dring ident # to use */
1107ea9346159bcc8ea154084897667347c4e6d5Sriharsha Basavapatna boolean_t pls_negotiated; /* phys link state update ? */
7b1f684a14f99a2b9b1b2561f484ff648eff6d9bSriharsha Basavapatna uint32_t max_rxpool_size; /* max size of rxpool in use */
7bd3a2e26cc8569257b88c1691d559138e1d32d0Sriharsha Basavapatna uint32_t dringdata_msgid; /* msgid in RxDringData mode */
06db247c678f0e3956535e8a6dec31d6c2108827raghuram /* tx thread fields */
7bd3a2e26cc8569257b88c1691d559138e1d32d0Sriharsha Basavapatna /* message thread fields */
7bd3a2e26cc8569257b88c1691d559138e1d32d0Sriharsha Basavapatna kthread_t *msg_thread; /* message thread */
7bd3a2e26cc8569257b88c1691d559138e1d32d0Sriharsha Basavapatna uint32_t msg_thr_flags; /* message thread flags */
7bd3a2e26cc8569257b88c1691d559138e1d32d0Sriharsha Basavapatna kmutex_t msg_thr_lock; /* lock for message thread */
7bd3a2e26cc8569257b88c1691d559138e1d32d0Sriharsha Basavapatna kcondvar_t msg_thr_cv; /* cond.var for msg thread */
06db247c678f0e3956535e8a6dec31d6c2108827raghuram /* receive thread fields */
7bd3a2e26cc8569257b88c1691d559138e1d32d0Sriharsha Basavapatna kthread_t *rcv_thread; /* receive thread */
7bd3a2e26cc8569257b88c1691d559138e1d32d0Sriharsha Basavapatna uint32_t rcv_thr_flags; /* receive thread flags */
7bd3a2e26cc8569257b88c1691d559138e1d32d0Sriharsha Basavapatna kmutex_t rcv_thr_lock; /* lock for receive thread */
7bd3a2e26cc8569257b88c1691d559138e1d32d0Sriharsha Basavapatna kcondvar_t rcv_thr_cv; /* cond.var for recv thread */
7bd3a2e26cc8569257b88c1691d559138e1d32d0Sriharsha Basavapatna vsw_ldcrx_pktdata_t rx_pktdata; /* process raw data msg */
7bd3a2e26cc8569257b88c1691d559138e1d32d0Sriharsha Basavapatna vsw_ldcrx_dringdata_t rx_dringdata; /* process dring data msg */
06db247c678f0e3956535e8a6dec31d6c2108827raghuram /* channel statistics */
06db247c678f0e3956535e8a6dec31d6c2108827raghuram/* worker thread flags */
6f09f0fef8e4582cfa771d87fe2a1f777bfb5cf0WENTAO YANG#define VSW_WTHR_DATARCVD 0x01 /* data received */
6f09f0fef8e4582cfa771d87fe2a1f777bfb5cf0WENTAO YANG#define VSW_WTHR_STOP 0x02 /* stop worker thread request */
06db247c678f0e3956535e8a6dec31d6c2108827raghuram/* multicast addresses port is interested in */
06db247c678f0e3956535e8a6dec31d6c2108827raghuram uint64_t addr; /* mcast addr converted to hash key */
06db247c678f0e3956535e8a6dec31d6c2108827raghuram boolean_t mac_added; /* added into physical device */
06db247c678f0e3956535e8a6dec31d6c2108827raghuram/* Port detach states */
06db247c678f0e3956535e8a6dec31d6c2108827raghuram#define VSW_PORT_INIT 0x1 /* Initial non-detach state */
06db247c678f0e3956535e8a6dec31d6c2108827raghuram#define VSW_PORT_DETACHING 0x2 /* In process of being detached */
06db247c678f0e3956535e8a6dec31d6c2108827raghuram#define VSW_PORT_DETACHABLE 0x4 /* Safe to detach */
06db247c678f0e3956535e8a6dec31d6c2108827raghuram/* port information associated with a vsw */
06db247c678f0e3956535e8a6dec31d6c2108827raghuram struct vsw_port *p_next; /* next port in the list */
7bd3a2e26cc8569257b88c1691d559138e1d32d0Sriharsha Basavapatna vsw_ldc_t *ldcp; /* ldc for this port */
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng krwlock_t maccl_rwlock; /* protect fields below */
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng mac_client_handle_t p_mch; /* mac client handle */
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng mac_unicast_handle_t p_muh; /* mac unicast handle */
06db247c678f0e3956535e8a6dec31d6c2108827raghuram * mac address of the port & connected device
678453a8ed49104d8adad58f3ba591bdc39883e8speer /* HybridIO related info */
bce0a86e5d4d65341c5aca6da2595c848297b2aaWENTAO YANG /* bandwidth limit */
06db247c678f0e3956535e8a6dec31d6c2108827raghuram/* list of ports per vsw */
06db247c678f0e3956535e8a6dec31d6c2108827raghuram krwlock_t lockrw; /* sync access(rw) to the list */
06db247c678f0e3956535e8a6dec31d6c2108827raghuram * Taskq control message
06db247c678f0e3956535e8a6dec31d6c2108827raghuram * State of connection to peer. Some of these states
06db247c678f0e3956535e8a6dec31d6c2108827raghuram * can be mapped to LDC events as follows:
06db247c678f0e3956535e8a6dec31d6c2108827raghuram * VSW_CONN_RESET -> LDC_RESET_EVT
06db247c678f0e3956535e8a6dec31d6c2108827raghuram * VSW_CONN_UP -> LDC_UP_EVT
06db247c678f0e3956535e8a6dec31d6c2108827raghuram#define VSW_CONN_RESTART 0x4 /* Restarting handshake on connection */
06db247c678f0e3956535e8a6dec31d6c2108827raghuram * Ethernet broadcast address definition.
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng (bcmp(&ehp->ether_dhost, ðerbroadcastaddr, ETHERADDRL) == 0)
06db247c678f0e3956535e8a6dec31d6c2108827raghuram#define VSW_PORT_REFHOLD(portp) atomic_inc_32(&((portp)->ref_cnt))
06db247c678f0e3956535e8a6dec31d6c2108827raghuram#define VSW_PORT_REFRELE(portp) atomic_dec_32(&((portp)->ref_cnt))
06db247c678f0e3956535e8a6dec31d6c2108827raghuram#endif /* _VSW_LDC_H */